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

ESP32-Based Smart Medication Dispenser with Wi-Fi Connectivity and RTC Scheduling

View and Edit Project In Cirkit DesignerImage of ESP32-Based Smart Medication Dispenser with Wi-Fi Connectivity and RTC Scheduling

Circuit Documentation

Summary

This circuit is designed around the ESP32 Wroom Dev Kit, which serves as the central microcontroller unit (MCU) for interfacing with various peripherals including a membrane matrix keypad, an RTC (Real-Time Clock) module DS3231, an I2C LCD 16x2 screen, buzzers, pushbuttons, servos, and a set of resistors and capacitors for signal conditioning and power stabilization. The ESP32 is programmed to handle user inputs from the keypad, display information on the LCD, keep track of time with the RTC, and control output devices like buzzers and servos based on the logic defined in the embedded code.

Component List

ESP32 Wroom Dev Kit

Membrane Matrix Keypad

RTC DS3231

I2C LCD 16x2 Screen

Buzzer

Pushbutton

Resistor

Tower Pro SG90 Servo

Electrolytic Capacitor

Ceramic Capacitor

7805 Voltage Regulator

9V Battery

LED: Two Pin (red)

Rocker Switch

Wiring Details

ESP32 Wroom Dev Kit

Membrane Matrix Keypad

RTC DS3231

I2C LCD 16x2 Screen

Buzzer

Pushbutton

Resistor (330 Ohms)

Tower Pro SG90 Servo

Electrolytic Capacitor (10 µF)

Ceramic Capacitor (100 nF)

7805 Voltage Regulator

9V Battery

LED: Two Pin (red)

Rocker Switch

Documented Code

The code for the ESP32 Wroom Dev Kit is written in C++ and is designed to be compiled and uploaded using the Arduino IDE. The code includes several libraries for handling Wi-Fi connectivity, LCD display, RTC, and keypad interfacing. The code is structured into different modes, each representing a state of the system, such as setting alarms, configuring pins, and handling user input.

The code begins with the inclusion of necessary libraries and the definition of constants and global variables. It then proceeds to define functions for each mode of operation, such as MODE_0 for entering a pin, MODE_1 for the main menu, and so on. The setup() function initializes the system, setting up Wi-Fi, RTC, EEPROM, and input/output pins. The loop() function continuously checks for alarms, user input, and system state changes.

The code also includes functions for checking the entered pin (checkPin()), setting and saving alarms (saveAlarm()), triggering alarms (triggerAlarm()), and checking for missed doses (checkDose()). EEPROM is used to store and retrieve system settings and alarm times.

// Include necessary libraries
#include <WiFiManager.h>
#include <WiFi.h>
#include <LiquidCrystal_I2C.h>
#include <RTClib.h>
#include <Keypad.h>
#include "time.h"
#include <EEPROM.h>

// Define constants and global variables
#define WIFI_BUTTON 0
// ... (additional constants and variables)

// Define key mappings and initialize peripherals
char keyMap[keypadROWS][keypadCOLS] = {
  {'1','2','3',},
  // ... (additional key mappings)
};
// ... (additional initializations)

// Function prototypes
void resetInput();
void keypadEvent(KeypadEvent key);
void connectWIFI();
void MODE_0();
// ... (additional function prototypes)

// setup() function
void setup() {
  // Initialize serial communication, Wi-Fi, RTC, EEPROM, and peripherals
  Serial.begin(115200);
  // ... (additional setup code)
}

// loop() function
void loop() {
  // Check for alarms and handle system modes
  alarmTriggered = checkAlarms();
  // ... (additional loop code)
}

// Additional function implementations
void resetInput() {
  // Function to reset user input
}
// ... (additional functions)

// Main code logic for handling different modes and user interactions
// ... (complete code logic)

The provided code snippet is a simplified representation of the actual code, which includes detailed logic for handling user interactions, system states, and peripheral control. The full code should be reviewed and uploaded to the ESP32 using the Arduino IDE or a similar development environment.