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

Automated Medicine Dispenser with Arduino UNO, RTC, and Bluetooth Connectivity

View and Edit Project In Cirkit DesignerImage of Automated Medicine Dispenser with Arduino UNO, RTC, and Bluetooth Connectivity

Automated Medicine Dispenser Circuit Documentation

Summary

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.

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

    • Description: An electronic device that produces a sound when a voltage is applied.
    • Pins: POSITIVE, NEGATIVE
  3. Micro Servo 9G

    • Description: A small servo motor used for precise control of angular position.
    • Pins: GND, +5V, PWM
  4. RTC DS3231

    • Description: Real-Time Clock module with a temperature-compensated crystal oscillator.
    • Pins: 32K, SQW, SCL, SDA, VCC, GND
  5. 16x2 I2C LCD

    • Description: A 16x2 character LCD display with I2C interface.
    • Pins: GND, VCC, SDA, SCL
  6. HC-05 Bluetooth Module

    • Description: A Bluetooth module for wireless communication.
    • Pins: Key, VCC, GND, TXD, RXD, State
  7. Resistor (10.6k Ohms)

    • Description: A resistor with a resistance of 10.6k Ohms.
    • Pins: pin1, pin2

Wiring Details

Arduino UNO

Buzzer

Micro Servo 9G

RTC DS3231

16x2 I2C LCD

HC-05 Bluetooth Module

Resistor (10.6k Ohms)

Code Documentation

/*
 * 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.