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

Arduino-Based Bluetooth-Controlled Pill Dispenser with LCD and Servo Mechanism

View and Edit Project In Cirkit DesignerImage of Arduino-Based Bluetooth-Controlled Pill Dispenser with LCD and Servo Mechanism

Circuit Documentation

Summary

This document provides a detailed overview of a circuit designed to control a pill dispenser using an Arduino UNO. The circuit includes multiple LEDs, servos, a buzzer, an HC-05 Bluetooth module, and a 16x2 I2C LCD. The Arduino UNO is programmed to receive commands via Bluetooth to dispense pills and provide visual and auditory feedback.

Component List

  1. Resistor (220 Ohms)

    • Pins: pin1, pin2
    • Description: Limits current to LEDs
  2. LED: Two Pin (red)

    • Pins: cathode, anode
    • Description: Provides visual feedback
  3. LED: Two Pin (green)

    • Pins: cathode, anode
    • Description: Provides visual feedback
  4. LED: Two Pin (white)

    • Pins: cathode, anode
    • Description: Provides visual feedback
  5. LED: Two Pin (blue)

    • Pins: cathode, anode
    • Description: Provides visual feedback
  6. HC-05 Bluetooth Module

    • Pins: Key, VCC, TXD, RXD, State, GND
    • Description: Receives commands via Bluetooth
  7. Arduino UNO

    • 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
    • Description: Microcontroller for controlling the circuit
  8. Buzzer

    • Pins: PIN, GND
    • Description: Provides auditory feedback
  9. Servo

    • Pins: gnd, vcc, pulse
    • Description: Controls the dispensing mechanism
  10. 9V Battery

    • Pins: -, +
    • Description: Powers the circuit
  11. Power Jack

    • Pins: POSITIF, NEGATIF
    • Description: Connects the 9V battery to the circuit
  12. 16x2 I2C LCD

    • Pins: GND, VCC, SDA, SCL
    • Description: Displays messages

Wiring Details

Resistor (220 Ohms)

LED: Two Pin (red)

LED: Two Pin (green)

LED: Two Pin (white)

LED: Two Pin (blue)

HC-05 Bluetooth Module

Arduino UNO

Buzzer

Servo

9V Battery

Power Jack

16x2 I2C LCD

Code Documentation

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

// Define pins
#define RED_LED_PIN 2
#define GREEN_LED_PIN 11
#define BLUE_LED_PIN 12
#define WHITE_LED_PIN 4
#define BUZZER_PIN 7
#define SERVO1_PIN 3
#define SERVO2_PIN 5
#define SERVO3_PIN 8
#define SERVO4_PIN 13

// Create servo objects
Servo servo1;
Servo servo2;
Servo servo3;
Servo servo4;

// Create LCD object
LiquidCrystal_I2C lcd(0x27, 16, 2);

void setup() {
  // Initialize serial communication
  Serial.begin(9600);

  // Initialize pins
  pinMode(RED_LED_PIN, OUTPUT);
  pinMode(GREEN_LED_PIN, OUTPUT);
  pinMode(BLUE_LED_PIN, OUTPUT);
  pinMode(WHITE_LED_PIN, OUTPUT);
  pinMode(BUZZER_PIN, OUTPUT);

  // Attach servos
  servo1.attach(SERVO1_PIN);
  servo2.attach(SERVO2_PIN);
  servo3.attach(SERVO3_PIN);
  servo4.attach(SERVO4_PIN);

  // Initialize LCD
  lcd.begin(16, 2); // Corrected to include the number of columns and rows
  lcd.backlight();
  lcd.print("Pill Dispenser");
}

void loop() {
  // Check for Bluetooth commands
  if (Serial.available() > 0) {
    char command = Serial.read();
    handleCommand(command);
  }
}

void handleCommand(char command) {
  switch (command) {
    case '1':
      dispensePill(servo1);
      break;
    case '2':
      dispensePill(servo2);
      break;
    case '3':
      dispensePill(servo3);
      break;
    case '4':
      dispensePill(servo4);
      break;
    default:
      lcd.clear();
      lcd.print("Invalid Command");
      tone(BUZZER_PIN, 1000, 500);
      break;
  }
}

void dispensePill(Servo &servo) {
  lcd.clear();
  lcd.print("Dispensing...");
  digitalWrite(GREEN_LED_PIN, HIGH);
  servo.write(90); // Rotate servo to dispense
  delay(1000); // Wait for pill to dispense
  servo.write(0); // Return servo to initial position
  digitalWrite(GREEN_LED_PIN, LOW);
  lcd.clear();
  lcd.print("Done");
  tone(BUZZER_PIN, 2000, 500);
}

This code initializes the Arduino UNO to control LEDs, servos, a buzzer, and an LCD. It listens for commands via Bluetooth to dispense pills and provides visual and auditory feedback.