Community project

Medication Reminder Countdown

Photo of Medication Reminder Countdown
Generated with AI

Cosplay Allstars

Published November 19, 2026

This project builds a medication reminder system using an ESP32 microcontroller and a round 360x360 SPI display to show countdown timers for multiple medications. The device connects to WiFi, syncs with network time, and stores medication schedules with history tracking in local storage.

The guide includes a complete wiring diagram for connecting the GC9B72 display to the ESP32, a full parts list, the Arduino firmware with web-based configuration interface, and step-by-step assembly instructions. Builders will learn how to set up medication reminders with customizable intervals, view real-time countdowns on the circular display, and access a web dashboard to manage schedules and view medication history.

Wiring diagram

Wiring diagram for Medication Reminder Countdown
Loading diagram…

Gather all the parts

QtyComponent
1

GC9B72 2.1-inch 360x360 round SPI display

3.3 V EstarDyn GC9B72 module; active-high backlight control.

Assemble it in 2 steps

1. Connect display power

With USB unplugged, connect display VCC and BL to 3V3, and GND to GND on the ESP32-S3.

  • Never connect this display to 5 V. It can damage the module.

2. Connect the screen signals

SCL to GPIO12 (clock), SDA to GPIO11 (display data), CS to GPIO10 (screen select), DC to GPIO9 (command or image data), RST to GPIO14 (reset). BL stays connected to 3V3 so the backlight is always on. Leave SDO and TE unconnected.

  • Use short wires. SDA and SCL here are SPI signals, not I2C.
  • This wiring is for the 3.3 V 360x360 GC9B72 breakout module.

Review all connections

1. Connections between "display" and "ESP32"

FunctiondisplayESP32
powerVCC3V3
groundGNDGND
spiSCLGPIO 12
spiSDAGPIO 11
digitalRSTGPIO 14
digitalDCGPIO 9
spiCSGPIO 10
powerBL3V3

Deploy the firmware

#include <Arduino.h>
#include <Arduino_GFX_Library.h>
#include <Arduino_GC9B72.h>
#include <WiFi.h>
#include <WiFiManager.h>
#include <WebServer.h>
#include <Preferences.h>
#include <LittleFS.h>
#include <time.h>
#include <math.h>
#include <vector>
Arduino_DataBus *bus=new Arduino_ESP32SPI(9,10,12,11,GFX_NOT_DEFINED);
Arduino_GFX *panel=new Arduino_GC9B72(bus,14,0,false,360,360);
Arduino_Canvas *canvas=new Arduino_Canvas(360,360,panel);
Arduino_GFX *gfx=canvas;
WiFiManager wm; WebServer web(80); Preferences prefs;
bool buffered=true, serverStarted=false, ntpStarted=false, dirty=true, storageOK=false;
const uint16_t navy=0x0843,mint=0x5F3A,white=0xFFFF,muted=0x94B6,coral=0xFACC;
const long retention=30L*86400;
struct Med { char name[25]; uint16_t start,interval; uint8_t maximum,enabled; int64_t since; };
struct Event { int64_t due,ack; uint8_t med,late; char name[25]; };
Med meds[5]={}; std::vector<Event> events;
time_t cursor=0; String token; long lastSecond=-1; int lastConnection=-1;
bool valid(time_t t){return t>1700000000;}
String escape(String s){s.replace("&","&amp;");s.replace("<","&lt;");s.replace(">","&gt;");s.replace("\"","&quot;");s.replace("'","&#39;");return s;}
String stamp(time_t t){if(!valid(t))return "Waiting for time";struct tm x;localtime_r(&t,&x);char b[40];strftime(b,sizeof(b),"%d %b %H:%M %Z",&x);return b;}
void saveLog(){
 if(!storageOK)return;
 File f=LittleFS.open("/history.tmp","w"); if(!f){storageOK=false;return;}
 uint32_t n=events.size(); bool ok=f.write((uint8_t*)&n,sizeof(n))==sizeof(n);
 if(n)ok=ok && f.write((uint8_t*)events.data(),n*sizeof(Event))==n*sizeof(Event);
 f.close(); if(!ok || !LittleFS.rename("/history.tmp","/history.bin")){storageOK=false;return;}
 prefs.putLong64("cursor",cursor);
}
void load(){
 prefs.begin("medclock",false);
 if(prefs.getBytesLength("profiles")==sizeof(meds))prefs.getBytes("profiles",meds,sizeof(meds));
 else for(int i=0;i<5;i++){snprintf(meds[i].name,25,"Medication %d",i+1);meds[i].start=480;meds[i].interval=240;meds[i].maximum=4;}
 cursor=prefs.getLong64("cursor",0);
 storageOK=LittleFS.begin(true);
 if(storageOK){File f=LittleFS.open("/history.bin","r");if(f){uint32_t n=0;f.read((uint8_t*)&n,sizeof(n));if(n<=3600 && f.size()==sizeof(n)+n*sizeof(Event)){events.resize(n);f.read((uint8_t*)events.data(),n*sizeof(Event));}else storageOK=false;f.close();}}
}
time_t slot(time_t day,int minute){struct tm x;localtime_r(&day,&x);x.tm_hour=minute/60;x.tm_min=minute%60;x.tm_sec=0;x.tm_isdst=-1;return mktime(&x);}
time_t dayShift(time_t now,int days){struct tm x;localtime_r(&now,&x);x.tm_mday+=days;x.tm_hour=12;x.tm_min=0;x.tm_sec=0;x.tm_isdst=-1;return mktime(&x);}
bool exists(int m,time_t due){for(auto &e:events)if(e.med==m && e.due==due)return true;return false;}
void processSchedule(time_t now){
 if(!valid(now))return;
 if(!cursor){cursor=now;prefs.putLong64("cursor",cursor);}
 if(now<cursor)return; // never replay on a backward clock correction
 bool changed=false;
 for(int d=-30;d<=0;d++){
 time_t day=dayShift(now,d);
 for(int m=0;m<5;m++)if(meds[m].enabled){
 for(int k=0;k<meds[m].maximum;k++){
 int minute=meds[m].start+k*meds[m].interval;if(minute>=1440)break;
 time_t due=slot(day,minute);
 if(due<=cursor || due>now || due<=meds[m].since || due<now-retention || exists(m,due))continue;
 Event e={};e.due=due;e.med=m;e.late=(now-due>90);strncpy(e.name,meds[m].name,24);events.push_back(e);changed=true;
 }}}
 for(size_t i=0;i<events.size();)if(events[i].due<now-retention){events.erase(events.begin()+i);changed=true;}else i++;
 cursor=now;
 if(changed){saveLog();dirty=true;}
}
time_t nextDue(time_t now,int &index){time_t next=0;index=-1;
 for(int d=0;d<=1;d++)for(int m=0;m<5;m++)if(meds[m].enabled)for(int k=0;k<meds[m].maximum;k++){
 int minute=meds[m].start+k*meds[m].interval;if(minute>=1440)break;
 time_t t=slot(dayShift(now,d),minute);if(t>now && (!next||t<next)){next=t;index=m;}}
 return next;
}
String head(String title){return "<!doctype html><html><head><meta charset='UTF-8'><meta name='viewport' content='width=device-width,initial-scale=1'><title>Dose It</title><style>body{background:#101a29;color:#edf9f6;font:16px system-ui;max-width:700px;margin:24px auto;padding:16px}h1,b{color:#70efd0}.card{background:#1b293b;border-radius:20px;padding:20px;margin:16px 0}input,select,button{font:inherit;padding:12px;border-radius:10px;margin:6px 0;box-sizing:border-box;max-width:100%}input:not([type=checkbox]){width:100%}button{background:#70efd0;border:0;color:#101a29}a{color:#70efd0}.warning{color:#ffaf94}small{color:#b1c4cf}</style></head><body><h1>Dose It</h1><p>Medication Reminder</p><h2>"+title+"</h2>";}
String csrf(){return "<input type='hidden' name='token' value='"+token+"'>";}
bool authorized(){if(web.arg("token")!=token){web.send(403,"text/plain","Reload the page and try again.");return false;}return true;}
void home(){time_t now=time(nullptr);processSchedule(now);String h=head("Your reminder hub");
 h+="<p>"+stamp(now)+" &middot; Europe/London</p><p><a href='/settings'>Edit five medications</a> &middot; <a href='/history'>History / export</a></p>";
 if(!storageOK)h+="<p class='warning'>Storage error: history may not survive power loss.</p>";
 h+="<p class='warning'>Acknowledged means seen, not taken. For overdue reminders, check your medication's missed-dose instructions. Do not take extra doses based on this device.</p>";
 int pending=0;
 for(int i=(int)events.size()-1;i>=0;i--)if(!events[i].ack){auto &e=events[i];pending++;h+="<div class='card'><b>"+escape(e.name)+"</b><p>"+stamp(e.due)+ (e.late?" &mdash; missed / overdue":" &mdash; unacknowledged")+"</p><form method='post' action='/ack'>"+csrf()+"<input type='hidden' name='id' value='"+String(i)+"'><button>Acknowledge reminder (seen)</button></form></div>";}
 if(!pending)h+="<p>No unacknowledged reminders.</p>";
 for(int i=0;i<5;i++)if(meds[i].enabled){h+="<div class='card'><b>"+escape(meds[i].name)+"</b><p>";for(int k=0;k<meds[i].maximum;k++){int t=meds[i].start+k*meds[i].interval;if(t>=1440)break;char b[12];snprintf(b,sizeof(b),"%02d:%02d ",t/60,t%60);h+=b;}h+="</p><small>Local wall-clock times; resets at midnight.</small></div>";}
 h+="<p><button onclick='location.reload()'>Refresh status</button></p><small>Local network only. Keep a backup reminder. History retained for 30 days; older events are removed.</small></body></html>";web.send(200,"text/html",h);
}
void settings(){String h=head("Medication settings");h+="<p><a href='/'>Back to reminders</a></p><p>Use your prescribed schedule. Each day starts at local midnight. Reminders stop at midnight, even if the maximum has not been reached.</p>";
 for(int i=0;i<5;i++){Med &m=meds[i];char b[8];snprintf(b,sizeof(b),"%02d:%02d",m.start/60,m.start%60);
 h+="<form class='card' method='post' action='/save'>"+csrf()+"<input type='hidden' name='id' value='"+String(i)+"'><h3>Profile "+String(i+1)+"</h3><label><input type='checkbox' name='enabled' "+String(m.enabled?"checked":"")+"> Enabled</label><p>Name (24 ASCII characters)</p><input name='name' maxlength='24' required value='"+escape(m.name)+"'><p>First reminder (London time)</p><input type='time' name='start' required value='"+String(b)+"'><p>Interval in minutes (240 = 4 hours)</p><input type='number' name='interval' min='15' max='1440' required value='"+String(m.interval)+"'><p>Maximum reminders per day (not dose quantity)</p><input type='number' name='maximum' min='1' max='24' required value='"+String(m.maximum)+"'><button>Save this profile</button></form>";
 }h+="<p>Changes apply from now; past reminders stay in history. Spring's skipped hour moves forward; autumn's repeated hour generates only one reminder per scheduled slot. Midnight-to-midnight can be 23 or 25 hours.</p></body></html>";web.send(200,"text/html",h);}
void redirect(){web.sendHeader("Location","/");web.send(303,"text/plain","");}
void saveProfile(){if(!authorized())return;time_t now=time(nullptr);if(!valid(now)){web.send(503,"text/plain","Wait for internet time before changing schedules.");return;}
 int i=web.arg("id").toInt(),iv=web.arg("interval").toInt(),mx=web.arg("maximum").toInt();String s=web.arg("start"),name=web.arg("name");name.trim();
 int hh=s.substring(0,2).toInt(),mm=s.substring(3,5).toInt();bool ascii=true;for(unsigned int j=0;j<name.length();j++)if(name[j]<32||name[j]>126)ascii=false;
 if(i<0||i>=5||iv<15||iv>1440||mx<1||mx>24||s.length()!=5||s[2]!=':'||hh<0||hh>23||mm<0||mm>59||name.length()<1||name.length()>24||!ascii){web.send(400,"text/plain","Invalid settings. Use a short ASCII name, valid time, interval 15–1440 minutes and maximum 1–24.");return;}
 processSchedule(now);Med &m=meds[i];memset(&m,0,sizeof(m));strncpy(m.name,name.c_str(),24);m.start=hh*60+mm;m.interval=iv;m.maximum=mx;m.enabled=web.hasArg("enabled");m.since=now;
 prefs.putBytes("profiles",meds,sizeof(meds));dirty=true;redirect();}
void history(){String h=head("Reminder history");h+="<p><a href='/'>Back</a> &middot; <a href='/export'>Download CSV</a></p><p>Last 30 days. This is a reminder log, not proof of doses taken. Downtime events are reconstructed from the saved schedule.</p>";
 for(int i=(int)events.size()-1;i>=0;i--){auto &e=events[i];h+="<div class='card'><b>"+escape(e.name)+"</b><p>Scheduled: "+stamp(e.due)+"</p><p>"+(e.ack?"Acknowledged: "+stamp(e.ack):String(e.late?"Missed / overdue":"Unacknowledged"))+"</p></div>";}web.send(200,"text/html",h+"</body></html>");}
void startWeb(){
 web.on("/",HTTP_GET,home);web.on("/settings",HTTP_GET,settings);web.on("/save",HTTP_POST,saveProfile);web.on("/history",HTTP_GET,history);
 web.on("/ack",HTTP_POST,[]{if(!authorized())return;int i=web.arg("id").toInt();time_t now=time(nullptr);if(i<0||i>=(int)events.size()||!valid(now)){web.send(400,"text/plain","Invalid event or clock unavailable");return;}events[i].ack=now;saveLog();dirty=true;redirect();});
 web.on("/export",HTTP_GET,[]{String csv="medication,scheduled_london,acknowledged_london,status\r\n";for(auto &e:events){String name=e.name;name.replace("\"","\"\"");csv+="\""+name+"\",\""+stamp(e.due)+"\",\""+(e.ack?stamp(e.ack):String(""))+"\","+(e.ack?"seen":e.late?"missed_or_overdue":"unacknowledged")+"\r\n";}web.sendHeader("Content-Disposition","attachment; filename=reminders.csv");web.send(200,"text/csv",csv);});
 web.begin();serverStarted=true;dirty=true;
}
void text(String s,int y,int size,uint16_t c){gfx->setTextSize(size);gfx->setTextColor(c);gfx->setCursor((360-s.length()*6*size)/2,y);gfx->print(s);}
String localTime(time_t t,const char *format){struct tm x;localtime_r(&t,&x);char b[40];strftime(b,sizeof(b),format,&x);return b;}
void draw(time_t now){
 bool clock=valid(now);int count=0,first=-1;
 for(int i=0;i<(int)events.size();i++)if(!events[i].ack){count++;if(first<0)first=i;}
 bool alert=clock&&count;int mi=-1;time_t next=clock?nextDue(now,mi):0;long left=next?next-now:0;
 // Static content only changes with the profile, status, date or address.
 String signature=String(clock)+":"+String(count)+":"+String(first)+":"+String(mi)+":"+String((long)next)+":"+String(storageOK)+":"+String(WiFi.status())+":"+WiFi.localIP().toString();
 if(clock)signature+=localTime(now,"%d %b %Y");
 static String previous;bool full=dirty||signature!=previous;previous=signature;
 const uint16_t blue=0x359F,orange=0xFD20,red=0xF800;
 if(full){
 gfx->fillScreen(navy);
 gfx->fillRoundRect(161,35,38,34,10,mint);gfx->fillRect(177,40,6,24,navy);gfx->fillRect(168,49,24,6,navy);
 text("Dose It",81,3,white);text("Medication Reminder",113,1,muted);
 if(!clock){text("Syncing Time",158,2,white);text(WiFi.status()==WL_CONNECTED?"Waiting for internet time":"Wi-Fi: MedReminder",205,1,muted);text(WiFi.status()==WL_CONNECTED?"Schedule unavailable":"Password: MedClock2026",224,1,muted);text(WiFi.status()==WL_CONNECTED?WiFi.localIP().toString():String("192.168.4.1"),251,2,mint);}
 else if(alert){Event &e=events[first];String name=e.name;text(name,151,name.length()<=16?3:2,white);text("Reminder: "+localTime(e.due,"%H:%M"),191,1,muted);gfx->fillRoundRect(75,213,210,40,12,0x5128);text(String(count)+" To Review",225,2,coral);text("Seen is not taken",266,1,muted);text("Check missed-dose instructions",280,1,coral);}
 else if(next){String name=meds[mi].name;text(name,150,name.length()<=16?3:2,mint);text("Next Dose: "+localTime(next,"%H:%M"),247,2,muted);}
 else{text("Let's Get Set",160,2,mint);text("Add medications on your phone",205,1,white);text("No schedules enabled",231,1,muted);}
 if(clock){text(localTime(now,"%d %b %Y"),294,1,mint);text(storageOK?(WiFi.status()==WL_CONNECTED?WiFi.localIP().toString():String("Wi-Fi offline | alerts active")):String("Storage error - check phone"),310,1,storageOK?muted:coral);}
 }
 if(clock&&!alert&&next){
 gfx->fillRect(72,195,216,32,navy);char b[24];snprintf(b,sizeof(b),"%02ld:%02ld:%02ld",left/3600,(left/60)%60,left%60);text(b,195,4,white);
 }
 // Remaining arc starts at the top; its leading edge travels clockwise.
 long span=next&&mi>=0?max(86400L, (long)meds[mi].interval*60):86400L;
 int elapsed=next?constrain((int)(120L*(span-left)/span),0,120):0;
 uint16_t colour=next?(left<=600?red:left<=1800?orange:blue):blue;
 int runner=clock&&!alert&&next?now%120:-1;
 for(int i=0;i<120;i++){float a=(i*3-90)*PI/180;uint16_t c=alert?coral:next&&i>=elapsed?colour:0x2127;
 if(i==runner)c=colour;
 gfx->drawLine(180+164*cos(a),180+164*sin(a),180+170*cos(a),180+170*sin(a),c);}
 if(buffered)canvas->flush();
}
void setup(){Serial.begin(115200);if(!canvas->begin(10000000)){gfx=panel;buffered=false;if(!panel->begin(10000000))while(true)delay(1000);}gfx->setTextWrap(false);load();token=String((uint32_t)esp_random(),HEX)+String((uint32_t)esp_random(),HEX);setenv("TZ","GMT0BST,M3.5.0/1,M10.5.0",1);tzset();draw(0);wm.setConfigPortalBlocking(false);wm.autoConnect("MedReminder","MedClock2026");}
void loop(){wm.process();if(WiFi.status()==WL_CONNECTED){if(!ntpStarted){configTzTime("GMT0BST,M3.5.0/1,M10.5.0","pool.ntp.org","time.google.com","time.cloudflare.com");ntpStarted=true;}if(!serverStarted&&!wm.getConfigPortalActive())startWeb();}if(serverStarted)web.handleClient();time_t now=time(nullptr);static long scan=-1;if(valid(now)&&now/60!=scan){processSchedule(now);scan=now/60;}long sec=valid(now)?now:0;int connection=WiFi.status()==WL_CONNECTED;if(sec!=lastSecond||connection!=lastConnection||dirty){draw(now);lastSecond=sec;lastConnection=connection;dirty=false;}delay(10);}

Remix this project

Make it yours in one click

Open a full copy of this project in your own Schematik workspace, diagram, code, parts, and assembly steps included. Swap the sensor, add features, or redesign the whole thing with AI. The author's original stays untouched.

Open in Schematik