This circuit is designed to function as a medicine dispenser with a set of features to assist in the timely dispensing of medication. It includes an Arduino UNO microcontroller as the central processing unit, interfaced with a 16x2 I2C LCD for display, a buzzer for audible alerts, a micro servo for mechanical actuation, a Real-Time Clock (RTC) module for timekeeping, multiple pushbuttons for user input, resistors for input protection, a heart pulse sensor for health monitoring, and an mlx90614 infrared temperature sensor for non-contact temperature measurements.
5V
& GND
to power the circuit.A0
connected to the Heart Pulse Sensor signal output.A4
(SDA) & A5
(SCL) for I2C communication with the RTC DS3231, 16x2 I2C LCD, and mlx90614 sensor.D9
connected to the Micro servo 9G PWM input.D6
connected to the Buzzer positive terminal.D2
, D3
, D4
connected to Pushbuttons with corresponding pull-up resistors.GND
& VCC
for power supply.SDA
& SCL
for I2C communication with the Arduino UNO.POSITIVE
connected to Arduino UNO pin D6
.NEGATIVE
connected to ground.GND
& +5V
for power supply.PWM
connected to Arduino UNO pin D9
.GND
& VCC
for power supply.SCL
& SDA
for I2C communication with the Arduino UNO.5V
through a pull-up resistor.D2
, D3
, D4
).GND
& VCC
for power supply.SIGNAL
connected to Arduino UNO pin A0
.GND
& VIN
for power supply.SDA
& SCL
for I2C communication with the Arduino UNO.#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <RTClib.h>
#include <Servo.h>
LiquidCrystal_I2C lcd(0x27, 16, 2); // LCD address may vary, check yours
RTC_DS3231 rtc;
Servo dispenserServo;
const int buttonSetHour = 2;
const int buttonSetMinute = 3;
const int buttonConfirmTime = 4;
const int buzzerPin = 6;
const int servoPin = 9;
int alarmHours[3] = {8, 12, 20}; // Example dispensing times (8 AM, 12 PM, 8 PM)
int alarmMinutes[3] = {0, 0, 0}; // Corresponding minutes for each hour set
bool alarmTriggered[3] = {false, false, false}; // Tracks if alarm has triggered
void setup() {
lcd.begin();
rtc.begin();
dispenserServo.attach(servoPin);
pinMode(buzzerPin, OUTPUT);
pinMode(buttonSetHour, INPUT_PULLUP);
pinMode(buttonSetMinute, INPUT_PULLUP);
pinMode(buttonConfirmTime, INPUT_PULLUP);
lcd.print("Medicine Dispenser");
delay(2000);
lcd.clear();
}
void loop() {
DateTime now = rtc.now();
lcd.setCursor(0, 0);
lcd.print("Time: ");
lcd.print(now.hour());
lcd.print(":");
lcd.print(now.minute());
lcd.print(":");
lcd.print(now.second());
// Check each alarm time
for (int i = 0; i < 3; i++) {
if (now.hour() == alarmHours[i] && now.minute() == alarmMinutes[i] && !alarmTriggered[i]) {
dispenseMedicine(i);
alarmTriggered[i] = true; // Prevent retriggering in the same minute
}
if (now.minute() != alarmMinutes[i]) {
alarmTriggered[i] = false; // Reset trigger for next day
}
}
handleButtonInput();
}
void dispenseMedicine(int alarmIndex) {
lcd.setCursor(0, 1);
lcd.print("Dispensing Dose ");
lcd.print(alarmIndex + 1);
tone(buzzerPin, 1000); // Sound buzzer
dispenserServo.write(90); // Rotate servo to release pills
delay(1000); // Wait for pill to drop
dispenserServo.write(0); // Return servo to original position
noTone(buzzerPin);
delay(1000); // Extra delay to ensure complete dispensing
}
void handleButtonInput() {
static int settingHour = 8;
static int settingMinute = 0;
static int alarmSettingIndex = 0;
// Increment hour setting
if (digitalRead(buttonSetHour) == LOW) {
settingHour = (settingHour + 1) % 24;
delay(200);
}
// Increment minute setting
if (digitalRead(buttonSetMinute) == LOW) {
settingMinute = (settingMinute + 1) % 60;
delay(200);
}
// Confirm time setting
if (digitalRead(buttonConfirmTime) == LOW) {
alarmHours[alarmSettingIndex] = settingHour;
alarmMinutes[alarmSettingIndex] = settingMinute;
alarmSettingIndex = (alarmSettingIndex + 1) % 3; // Cycle through alarms
lcd.setCursor(0, 1);
lcd.print("Set Alarm ");
lcd.print(alarmSettingIndex);
lcd.print(": ");
lcd.print(settingHour);
lcd.print(":");
lcd.print(settingMinute);
delay(500);
}
}
This code is responsible for controlling the medicine dispenser's operation, including setting alarm times, dispensing medication, and displaying information on the LCD. It uses the RTC to keep track of the current time and triggers the servo to dispense medicine at preset times. It also listens for button presses to set the alarm times and provides feedback through the buzzer and LCD.