A complete IoT solution for medication management using ESP32, designed to help patients and caregivers track medicine intake with real-time notifications and comprehensive logging.
- Remote Time Setting: Configure medicine schedules from anywhere using time input widgets
- Real-time Status Monitoring: View current medicine schedule and taken status
- Push Notifications: Instant alerts for medicine time reminders
- Complete Activity Log: Detailed history with timestamps
- Current Time Display: Check RTC time remotely with a button press
- 6 Customizable Time Slots: Perfect for multiple daily medications
- Morning Before/After Breakfast
- Noon Before/After Lunch
- Night Before/After Dinner
- Automatic Reminders: Red LED + buzzer alerts at scheduled times
- Daily Reset: Automatic schedule reset at midnight
- Green LED Confirmation: 10-minute confirmation when medicine is taken
- ๐ Medicine Time Alert: Red LED + buzzer when it's time to take medication
- โ Confirmation: Green LED when medicine is successfully taken
- ๐ฑ Blynk Events: Push notifications sent to your mobile device
- Daily Intake Logging: Complete record of all medication activities
- Status Monitoring: Track which medicines have been taken
- Historical Data: Perfect for sharing with healthcare providers
- Manual Reset: Clear daily logs and reset status anytime
| Component | Quantity | Purpose |
|---|---|---|
| ESP32 Development Board | 1 | Main controller with WiFi |
| DS3231 RTC Module | 1 | Real-time clock for accurate timing |
| Reed Switches | 6 | Detect drawer opening (magnetic sensors) |
| Red LEDs | 6 | Medicine time indicators |
| Green LEDs | 6 | Medicine taken confirmation |
| Buzzer | 1 | Audio alerts |
| Resistors (220ฮฉ) | 12 | LED current limiting |
| Pull-up Resistors (10kฮฉ) | 4 | For input-only GPIO pins (34-39) |
ESP32 Pin Assignments:
โโโ Reed Switches (INPUT): 2, 4, 34, 35, 36, 39
โโโ Red LEDs (OUTPUT): 12, 13, 14, 25, 26, 27
โโโ Green LEDs (OUTPUT): 32, 33, 15, 16, 17, 23
โโโ Buzzer (OUTPUT): 19
โโโ I2C (RTC): SDA-21, SCL-22
- GPIO 34-39: Input-only pins, require external 10kฮฉ pull-up resistors
- GPIO 2, 4: Use internal pull-up resistors (INPUT_PULLUP)
- RTC Module: Connect VCC to 3.3V, GND to GND
- LEDs: Use 220ฮฉ current-limiting resistors
Install these libraries through Arduino IDE Library Manager:
// Core Libraries
#include <WiFi.h> // ESP32 WiFi (built-in)
#include <Wire.h> // I2C communication (built-in)
// External Libraries (install via Library Manager)
#include <RTClib.h> // by Adafruit
#include <BlynkSimpleEsp32.h> // by Volodymyr Shymanskyy# In Arduino IDE:
Tools โ Manage Libraries โ Search and Install:
- "RTClib" by Adafruit
- "Blynk" by Volodymyr Shymanskyy- Connect components according to pin diagram above
- Install ESP32 in breadboard/PCB
- Connect RTC module via I2C (SDA-21, SCL-22)
- Wire reed switches:
- Pins 2, 4: Direct connection (uses INPUT_PULLUP)
- Pins 34-39: External 10kฮฉ pull-up resistors required
- Connect LEDs with 220ฮฉ current-limiting resistors
- Add buzzer to pin 19
- Go to console.blynk.cloud
- Create new template: "MediTrack"
- Hardware: ESP32, Connection: WiFi
- Copy your Template ID
Add these Virtual Pins in your Blynk template:
| Pin | Name | Type | Purpose |
|---|---|---|---|
| V0 | Morning Before Time | String | Time input widget |
| V1 | Morning After Time | String | Time input widget |
| V2 | Noon Before Time | String | Time input widget |
| V3 | Noon After Time | String | Time input widget |
| V4 | Night Before Time | String | Time input widget |
| V5 | Night After Time | String | Time input widget |
| V6 | Medicine Log | String | Log display |
| V7 | Reset Log | Integer | Reset button |
| V8 | Status Display | String | Current status |
| V9 | Current Time Button | Integer | Get time button |
| V10 | Current Time Display | String | Time display |
- Go to Devices tab
- Create "New Device" from template
- Copy Auth Token for Arduino code
Create event for notifications:
- Event Name:
medicine_reminder - Description: Medicine reminder notification
- Android: Google Play Store
- iOS: App Store
- Search for "Blynk IoT" (NOT Blynk Legacy)
| Widget Type | Virtual Pin | Configuration |
|---|---|---|
| Time Input | V0-V5 | Medicine schedule times (24H format) |
| Label | V8 | Current medicine status |
| Label | V6 | Medicine intake log |
| Button | V7 | Reset daily log (Push mode) |
| Button | V9 | Show current time (Push mode) |
| Label | V10 | Current time display |
Update these credentials in MediTrack.ino:
// Blynk Credentials (from Blynk Console)
#define BLYNK_TEMPLATE_ID "Template_ID" // Your Template ID
#define BLYNK_TEMPLATE_NAME "Template_name" // Your Template Name
#define BLYNK_AUTH_TOKEN "Auth_token" // Your Device Auth Token
// WiFi Credentials
char ssid[] = "wifi_name"; // Your WiFi SSID
char pass[] = "wifi_password"; // Your WiFi Password- Select ESP32 Dev Module in Arduino IDE
- Upload code to ESP32
- Open Serial Monitor (115200 baud)
- Look for these messages:
- "Current RTC time: ..."
- "Smart Medicine Box Started!"
- "Connected to Blynk!"
- Set Medicine Times: Use time input widgets in Blynk app (format: HH:MM)
- Verify Connection: Check device shows "Online" in Blynk console
- Test Current Time: Press "Show Current Time" button to verify RTC
- Enable Notifications: Allow push notifications in phone settings
- Alert Phase: Red LED turns on + buzzer beeps every second
- Taking Medicine: Open drawer (reed switch detects opening)
- Confirmation: Red LED/buzzer stop, Green LED turns on for 10 minutes
- Logging: Activity automatically logged with timestamp
- ๐ Schedule Management: Set/modify medicine times remotely
- ๐ Real-time Status: View which medicines are taken/scheduled
- ๐ Activity Logging: Complete history with timestamps
- ๐ Smart Notifications: Push notifications for medicine time
- โฐ Time Verification: Check current RTC time anytime
| Color | Meaning | Duration |
|---|---|---|
| โซ Off | Normal state | - |
| ๐ด Red | Medicine time - take now! | Until drawer opened |
| ๐ข Green | Medicine taken - confirmed | 10 minutes |
- Drawer Closed: Magnet close to reed switch = LOW
- Drawer Open: Magnet away from reed switch = HIGH (triggers medicine taken)
![]() |
![]() |
|---|
=== Daily Medicine Log ===
1. Morning Before taken at 8:02
2. Morning After taken at 8:32
3. Noon Before taken at 12:01
4. Noon After taken at 12:31
5. Night Before taken at 18:02
6. Night After taken at 19:15
// Check Serial Monitor:
Serial.println("Current RTC time: ..."); // Should show current time
// Verify:
- WiFi SSID and password are correct
- Using 2.4GHz network (ESP32 doesn't support 5GHz)
- Network has internet access// Verify in code:
- Template ID matches Blynk Console exactly
- Auth Token is from Device tab (not Template)
- Device shows "Online" in Blynk Console// Check Serial Monitor:
"Current RTC time: 2025/8/22 14:30:25" // Should show reasonable time
// If time is wrong:
- RTC module needs backup battery (CR2032)
- Check I2C connections (SDA=21, SCL=22)
- Verify 3.3V power (not 5V)// For different pin types:
GPIO 2, 4: pinMode(pin, INPUT_PULLUP); // Built-in pull-up
GPIO 34-39: pinMode(pin, INPUT); // External 10kฮฉ pull-up required
// Check magnet alignment and distance// Debug steps:
1. Check current time: Press "Show Current Time" button
2. Set test time 2 minutes in future
3. Watch Serial Monitor for:
"MEDICINE TIME TRIGGERED for Morning Before"Monitor these in Serial Monitor (115200 baud):
โ "Current RTC time: 2025/8/22 14:30:25" - RTC working
โ "Smart Medicine Box Started!" - Setup complete
โ "Connected to Blynk!" - Blynk connected
โ "Current time: 14:30:25" - Printed every 30 seconds
โ "MEDICINE TIME TRIGGERED for Morning Before" - Alert activated
โ "Morning Before taken at 14:32" - Medicine logged
- RTC automatically set to compile time on first run
- Handles power loss recovery
- Manual time adjustment capability
- Automatic INPUT_PULLUP for GPIO 2, 4
- INPUT mode for GPIO 34-39 (input-only pins)
- Proper reed switch logic for all pin types
- Handles time input widgets that send seconds since midnight
- Converts to hours and minutes automatically
- Validates time ranges (0-23 hours, 0-59 minutes)
- Buzzer beeps every second when any alarm is active
- Stops immediately when medicine is taken
- No interference between multiple active alarms
- Current time printed every 30 seconds
- Schedule checking debug every minute
- Detailed logging for troubleshooting
git clone https://github.com/yourusername/meditrack.git
cd meditrack
# Open MediTrack.ino in Arduino IDEsetup()- Initialize hardware and connectionsloop()- Main execution cyclecheckMedicineTime()- Handle scheduling logiccheckDrawerStatus()- Monitor reed switchesparseTime()- Process time input from BlynkupdateBlynkStatus()- Update mobile app display
- Blynk Documentation: docs.blynk.cloud
- ESP32 Reference: docs.espressif.com
- RTClib Guide: learn.adafruit.com
- Check Serial Monitor output first
- Verify hardware connections match pin assignments
- Test individual components before full system
- Use Blynk console to monitor device status
โญ Star this repo if it helps you manage medications better!
Made with โค๏ธ for better healthcare management
.jpg)

