Build an ESP32 medicine reminder box with four compartments that beeps and lights the right box at dose time, detects when the lid is really opened, and sends due, taken and missed-dose alerts to your phone through ntfy.sh.
Need it ready-made? Buy Ready Project
Forgetting a tablet, or taking the same dose twice, is a real problem for elderly parents, patients on several medicines and anyone with a busy day. A simple phone alarm only tells you the time; it cannot tell whether the medicine was actually taken. This ESP32 medicine reminder box can.
The box has four compartments: Morning, Afternoon, Evening and Night. Each lid carries a small magnet and a reed switch, so the ESP32 knows exactly when a lid is opened. At dose time the right compartment LED blinks, the buzzer beeps and an OLED shows TAKE Morning BOX 1. Opening that lid marks the dose as taken. If nobody opens it within 30 minutes, the dose is marked as missed and an urgent notification goes to a family member’s phone through the free ntfy.sh service. All four dose times are set from a web page at http://pillbox.local/.

How It Works
- Clock: after connecting to Wi-Fi, the ESP32 gets the time from NTP servers in the Indian time zone (
IST-5:30). The internal clock keeps running even if Wi-Fi drops later. - Schedule: each compartment is one dose slot with a time and an on/off switch. Times are stored in the ESP32 flash (
Preferences), so they survive a power cut. - Dose due: when the clock reaches a slot time, the slot changes to DUE: its LED blinks fast, the buzzer beeps six times and a high-priority notification “Take the Morning dose from box 1” is sent. The beep and the phone reminder repeat every 5 minutes.
- Lid detection: the four reed switches are scanned every 10 ms and must be stable for 50 ms (debounce). Opening the lid of a DUE compartment marks it TAKEN, stops the alarm and sends a “Dose taken at 08:03” message, so a family member at work knows it was done.
- Wrong box or too early: opening a compartment before its time gives three warning beeps and an “opened early” notification, but does not count as taken. This helps to avoid double doses.
- Missed dose: if the lid is still closed 30 minutes after the dose time, the slot becomes MISSED, its LED blinks slowly for the rest of the day and an urgent notification is sent. Taken and missed totals are stored in flash.
- Button: a short press silences the buzzer and snoozes the reminder for 10 minutes. A 3-second press skips the current dose (for example when the doctor stopped it for a day).
- Midnight reset: at the start of each day all slots go back to waiting. After a power cut, a dose whose window already passed is marked skipped instead of ringing late.
- Web page and JSON: the page shows today’s status of every slot with colours, lets you change times and enable or disable slots, and lists the last 8 events.
/statusreturns JSON for Home Assistant or other tools.
Components Required
- ESP32 DevKit V1 (ESP32-WROOM-32, 30 or 38 pin) – 1
- Reed switch module or bare glass reed switch – 4
- Small neodymium magnets (6–10 mm) – 4
- 0.96″ SSD1306 I2C OLED 128×64 – 1
- 5 mm LEDs (any colour) + 220 Ω resistors – 4 sets
- 5 V active buzzer – 1
- BC547 NPN transistor + 1 kΩ base resistor – 1 set
- 12 mm tactile push button – 1
- 4-compartment pill organiser or a 3D-printed/wooden box with 4 hinged lids – 1
- 5 V 1 A USB adapter + micro-USB cable – 1
- Perfboard, jumper wires, hot glue – 1 set
Wiring Table
| Part / pin | ESP32 pin | Notes |
|---|---|---|
| Reed switch box 1 (Morning) | GPIO32 and GND | Internal pull-up; magnet in the lid |
| Reed switch box 2 (Afternoon) | GPIO33 and GND | Same as above |
| Reed switch box 3 (Evening) | GPIO25 and GND | Same as above |
| Reed switch box 4 (Night) | GPIO26 and GND | Same as above |
| LED box 1 / 2 / 3 / 4 | GPIO16 / 17 / 18 / 19 through 220 Ω | Cathode (short leg) to GND; place each LED next to its compartment |
| BC547 base | GPIO23 through 1 kΩ | Emitter to GND |
| Active buzzer | + to VIN (5V), − to BC547 collector | 5 V buzzer driven by the transistor |
| Push button | GPIO27 and GND | Internal pull-up; short = snooze, 3 s = skip |
| OLED VCC / GND | 3V3 / GND | SSD1306 128×64, address 0x3C |
| OLED SDA / SCL | GPIO21 / GPIO22 | Default ESP32 I2C pins |
| Power | Micro-USB | 5 V 1 A phone adapter |
Connection Diagram (Schematic)
The image above gives the overview. The drawing below is the exact pin-by-pin wiring; follow this one when you solder.
Building the Box
- Use a 4-compartment pill organiser with separate lids, or make one from 3 mm plywood or a 3D print. Keep the electronics in a separate base or back section, away from the medicines.
- Glue a reed switch on the box wall under each lid with hot glue, and a small magnet inside the lid so that it sits within about 10 mm of the reed when the lid is closed. Test with a multimeter: closed lid = continuity.
- Fix one LED next to each compartment and the OLED, buzzer and button on the front panel.
- Mark each compartment clearly: 1 Morning, 2 Afternoon, 3 Evening, 4 Night.
Set Up the ntfy Phone App
- Install the free ntfy app from the Play Store or App Store (no account needed) on your phone and on the phones of family members who should get the alerts.
- Tap + and subscribe to a topic with a long, hard-to-guess name, for example
papa-medicine-box-8k2v9. Anyone who knows the topic can read the messages, so never use a simple word or a person’s name alone. - Put the same name in
NTFY_TOPICin the code, and replaceYOUR_WIFI_SSIDandYOUR_WIFI_PASSWORDwith your own Wi-Fi details.
Code
Install the ESP32 board package in the Arduino IDE and select ESP32 Dev Module. Install Adafruit SSD1306 and Adafruit GFX from the Library Manager. WiFi, WebServer, ESPmDNS, Preferences and HTTPClient come with the ESP32 core. The sketch is non-blocking: lids, button, buzzer, LEDs, display, web server and schedule all run together in loop().
/*
ESP32 Smart Medicine Reminder Box
4 compartments with lid reed switches + LEDs, buzzer, SSD1306 OLED,
NTP clock, web page to set dose times and ntfy.sh phone alerts
(dose due, dose taken, dose missed, lid opened at the wrong time).
Project #80 - ardiunoprojecthub.online
Pins (ESP32 DevKit V1, 30/38-pin):
Lid reed switches (to GND, INPUT_PULLUP) -> GPIO32, GPIO33, GPIO25, GPIO26
lid closed = magnet near = switch closed = LOW
lid open = magnet away = switch open = HIGH
Compartment LEDs (each through 220 ohm) -> GPIO16, GPIO17, GPIO18, GPIO19
Buzzer driver: GPIO23 -> 1k -> BC547 base (5 V active buzzer on collector)
Push button (to GND, INPUT_PULLUP) -> GPIO27 short = snooze, 3 s = skip dose
OLED SDA -> GPIO21, OLED SCL -> GPIO22 (SSD1306 128x64, address 0x3C)
*/
#include <WiFi.h>
#include <WebServer.h>
#include <ESPmDNS.h>
#include <Preferences.h>
#include <HTTPClient.h>
#include <WiFiClientSecure.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <time.h>
// ---------- user settings ----------
const char* WIFI_SSID = "YOUR_WIFI_SSID"; // put your Wi-Fi name here
const char* WIFI_PASS = "YOUR_WIFI_PASSWORD"; // put your Wi-Fi password here
const char* NTFY_TOPIC = "your-long-secret-pillbox-topic"; // same topic in the ntfy app
const char* TZ_INFO = "IST-5:30"; // POSIX time zone (India)
const uint16_t MISSED_AFTER_MIN = 30; // dose counts as missed after this
const uint16_t SNOOZE_MIN = 10; // button snooze time
const uint16_t REMIND_EVERY_MIN = 5; // repeat beep + phone reminder
// ---------- pins ----------
const uint8_t PIN_REED[4] = {32, 33, 25, 26};
const uint8_t PIN_LED[4] = {16, 17, 18, 19};
const uint8_t PIN_BUZZER = 23;
const uint8_t PIN_BUTTON = 27;
Adafruit_SSD1306 oled(128, 64, &Wire, -1);
WebServer server(80);
Preferences prefs;
// ---------- dose slots (one slot = one compartment) ----------
enum SlotState : uint8_t { WAITING, DUE, TAKEN, MISSED, SKIPPED };
const char* STATE_NAME[] = {"waiting", "DUE", "taken", "MISSED", "skipped"};
struct Slot {
char name[12]; // e.g. "Morning"
int16_t minute; // dose time in minutes after midnight
bool enabled;
SlotState state;
int16_t doneAt; // minute of the day it was taken / missed, -1 = none
unsigned long dueMs; // millis() when it became due
unsigned long nextRemindMs;
};
Slot slot[4] = {
{"Morning", 8 * 60, true, WAITING, -1, 0, 0},
{"Afternoon", 13 * 60 + 30, true, WAITING, -1, 0, 0},
{"Evening", 18 * 60, true, WAITING, -1, 0, 0},
{"Night", 21 * 60 + 30, true, WAITING, -1, 0, 0},
};
bool lidOpen[4]; // debounced lid state
uint8_t lidCount[4]; // debounce counters
int today = -1; // day of year, for the midnight reset
int lastMinuteChecked = -1;
bool timeValid = false;
uint16_t takenTotal = 0, missedTotal = 0; // lifetime counters (Preferences)
// small event log for the web page
String logLines[8];
uint8_t logHead = 0;
// buzzer pattern (non-blocking)
uint8_t beepsLeft = 0;
unsigned long beepMs = 0;
bool buzzerOn = false;
// button
unsigned long btnDownMs = 0;
bool btnWasDown = false, longDone = false;
// ---------- helpers ----------
bool getNow(struct tm& t) {
if (!getLocalTime(&t, 10)) return false;
return t.tm_year > (2023 - 1900); // not synced yet = year 1970
}
String hhmm(int m) {
if (m < 0) return "--:--";
char b[12];
snprintf(b, sizeof(b), "%02d:%02d", m / 60, m % 60);
return String(b);
}
int nowMinute() {
struct tm t;
if (!getNow(t)) return -1;
return t.tm_hour * 60 + t.tm_min;
}
void addLog(const String& s) {
logLines[logHead] = hhmm(nowMinute()) + " " + s;
logHead = (logHead + 1) % 8;
Serial.println(s);
}
void beep(uint8_t count) { beepsLeft = count * 2; beepMs = 0; }
void serviceBuzzer() {
if (beepsLeft == 0) return;
if (millis() - beepMs < 180) return;
beepMs = millis();
buzzerOn = !buzzerOn;
digitalWrite(PIN_BUZZER, buzzerOn);
beepsLeft--;
if (beepsLeft == 0) { buzzerOn = false; digitalWrite(PIN_BUZZER, LOW); }
}
// ---------- ntfy phone notification ----------
void notifyPhone(const String& title, const String& msg, const char* prio) {
if (WiFi.status() != WL_CONNECTED) { Serial.println("ntfy skipped: no Wi-Fi"); return; }
WiFiClientSecure client;
client.setInsecure(); // HTTPS without certificate pinning (simple home use)
HTTPClient http;
http.setTimeout(5000);
if (!http.begin(client, String("https://ntfy.sh/") + NTFY_TOPIC)) return;
http.addHeader("Title", title);
http.addHeader("Priority", prio); // "default", "high" or "urgent"
http.addHeader("Tags", "pill");
int code = http.POST(msg);
Serial.printf("ntfy response: %d\n", code);
http.end();
}
// ---------- storage ----------
void loadSettings() {
prefs.begin("pillbox", false);
for (int i = 0; i < 4; i++) {
String k = "m" + String(i);
slot[i].minute = prefs.getShort(k.c_str(), slot[i].minute);
k = "e" + String(i);
slot[i].enabled = prefs.getBool(k.c_str(), slot[i].enabled);
}
takenTotal = prefs.getUShort("taken", 0);
missedTotal = prefs.getUShort("missed", 0);
}
void saveSettings() {
for (int i = 0; i < 4; i++) {
prefs.putShort(("m" + String(i)).c_str(), slot[i].minute);
prefs.putBool(("e" + String(i)).c_str(), slot[i].enabled);
}
}
// ---------- dose logic ----------
void newDay(int curMin) {
// midnight (or first time sync): reset all slots; doses already past are not alarmed
for (int i = 0; i < 4; i++) {
slot[i].state = WAITING;
slot[i].doneAt = -1;
if (curMin >= 0 && slot[i].minute + MISSED_AFTER_MIN <= curMin) slot[i].state = SKIPPED;
}
addLog("New day - schedule reset");
}
void makeDue(int i) {
slot[i].state = DUE;
slot[i].dueMs = millis();
slot[i].nextRemindMs = millis() + REMIND_EVERY_MIN * 60000UL;
beep(6);
addLog(String(slot[i].name) + " dose due (box " + String(i + 1) + ")");
notifyPhone("Medicine time", String("Take the ") + slot[i].name + " dose from box " + String(i + 1) + ".", "high");
}
void markTaken(int i, int curMin) {
slot[i].state = TAKEN;
slot[i].doneAt = curMin;
takenTotal++;
prefs.putUShort("taken", takenTotal);
beepsLeft = 0; digitalWrite(PIN_BUZZER, LOW);
beep(1);
addLog(String(slot[i].name) + " dose taken");
notifyPhone("Dose taken", String(slot[i].name) + " dose taken at " + hhmm(curMin) + ".", "default");
}
void checkSchedule() {
struct tm t;
if (!getNow(t)) { timeValid = false; return; }
int curMin = t.tm_hour * 60 + t.tm_min;
if (!timeValid || t.tm_yday != today) { // first sync or midnight
today = t.tm_yday;
timeValid = true;
newDay(curMin);
}
if (curMin == lastMinuteChecked) return; // run once per minute
lastMinuteChecked = curMin;
for (int i = 0; i < 4; i++) {
Slot& s = slot[i];
if (!s.enabled) continue;
// dose time reached (also catches a reboot within the missed window)
if (s.state == WAITING && curMin >= s.minute && curMin < s.minute + MISSED_AFTER_MIN) makeDue(i);
// still not taken after the window -> missed
if (s.state == DUE && curMin >= s.minute + MISSED_AFTER_MIN) {
s.state = MISSED;
s.doneAt = curMin;
missedTotal++;
prefs.putUShort("missed", missedTotal);
addLog(String(s.name) + " dose MISSED");
notifyPhone("Dose missed", String(s.name) + " dose (box " + String(i + 1) + ") was not taken by " + hhmm(curMin) + ".", "urgent");
}
}
}
void serviceReminders() {
for (int i = 0; i < 4; i++) {
Slot& s = slot[i];
if (s.state != DUE) continue;
if ((long)(millis() - s.nextRemindMs) >= 0) {
s.nextRemindMs = millis() + REMIND_EVERY_MIN * 60000UL;
beep(6);
notifyPhone("Medicine reminder", String("Still waiting: ") + s.name + " dose in box " + String(i + 1) + ".", "high");
}
}
}
// ---------- lids ----------
void readLids() {
static unsigned long lastScan = 0;
if (millis() - lastScan < 10) return; // scan every 10 ms
lastScan = millis();
for (int i = 0; i < 4; i++) {
bool raw = digitalRead(PIN_REED[i]) == HIGH; // HIGH = magnet away = lid open
if (raw != lidOpen[i]) {
if (++lidCount[i] >= 5) { // stable for 50 ms
lidOpen[i] = raw;
lidCount[i] = 0;
if (raw) onLidOpened(i);
}
} else {
lidCount[i] = 0;
}
}
}
void onLidOpened(int i) {
int curMin = nowMinute();
if (slot[i].state == DUE) {
markTaken(i, curMin);
} else if (slot[i].enabled && slot[i].state == WAITING) {
// opened before its time: warn, but do not count it as taken
beep(3);
addLog("Box " + String(i + 1) + " opened early");
notifyPhone("Box opened early", "Box " + String(i + 1) + " (" + slot[i].name + ") was opened before " + hhmm(slot[i].minute) + ".", "default");
} else {
addLog("Box " + String(i + 1) + " opened");
}
}
// ---------- button ----------
void readButton() {
bool down = digitalRead(PIN_BUTTON) == LOW;
if (down && !btnWasDown) { btnDownMs = millis(); longDone = false; }
if (down && !longDone && millis() - btnDownMs > 3000) {
longDone = true; // long press: skip all due doses
for (int i = 0; i < 4; i++) if (slot[i].state == DUE) {
slot[i].state = SKIPPED;
slot[i].doneAt = nowMinute();
addLog(String(slot[i].name) + " dose skipped by button");
}
beep(2);
}
if (!down && btnWasDown && !longDone && millis() - btnDownMs > 40) {
// short press: silence now, remind again after SNOOZE_MIN
beepsLeft = 0; digitalWrite(PIN_BUZZER, LOW);
for (int i = 0; i < 4; i++) if (slot[i].state == DUE)
slot[i].nextRemindMs = millis() + SNOOZE_MIN * 60000UL;
addLog("Snoozed");
}
btnWasDown = down;
}
// ---------- LEDs ----------
void updateLeds() {
bool fast = (millis() / 250) % 2;
bool slow = (millis() / 1000) % 2;
for (int i = 0; i < 4; i++) {
bool on = false;
if (slot[i].state == DUE) on = fast; // take from this box
else if (slot[i].state == MISSED) on = slow; // missed today
digitalWrite(PIN_LED[i], on);
}
}
// ---------- OLED ----------
void drawOled() {
static unsigned long last = 0;
if (millis() - last < 300) return;
last = millis();
oled.clearDisplay();
oled.setTextColor(SSD1306_WHITE);
oled.setTextSize(2);
oled.setCursor(0, 0);
int m = nowMinute();
oled.print(m >= 0 ? hhmm(m) : String("--:--"));
oled.setTextSize(1);
oled.setCursor(72, 0);
oled.print(WiFi.status() == WL_CONNECTED ? "WiFi OK" : "no WiFi");
oled.setCursor(72, 8);
oled.printf("T%u M%u", takenTotal, missedTotal);
int due = -1;
for (int i = 0; i < 4; i++) if (slot[i].state == DUE) { due = i; break; }
if (due >= 0 && (millis() / 500) % 2) {
oled.fillRect(0, 18, 128, 14, SSD1306_WHITE);
oled.setTextColor(SSD1306_BLACK);
oled.setCursor(2, 21);
oled.printf("TAKE %s BOX %d", slot[due].name, due + 1);
oled.setTextColor(SSD1306_WHITE);
}
for (int i = 0; i < 4; i++) {
oled.setCursor(0, 34 + i * 8);
oled.printf("%d %-5.5s %s %s", i + 1, slot[i].name, hhmm(slot[i].minute).c_str(),
slot[i].enabled ? STATE_NAME[slot[i].state] : "off");
}
oled.display();
}
// ---------- web page ----------
String page() {
String h = F("<!DOCTYPE html><html><head><meta name='viewport' content='width=device-width,initial-scale=1'>"
"<meta http-equiv='refresh' content='30'><title>Medicine Box</title>"
"<style>body{font-family:Arial;margin:16px;max-width:520px}table{border-collapse:collapse;width:100%}"
"td,th{border:1px solid #ccc;padding:6px}.DUE{background:#ffe082}.MISSED{background:#ef9a9a}"
".taken{background:#c8e6c9}button{padding:8px 16px;margin-top:10px}</style></head><body>"
"<h2>Smart Medicine Box</h2>");
h += "<p>Time: <b>" + hhmm(nowMinute()) + "</b> Taken: " + String(takenTotal) + " Missed: " + String(missedTotal) + "</p>";
h += F("<form action='/save' method='POST'><table><tr><th>Box</th><th>Dose</th><th>Time</th><th>On</th><th>Today</th></tr>");
for (int i = 0; i < 4; i++) {
h += "<tr class='" + String(STATE_NAME[slot[i].state]) + "'><td>" + String(i + 1) + "</td><td>" + slot[i].name + "</td>";
h += "<td><input type='time' name='t" + String(i) + "' value='" + hhmm(slot[i].minute) + "'></td>";
h += "<td><input type='checkbox' name='e" + String(i) + "'" + (slot[i].enabled ? " checked" : "") + "></td>";
h += "<td>" + String(slot[i].enabled ? STATE_NAME[slot[i].state] : "off");
if (slot[i].doneAt >= 0) h += " " + hhmm(slot[i].doneAt);
h += "</td></tr>";
}
h += F("</table><button type='submit'>Save schedule</button></form><h3>Recent events</h3><pre>");
for (int k = 0; k < 8; k++) {
const String& l = logLines[(logHead + 7 - k) % 8]; // newest first
if (l.length()) h += l + "\n";
}
h += F("</pre></body></html>");
return h;
}
int parseTime(const String& v) { // "HH:MM" -> minutes, -1 if invalid
if (v.length() < 5 || v[2] != ':') return -1;
int hh = v.substring(0, 2).toInt(), mm = v.substring(3, 5).toInt();
if (hh < 0 || hh > 23 || mm < 0 || mm > 59) return -1;
return hh * 60 + mm;
}
void handleSave() {
int curMin = nowMinute();
for (int i = 0; i < 4; i++) {
int m = parseTime(server.arg("t" + String(i)));
if (m >= 0 && m != slot[i].minute) {
slot[i].minute = m;
// a changed time later today becomes active again
if (slot[i].state != DUE) slot[i].state = (curMin >= 0 && m + MISSED_AFTER_MIN <= curMin) ? SKIPPED : WAITING;
}
slot[i].enabled = server.hasArg("e" + String(i));
}
saveSettings();
lastMinuteChecked = -1; // re-check the schedule now
addLog("Schedule saved from web");
server.sendHeader("Location", "/");
server.send(303);
}
void handleStatus() {
String j = "{\"time\":\"" + hhmm(nowMinute()) + "\",\"taken\":" + String(takenTotal) + ",\"missed\":" + String(missedTotal) + ",\"slots\":[";
for (int i = 0; i < 4; i++) {
if (i) j += ",";
j += "{\"box\":" + String(i + 1) + ",\"name\":\"" + slot[i].name + "\",\"time\":\"" + hhmm(slot[i].minute) +
"\",\"enabled\":" + (slot[i].enabled ? "true" : "false") + ",\"state\":\"" + STATE_NAME[slot[i].state] +
"\",\"lid_open\":" + (lidOpen[i] ? "true" : "false") + "}";
}
j += "]}";
server.send(200, "application/json", j);
}
// ---------- setup / loop ----------
void setup() {
Serial.begin(115200);
for (int i = 0; i < 4; i++) {
pinMode(PIN_REED[i], INPUT_PULLUP);
pinMode(PIN_LED[i], OUTPUT);
lidOpen[i] = digitalRead(PIN_REED[i]) == HIGH; // start state, no event at boot
}
pinMode(PIN_BUZZER, OUTPUT);
digitalWrite(PIN_BUZZER, LOW);
pinMode(PIN_BUTTON, INPUT_PULLUP);
Wire.begin(21, 22);
if (!oled.begin(SSD1306_SWITCHCAPVCC, 0x3C)) Serial.println("OLED not found (check SDA 21 / SCL 22)");
oled.clearDisplay();
oled.setTextColor(SSD1306_WHITE);
oled.setCursor(0, 0);
oled.println("Medicine Box");
oled.println("Connecting Wi-Fi...");
oled.display();
loadSettings();
WiFi.mode(WIFI_STA);
WiFi.setAutoReconnect(true);
WiFi.begin(WIFI_SSID, WIFI_PASS);
unsigned long t0 = millis();
while (WiFi.status() != WL_CONNECTED && millis() - t0 < 15000) delay(250);
if (WiFi.status() == WL_CONNECTED) Serial.printf("connected, IP %s\n", WiFi.localIP().toString().c_str());
else Serial.println("Wi-Fi not connected yet, will keep trying");
configTzTime(TZ_INFO, "pool.ntp.org", "time.google.com"); // the internal RTC keeps time after the first sync
MDNS.begin("pillbox"); // http://pillbox.local/
server.on("/", []() { server.send(200, "text/html", page()); });
server.on("/save", HTTP_POST, handleSave);
server.on("/status", handleStatus);
server.begin();
beep(1);
addLog("Started");
}
void loop() {
server.handleClient();
readLids();
readButton();
checkSchedule();
serviceReminders();
serviceBuzzer();
updateLeds();
drawOled();
}
Testing
- Upload the code and open the Serial Monitor at 115200 baud. You should see connected, IP …, and the OLED should show the correct time within a few seconds.
- Open
http://pillbox.local/(or the IP address) and set the Morning time two minutes ahead. Save. - At that time, LED 1 should blink, the buzzer should beep and your phone should show “Medicine time”. Open lid 1: the alarm stops and “Dose taken” arrives.
- Set another slot one minute ahead and do not open it. For a quick test, temporarily change
MISSED_AFTER_MINto 2 and check that the “Dose missed” alert arrives. - Open a compartment whose time has not come yet: you should hear three short beeps and get an “opened early” message.
Troubleshooting
| Problem | Fix |
|---|---|
| OLED shows –:– for a long time | The ESP32 has no internet, so NTP cannot set the clock. Check the Wi-Fi name and password and that the router has 2.4 GHz turned on. |
| A dose is marked taken without opening the lid | The magnet is too weak or too far, so the reed switch flickers. Move the magnet closer, or use a stronger one. Check that each lid’s magnet does not reach the neighbouring reed switch. |
| Opening the lid does nothing | Check the reed switch with a multimeter and that it is wired to the correct GPIO and GND. Reed switches are fragile glass; a cracked one stays open. |
| Wrong compartment reacts | The reed wires are swapped. Box 1 must be on GPIO32, box 2 on GPIO33, box 3 on GPIO25 and box 4 on GPIO26, or change PIN_REED in the code. |
| No phone notification (ntfy response -1) | No internet, or the topic in the code and in the app is different. The topic name is case-sensitive. |
| Board resets when the buzzer beeps | Use the BC547 driver and a good 5 V 1 A adapter. Never power a 5 V buzzer directly from a GPIO. |
| pillbox.local does not open | Some Android phones do not support mDNS. Use the IP address shown in the Serial Monitor, or reserve it in your router. |
Ideas to Extend
- Add a DS3231 RTC module so the clock is correct even without internet after a power cut.
- Use 7 or 14 compartments with a 74HC165 shift register for a full week organiser.
- Add an HX711 load cell under each compartment to check that a tablet was really removed, not just the lid opened.
This project is a reminder aid only. Always follow the doctor’s instructions for medicines and dose timing.