Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino UNO Based Smart Pill Dispenser with Servo, RTC, and LCD Interface

View and Edit Project In Cirkit DesignerImage of Arduino UNO Based Smart Pill Dispenser with Servo, RTC, and LCD Interface

Smart Pill Dispenser Circuit Documentation

Summary

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.

Component List

Arduino UNO

Micro servo 9G

RTC DS3231

16x2 I2C LCD

Pushbutton (x3)

Buzzer

Resistor (x3)

Wiring Details

Arduino UNO

Micro servo 9G

RTC DS3231

16x2 I2C LCD

Pushbuttons (x3)

Buzzer

Resistors (x3)

Documented Code

#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.