This document provides a detailed overview of the Automated Medicine Dispenser circuit. The circuit is designed to dispense medicine at pre-set times using an Arduino UNO microcontroller, a micro servo motor, an RTC DS3231 module, a buzzer, a 16x2 I2C LCD, and an HC-05 Bluetooth module. The system allows users to set up to three timings via Bluetooth, and at each specified time, the buzzer will sound, the LCD will display a reminder, and the servo will rotate to dispense the medicine.
Arduino UNO
Buzzer
Micro Servo 9G
RTC DS3231
16x2 I2C LCD
HC-05 Bluetooth Module
Resistor (10.6k Ohms)
/*
* Automated Medicine Dispenser
* Components: Arduino UNO, Micro Servo 9G, RTC DS3231, Buzzer, 16x2 I2C LCD, HC-05
* Functionality:
* - Displays 'waiting for BT' on LCD until Bluetooth connection is established.
* - Displays 'BT connected' on LCD after connection.
* - Prompts user to enter 3 timings via Bluetooth in HH:MM format.
* - Compares entered timings with current time from RTC module.
* - If a timing matches, buzzer beeps, LCD displays 'Take medicine', and servo rotates.
* - Servo rotates to 45, 90, or 135 degrees based on the timing.
* - After 20 seconds, servo returns to 0 degrees and LCD clears.
* - Keeps checking the time every minute if no match.
*/
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <RTClib.h>
#include <Servo.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
RTC_DS3231 rtc;
Servo myservo;
const int buzzerPin = 8;
const int servoPin = 9;
const int btRxPin = 10;
const int btTxPin = 11;
String timings[3];
bool btConnected = false;
void setup() {
lcd.begin();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("waiting for BT");
Serial.begin(9600);
pinMode(buzzerPin, OUTPUT);
myservo.attach(servoPin);
myservo.write(0);
if (!rtc.begin()) {
lcd.setCursor(0, 1);
lcd.print("RTC failed");
while (1);
}
if (rtc.lostPower()) {
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
}
void loop() {
if (Serial.available() > 0) {
String input = Serial.readStringUntil('\n');
if (!btConnected) {
btConnected = true;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("BT connected");
delay(2000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Enter Timings:");
} else {
static int timingIndex = 0;
if (timingIndex < 3) {
timings[timingIndex] = input;
timingIndex++;
lcd.setCursor(0, 1);
lcd.print("Timing ");
lcd.print(timingIndex);
lcd.print(": ");
lcd.print(input);
delay(2000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Enter Timings:");
}
}
}
DateTime now = rtc.now();
String currentTime = String(now.hour()) + ":" + String(now.minute());
for (int i = 0; i < 3; i++) {
if (timings[i] == currentTime) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Take medicine");
digitalWrite(buzzerPin, HIGH);
delay(2000);
digitalWrite(buzzerPin, LOW);
int angle = (i + 1) * 45;
myservo.write(angle);
delay(20000);
myservo.write(0);
lcd.clear();
break;
}
}
delay(60000); // Check every minute
}
This code initializes the components, waits for Bluetooth connection, allows the user to input three timings, and checks the current time against these timings. If a match is found, the buzzer sounds, the LCD displays a reminder, and the servo motor rotates to dispense the medicine.