Project Overview
This project creates a medicine reminder system that helps elderly or forgetful individuals remember to take their medication. A PIR sensor detects when someone approaches the medicine cabinet, and if it is time for medication, the system plays a reminder message and lights up LEDs.
Difficulty: Intermediate
Estimated time: 2-3 hours
Estimated cost: $30-40
How It Works
A PIR sensor at the medicine cabinet detects when someone approaches. The system checks the current time against a schedule of medication times. If it is within the reminder window, it plays a recorded message (via DFPlayer Mini) and lights up LEDs. If the person opens the cabinet (detected by a reed switch), the reminder is marked as taken.
Materials Needed
- ESP32 or Arduino Uno (1)
- HC-SR501 PIR sensor (1)
- DS3231 Real-Time Clock (1)
- DFPlayer Mini MP3 module (1)
- MicroSD card with reminder audio files
- Small speaker (3W, 4-8Ω)
- LEDs (red, green, blue) for status
- 220Ω resistors for LEDs
- Reed switch for cabinet door detection
- Magnet
- Jumper wires
- Power supply (5V 2A)
Circuit Diagram
Connection Table
| Component |
Pin |
ESP32 Pin |
PIR Sensor |
OUT
GPIO 4
DS3231 RTC |
SDA
GPIO 21
DS3231 RTC |
SCL
GPIO 22
DFPlayer Mini |
TX
GPIO 16
DFPlayer Mini |
RX
GPIO 17
Red LED |
Anode
GPIO 5
Green LED |
Anode
GPIO 18
Blue LED |
Anode
GPIO 19
Reed Switch |
One side
GPIO 23
表
Arduino Code
// Medicine Reminder System
#include <Wire.h>
#include <RTClib.h>
#include <SoftwareSerial.h>
#include <DFRobotDFPlayerMini.h>
RTC_DS3231 rtc;
SoftwareSerial mySoftwareSerial(16, 17);
DFRobotDFPlayerMini myDFPlayer;
const int pirPin = 4;
const int redLedPin = 5;
const int greenLedPin = 18;
const int blueLedPin = 19;
const int doorSensorPin = 23;
struct MedTime {
int hour;
int minute;
int messageFile;
bool taken;
};
MedTime medTimes[] = {
{8, 0, 1, false},
{12, 0, 2, false},
{18, 0, 3, false}
};
const int numMedTimes = 3;
bool reminderActive = false;
int activeMedIndex = -1;
unsigned long lastMotionTime = 0;
const unsigned long reminderDuration = 60000;
void setup() {
Serial.begin(115200);
pinMode(pirPin, INPUT);
pinMode(redLedPin, OUTPUT);
pinMode(greenLedPin, OUTPUT);
pinMode(blueLedPin, OUTPUT);
pinMode(doorSensorPin, INPUT_PULLUP);
digitalWrite(redLedPin, LOW);
digitalWrite(greenLedPin, LOW);
digitalWrite(blueLedPin, LOW);
rtc.begin();
mySoftwareSerial.begin(9600);
myDFPlayer.begin(mySoftwareSerial);
myDFPlayer.volume(20);
delay(60000);
}
void checkScheduledTimes() {
DateTime now = rtc.now();
int currentHour = now.hour();
int currentMinute = now.minute();
for (int i = 0; i < numMedTimes; i++) {
if (!medTimes[i].taken && currentHour == medTimes[i].hour &&
currentMinute >= medTimes[i].minute && currentMinute < medTimes[i].minute + 30) {
if (!reminderActive) {
reminderActive = true;
activeMedIndex = i;
digitalWrite(blueLedPin, HIGH);
}
return;
}
}
}
void playReminder() {
if (activeMedIndex >= 0) {
myDFPlayer.play(medTimes[activeMedIndex].messageFile);
}
}
void markTaken() {
if (activeMedIndex >= 0) {
medTimes[activeMedIndex].taken = true;
reminderActive = false;
activeMedIndex = -1;
digitalWrite(blueLedPin, LOW);
digitalWrite(greenLedPin, HIGH);
myDFPlayer.play(4);
delay(2000);
digitalWrite(greenLedPin, LOW);
}
}
void loop() {
checkScheduledTimes();
bool motion = digitalRead(pirPin) == HIGH;
bool doorOpen = digitalRead(doorSensorPin) == LOW;
if (reminderActive && motion) {
if (millis() - lastMotionTime > 10000) {
playReminder();
lastMotionTime = millis();
}
digitalWrite(redLedPin, HIGH);
} else {
digitalWrite(redLedPin, LOW);
}
if (doorOpen && reminderActive) markTaken();
if (reminderActive && (millis() - lastMotionTime > reminderDuration)) {
digitalWrite(redLedPin, LOW);
digitalWrite(blueLedPin, LOW);
}
delay(100);
}
Installation Steps
- Record reminder messages and place on SD card
- Set RTC time using example sketch
- Assemble circuit and test
- Mount PIR sensor near medicine cabinet
- Install reed switch on cabinet door and frame
- Position speaker where message can be heard clearly
- Approach cabinet at medication time to test reminder
Project Extensions
- Add Wi-Fi to send alerts to caregivers
- Add servo to dispense pills when door is opened
- Add voice recognition for confirmation
- Track adherence and send reports
- Add RFID to identify which person is taking medication
Conclusion
This medicine reminder system helps ensure medications are taken on time, especially helpful for elderly individuals or anyone who struggles with remembering medications.