Build it step by step
0 of 6 doneSet up the clock
Wire the DS3231, upload once with the rtc.adjust line enabled, then remove it and upload again.
Build the compartments
Make seven lids (a printed or cardboard box). Fix a magnet to each lid and a reed switch in the box beside it, closed while the lid is shut.
Wire the lights
One green LED with 220 Ω per compartment on D2 to D8.
Wire the reed switches
Each switch between its pin (D9 to D13, A0, A1) and GND.
Add the buzzer and display
Buzzer to A2, LCD on A4 and A5.
Test the alarm
Change a dose time to one minute ahead. Today's light and buzzer should start; open that lid to stop them.
How do you build a medicine reminder pill box?
A seven-day pill box lights today's compartment at set dose times and beeps until that lid is opened, and counts missed doses. You need Arduino Nano, DS3231 RTC module, LED 5 mm green × 7, Resistor 220 Ω × 7, Door reed switch MC-38 × 7, Neodymium magnets (10 × 3 mm) × 7, Active buzzer 5 V, 16x2 LCD with I2C backpack (PCF8574), Breadboard 1660 points (with base) and Jumper wires male to male (40 pcs, 20 cm). It takes 6 steps and about 120 minutes.
- Level
- Beginner
- Time
- About 120 min
- Parts
- 10
Parts list
- Development BoardsBuyArduino Nano × 1
- SensorsBuy
- SemiconductorsBuyLED 5 mm green × 7
- PassivesBuyResistor 220 Ω × 7
- SensorsBuy
- Mechanical & Hardware
- Motors & ActuatorsBuy
- DisplaysBuy
- PrototypingBuy
- PrototypingBuy
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| LED 1 to 7 anodes through 220 Ω | Nano D2 to D8 | One light per day (1 is Sunday) |
| LED cathodes | GND | Common ground |
| Reed switch 1 to 7 | Nano D9, D10, D11, D12, D13, A0, A1 (other legs to GND) | One per lid; closed when the lid and magnet are together |
| Active buzzer + / − | Nano A2 / GND | Reminder |
| DS3231 and LCD SDA / SCL | Nano A4 / A5 | Shared I2C bus |
| DS3231 and LCD VCC / GND | Nano 5V / GND | Power |
Code
Arduino IDE, board "Arduino Nano" (processor ATmega328P, or ATmega328P (Old Bootloader) for clones). Install "RTClib" by Adafruit and "LiquidCrystal I2C" by Frank de Brabander. Set the clock once by uncommenting the rtc.adjust line, upload, then comment it again and upload. The box is a reminder aid, not a medical device.
Runs on a virtual Arduino Nano in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).
#include <Wire.h>
#include <RTClib.h> // "RTClib" by Adafruit
#include <LiquidCrystal_I2C.h>
#include <EEPROM.h>
RTC_DS3231 rtc;
LiquidCrystal_I2C lcd(0x27, 16, 2);
const byte LEDS[7] = {2, 3, 4, 5, 6, 7, 8};
const byte REEDS[7] = {9, 10, 11, 12, 13, A0, A1};
const byte BUZ = A2;
const byte DOSE_H[] = {8, 20}, DOSE_M[] = {0, 0}; // doses at 08:00 and 20:00
const unsigned long WINDOW_MS = 30UL * 60 * 1000; // 30 minutes to open the lid
bool ringing = false;
byte day = 0;
unsigned long ringStart = 0;
int lastKey = -1;
unsigned int missed;
void setup() {
for (byte i = 0; i < 7; i++) { pinMode(LEDS[i], OUTPUT); pinMode(REEDS[i], INPUT_PULLUP); }
pinMode(BUZ, OUTPUT);
lcd.init(); lcd.backlight();
rtc.begin(); // set once: rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
EEPROM.get(0, missed);
if (missed == 0xFFFF) missed = 0;
}
bool lidOpen(byte d) { return digitalRead(REEDS[d]) == HIGH; } // magnet away: switch open: pin high
void loop() {
DateTime now = rtc.now();
day = now.dayOfTheWeek(); // 0 Sunday to 6 Saturday
for (byte s = 0; s < 2; s++) {
int key = now.day() * 10 + s;
if (now.hour() == DOSE_H[s] && now.minute() == DOSE_M[s] && key != lastKey && !ringing) {
lastKey = key; ringing = true; ringStart = millis();
}
}
if (ringing) {
bool beep = (millis() / 500) % 2;
digitalWrite(LEDS[day], beep);
digitalWrite(BUZ, beep);
if (lidOpen(day)) { ringing = false; } // taken
else if (millis() - ringStart > WINDOW_MS) { // missed
ringing = false; missed++; EEPROM.put(0, missed);
}
if (!ringing) { digitalWrite(BUZ, LOW); digitalWrite(LEDS[day], LOW); }
}
static unsigned long lastLcd = 0;
if (millis() - lastLcd > 500) {
lastLcd = millis();
char b[17];
snprintf(b, sizeof b, "%02d:%02d Day %d ", now.hour(), now.minute(), day + 1);
lcd.setCursor(0, 0); lcd.print(b);
snprintf(b, sizeof b, "Missed: %u ", missed);
lcd.setCursor(0, 1); lcd.print(b);
}
}Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| At dose time | Today's LED and the buzzer start beeping |
| Open the right lid | Alarm stops at once |
| Leave it for 30 minutes | Alarm stops and the Missed count goes up by one |
| Power off and on | The missed count is kept and the clock keeps time from the DS3231 |
If it does not work
The alarm never stops even when the lid is open
The reed logic may be reversed. If the switch is closed with the lid open, flip the magnet or swap HIGH and LOW in lidOpen.
The clock is wrong
Set it again with rtc.adjust and replace the CR2032 battery on the DS3231.
The LCD is blank
Adjust the contrast and try 0x3F.
Wrong compartment lights
dayOfTheWeek counts from Sunday = 0. Wire LED 1 to Sunday.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the medicine reminder pill box?
Arduino Nano, DS3231 RTC module, LED 5 mm green × 7, Resistor 220 Ω × 7, Door reed switch MC-38 × 7, Neodymium magnets (10 × 3 mm) × 7, Active buzzer 5 V, 16x2 LCD with I2C backpack (PCF8574), Breadboard 1660 points (with base) and Jumper wires male to male (40 pcs, 20 cm).
How long does the medicine reminder pill box take to build?
About 120 minutes for a beginner maker, in 6 steps.
How do I know the medicine reminder pill box works?
At dose time: Today's LED and the buzzer start beeping. Open the right lid: Alarm stops at once. Leave it for 30 minutes: Alarm stops and the Missed count goes up by one.
The alarm never stops even when the lid is open: what should I check?
The reed logic may be reversed. If the switch is closed with the lid open, flip the magnet or swap HIGH and LOW in lidOpen.
The clock is wrong: what should I check?
Set it again with rtc.adjust and replace the CR2032 battery on the DS3231.
The LCD is blank: what should I check?
Adjust the contrast and try 0x3F.
Wrong compartment lights: what should I check?
dayOfTheWeek counts from Sunday = 0. Wire LED 1 to Sunday.
