An intelligent medicine reminder system built with ESP32, featuring environmental monitoring, IoT connectivity, and automated dispensing capabilities.
- Multiple Alarm System: Up to 4 configurable medicine alarms with snooze functionality
- Real-time Clock: NTP-synchronized time with timezone support
- Environmental Monitoring: Temperature, humidity, and light intensity sensing
- Smart Dispensing: Servo-controlled mechanism based on environmental conditions
- Visual Feedback: 128x64 OLED display with intuitive menu system
- Audio Alerts: Musical tone sequences for alarms and warnings
- WiFi Connectivity: Remote monitoring and configuration
- MQTT Integration: Real-time data publishing and parameter updates
- Remote Configuration: Adjust sampling intervals, servo parameters, and more
- Data Logging: Continuous sensor data transmission
- Button Navigation: 4-button interface (UP, DOWN, OK, CANCEL)
- Menu System: Easy-to-navigate settings and alarm configuration
- Status LEDs: Visual indicators for temperature, humidity, and alarm states
- Warning System: Real-time alerts for environmental conditions
- ESP32 DevKit C V4: Main microcontroller with WiFi capability
- DHT22: Temperature and humidity sensor
- LDR (Photoresistor): Light intensity measurement
- SG90 Servo Motor: Medicine dispensing mechanism
- SSD1306 OLED Display: 128x64 pixel display for UI
- 4 Push Buttons: Navigation and control
- 3 Status LEDs:
- Red: Temperature warning
- Blue: Humidity warning
- Yellow: Alarm indicator
- Buzzer: Audio feedback and alarms
- Pull-up Resistors: Button debouncing and stable inputs
- Current Limiting Resistors: LED protection
- PlatformIO IDE or extension
- ESP32 development environment
The following libraries are automatically managed by PlatformIO:
lib_deps =
adafruit/Adafruit GFX Library@^1.12.0
beegee-tokyo/DHT sensor library for ESPx@^1.19
adafruit/Adafruit SSD1306@^2.5.13
knolleary/PubSubClient@^2.8
madhephaestus/ESP32Servo@^0.11.0
bblanchon/ArduinoJson @ ^6.21.5
-
Clone the Repository
git clone https://github.com/yourusername/smart-medibox.git cd smart-medibox
-
Hardware Assembly
- Follow the circuit diagram in
diagram.json
- Connect all components according to pin definitions in
MediBoxConfig.h
- Follow the circuit diagram in
-
Software Configuration
- Update WiFi credentials in
main.cpp
- Configure MQTT broker settings if needed
- Adjust pin assignments in
MediBoxConfig.h
if necessary
- Update WiFi credentials in
-
Build and Upload
pio run --target upload
#define BUZZER 5
#define LED_1 15 // Red: Temperature warning
#define LED_2 16 // Blue: Humidity warning
#define LED_3 17 // Yellow: Alarm ringing
#define PB_CANCEL 34
#define PB_OK 32
#define PB_UP 33
#define PB_DOWN 35
#define DHTPIN 12
#define LDR_PIN 36
#define SERVO_PIN 18
- SDA: GPIO 21
- SCL: GPIO 22
- OLED Address: 0x3C
- Power on the device
- Connect to "Wokwi-GUEST" WiFi network
- Set your timezone through the menu system
- Configure your medicine alarms
- Press OK to enter main menu
- Navigate to "Set Alarm 1" or "Set Alarm 2"
- Use UP/DOWN to adjust hours and minutes
- Press OK to confirm each setting
- OK: Enter menu / Confirm selection
- CANCEL: Go back / Cancel operation
- UP/DOWN: Navigate options / Adjust values
- OK during alarm: Snooze for 5 minutes
- CANCEL during alarm: Turn off alarm
medibox/data
: Binary sensor data (12 bytes)- Light intensity (4 bytes, float)
- Temperature (4 bytes, float)
- Servo angle (4 bytes, float)
medibox/cfg/ts
: Sampling interval configurationmedibox/cfg/tu
: Sending interval configurationmedibox/cfg/servo
: Servo parameters (JSON format)
- Default: test.mosquitto.org:1883
- Client ID: ESP32Client-[random]
The servo motor angle is calculated using environmental factors:
ฮธ = ฮธโ + (180 - ฮธโ) ร I ร ฮณ ร ln(ts/tu) ร (T/Tmed)
Where:
ฮธโ
: Base offset angleI
: Light intensity (0-1)ฮณ
: Gamma correction factorts
: Sampling intervaltu
: Sending intervalT
: Current temperatureTmed
: Reference temperature
- Normal Range: 24ยฐC - 32ยฐC
- Warning: Red LED flashes + audio alert
- Normal Range: 65% - 80%
- Warning: Blue LED flashes + audio alert
- Continuous LDR readings
- Influences dispensing mechanism
- Data logged via MQTT
// Timing
sampling_interval = 5.0 // seconds
sending_interval = 120.0 // seconds
// Servo Control
theta_offset = 30.0 // degrees
gamma = 0.75 // correction factor
T_med = 30.0 // reference temperature (ยฐC)
// Alarms
SNOOZE_DURATION = 5 // minutes
MAX_ALARMS = 4 // total alarms
Parameters can be updated via MQTT:
// Servo configuration
{
"theta": 45.0,
"gamma": 0.8,
"Tmed": 25.0
}
smart-medibox/
โโโ src/
โ โโโ main.cpp # Main application logic
โ โโโ MediBoxAlarm.cpp/h # Alarm management
โ โโโ MediBoxConfig.cpp/h # Configuration settings
โ โโโ MediBoxDisplay.cpp/h # OLED display control
โ โโโ MediBoxMenu.cpp/h # Menu system
โ โโโ MediBoxSensor.cpp/h # Sensor readings
โ โโโ MediBoxTime.cpp/h # Time management
โโโ platformio.ini # PlatformIO configuration
โโโ diagram.json # Wokwi circuit diagram
โโโ flows.json # Node-RED MQTT flows
โโโ README.md # This file
- Web-based configuration interface
- Mobile app integration
- Multi-user support with individual profiles
- Prescription schedule integration
- Voice command support
- Battery backup system
- Dose counting and inventory tracking
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
Savindu Wickramasinghe
- Electronics and Telecommunication Engineering Undergraduate
- University of Moratuwa, Sri Lanka
- ๐ง [email protected]
- ๐ LinkedIn
- ๐ป GitHub
- University of Moratuwa Electronics and Telecommunication Engineering Department
- Wokwi simulator for circuit design and testing
- Open source community for excellent libraries
- Node-RED community for MQTT integration examples
If you have any questions or need help with the project, feel free to:
- Open an issue on GitHub
- Contact me via email
- Check the Wiki for detailed documentation
โญ If you found this project helpful, please give it a star!