PIR Sensor for Medicine Reminder: Never Miss a Dose

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

OUT

GPIO 4

SDA

GPIO 21

SCL

GPIO 22

TX

GPIO 16

RX

GPIO 17

Anode

GPIO 5

Anode

GPIO 18

Anode

GPIO 19

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

  1. Record reminder messages and place on SD card
  2. Set RTC time using example sketch
  3. Assemble circuit and test
  4. Mount PIR sensor near medicine cabinet
  5. Install reed switch on cabinet door and frame
  6. Position speaker where message can be heard clearly
  7. 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.

Leave a Reply

Your email address will not be published. Required fields are marked *

Component Pin ESP32 Pin
PIR Sensor DS3231 RTC DS3231 RTC DFPlayer Mini DFPlayer Mini Red LED Green LED Blue LED Reed Switch