

The Smart Pill Dispenser circuit is designed to automate the dispensing of pills at a set time. It utilizes an Arduino UNO as the central microcontroller to manage the timing, user inputs, and control of peripheral devices such as a servo motor, buzzer, and an LCD display. The circuit includes buttons for setting the dispensing time, a real-time clock (RTC) module for accurate timekeeping, and a micro servo for the mechanical action of dispensing pills.
5V and GND are used to power the 16x2 I2C LCD, Micro servo 9G, and RTC DS3231.A4 (SDA) and A5 (SCL) are connected to the I2C bus for communication with the 16x2 I2C LCD and RTC DS3231.D2, D3, and D4 are connected to pushbuttons for user input.D6 is connected to the buzzer.D9 is connected to the PWM input of the Micro servo 9G.GND and +5V for power supply.PWM input is connected to D9 on the Arduino UNO for control signals.GND and VCC for power supply.SCL and SDA for I2C communication, connected to A5 (SCL) and A4 (SDA) on the Arduino UNO.GND and VCC for power supply.SDA and SCL for I2C communication, connected to A4 (SDA) and A5 (SCL) on the Arduino UNO.D2, D3, D4) and the other side to GND through a 200 Ohm resistor.POSITIVE connected to D6 on the Arduino UNO.NEGATIVE connected to GND.GND.#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <RTClib.h>
#include <Servo.h>
LiquidCrystal_I2C lcd(0x27, 16, 2); // LCD with I2C address 0x27
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 setHour = 8; // Default hour for pill dispensing
int setMinute = 0; // Default minute for pill dispensing
bool alarmSet = false;
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("Smart Pill Dispenser");
delay(2000);
lcd.clear();
}
void loop() {
DateTime now = rtc.now();
// Display current time
lcd.setCursor(0, 0);
lcd.print("Time: ");
lcd.print(now.hour());
lcd.print(":");
lcd.print(now.minute());
lcd.print(":");
lcd.print(now.second());
// Check if it's time to dispense pill
if (now.hour() == setHour && now.minute() == setMinute && !alarmSet) {
dispensePill();
alarmSet = true; // Prevents re-triggering within the same minute
}
if (now.minute() != setMinute) alarmSet = false; // Reset alarm after a minute
// Setting time with buttons
if (digitalRead(buttonSetHour) == LOW) {
setHour = (setHour + 1) % 24;
delay(200); // Debounce delay
}
if (digitalRead(buttonSetMinute) == LOW) {
setMinute = (setMinute + 1) % 60;
delay(200);
}
if (digitalRead(buttonConfirmTime) == LOW) {
lcd.setCursor(0, 1);
lcd.print("Set: ");
lcd.print(setHour);
lcd.print(":");
lcd.print(setMinute);
delay(500);
}
}
void dispensePill() {
lcd.setCursor(0, 1);
lcd.print("Dispensing Pill!");
tone(buzzerPin, 1000); // Sound buzzer
dispenserServo.write(90); // Move servo to release pills
delay(1000); // Wait for pill to drop
dispenserServo.write(0); // Return servo to original position
noTone(buzzerPin);
}
This code is responsible for controlling the Smart Pill Dispenser. It initializes the LCD, RTC, and servo, and sets up the button inputs. The main loop checks the current time against the set dispensing time and activates the servo to dispense a pill when the time matches. It also allows the user to set the dispensing time using buttons.