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

Arduino-Based Automated Medicine Dispenser with RTC and I2C LCD

View and Edit Project In Cirkit DesignerImage of Arduino-Based Automated Medicine Dispenser with RTC and I2C LCD

Circuit Documentation

Summary

This circuit is designed to manage a medication dispensing system. It includes an Arduino UNO microcontroller, a 16x2 I2C LCD for display, a buzzer for alerts, a micro servo motor for dispensing pills, an RTC DS3231 for real-time clock functionality, and multiple pushbuttons and resistors for user input and control.

Component List

  1. Arduino UNO

    • Description: Microcontroller board based on the ATmega328P.
    • Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0, A1, A2, A3, A4, A5, SCL, SDA, AREF, D13, D12, D11, D10, D9, D8, D7, D6, D5, D4, D3, D2, D1, D0
  2. 16x2 I2C LCD

    • Description: 16x2 character LCD display with I2C interface.
    • Pins: GND, VCC, SDA, SCL
  3. Buzzer

    • Description: Simple piezoelectric buzzer.
    • Pins: POSITIVE, NEGATIVE
  4. Micro servo 9G

    • Description: Small servo motor for precise control.
    • Pins: GND, +5V, PWM
  5. RTC DS3231

    • Description: Real-Time Clock module with I2C interface.
    • Pins: 32K, SQW, SCL, SDA, VCC, GND
  6. Pushbutton

    • Description: Momentary pushbutton switch.
    • Pins: Pin 3 (out), Pin 4 (out), Pin 1 (in), Pin 2 (in)
  7. Resistor

    • Description: Resistor with a resistance of 10k Ohms.
    • Pins: pin1, pin2

Wiring Details

Arduino UNO

16x2 I2C LCD

Buzzer

Micro servo 9G

RTC DS3231

Pushbutton 1

Pushbutton 2

Pushbutton 3

Resistor 1

Resistor 2

Resistor 3

Documented Code

#include <Wire.h>
#include <RTClib.h>
#include <Servo.h>
#include <LiquidCrystal_I2C.h>

// Initialize components
RTC_DS3231 rtc; // For Real-Time Clock module
Servo servo;    // For servo motor
LiquidCrystal_I2C lcd(0x27, 16, 2); // I2C address and dimensions of LCD

// Buzzer pin and servo settings
const int buzzerPin = 8;
const int servoPin = 9;

// Preset medicine timings (hh:mm format)
String timings[] = {"08:00", "14:00", "21:09"};
bool medicineDispensed = false; // To track if the medicine was dispensed for the current time

void setup() {
  // Initialize serial monitor for debugging
  Serial.begin(9600);

  // Initialize components
  lcd.begin(16,2);
  lcd.backlight();
  servo.attach(servoPin);
  pinMode(buzzerPin, OUTPUT);

  // Start the RTC
  if (!rtc.begin()) {
    lcd.print("RTC not found!");
    while (1); // Stop execution
  }

  // Check if RTC is running
  if (rtc.lostPower()) {
    lcd.print("RTC is reset!");
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); // Adjust to compile time
  }

  // Initialize the servo position
  servo.write(0); // Start position: pill plate is hidden
}

void loop() {
  // Get current time
  DateTime now = rtc.now();
  String currentTime = formatTime(now.hour(), now.minute());

  // Check if it's time for medication
  for (String timing : timings) {
    if (currentTime == timing && !medicineDispensed) {
      // Alert user and dispense medicine
      alertUser();
      delay(5000); // Buzzer duration: 5 seconds
      dispenseMedicine();
      medicineDispensed = true; // Mark as dispensed
    }
  }

  // Reset the flag after 1 minute
  if (millis() % 60000 == 0) {
    medicineDispensed = false;
  }

  delay(1000); // Wait 1 second before next check
}

// Function to alert the user
void alertUser() {
  lcd.clear();
  lcd.print("Take Medicine!");
  digitalWrite(buzzerPin, HIGH);
  delay(5000); // Keep buzzer on for 5 seconds
  digitalWrite(buzzerPin, LOW);
}

// Function to dispense the medicine
void dispenseMedicine() {
  delay(30000); // Wait 30 seconds after buzzer
  servo.write(90); // Rotate servo to expose the pill plate
  delay(5000); // Keep plate open for 5 seconds
  servo.write(0); // Rotate servo back to hide the plate
  lcd.clear();
  lcd.print("Medicine Taken");
}

// Helper function to format time into hh:mm
String formatTime(int hour, int minute) {
  char timeStr[6];
  sprintf(timeStr, "%02d:%02d", hour, minute);
  return String(timeStr);
}

This documentation provides a comprehensive overview of the circuit, including a summary, detailed component list, wiring details, and the embedded code used in the Arduino UNO microcontroller.