MediNow is an automated medication dispensing system built around an ESP32-S3 with a 7-inch touchscreen interface. The system uses stepper motors controlled via WiFi to dispense medications on schedule, with environmental monitoring via DHT22 temperature/humidity sensor, RFID card reader for user authentication, and infrared break-beam sensors to detect dispensing completion.
This guide provides a complete wiring diagram, parts list, and step-by-step assembly instructions for building the MediNow dispenser. The firmware enables WiFi-based motor control, touchscreen interaction for scheduling and status display, and sensor integration for reliable operation. Assembly focuses on properly wiring the eight stepper motors, configuring the fan cooling system, and testing all sensors before mechanical integration.
Wiring diagram
Gather all the parts
Assemble it in 3 steps
1. Wire the eight motors with power off
The pictured breakout is optional and only repeats the ESP32 pins. Leave its barrel jack unused. Use four SN74HCT595N chips and eight ULN2003 modules. In DIP pin order, QB through QH are pins 1–7, GND is 8, QHprime is 9, SRCLR is 10, SRCLK is 11, RCLK is 12, OE is 13, SER is 14, QA is 15, and VCC is 16. Match the wiring view, including every pull-down and the 100 nF capacitor next to each chip. With power off, connect the separate 5 V adapter to the drivers and registers using rated fused distribution wiring. Tie both adapter negatives and ESP32 ground together. Do not route motor power through the breakout or ESP32.
2. Wire the fan switch and sensors
Use a two-wire 12 V DC fan. Connect fan positive to 12 V and negative to the MOSFET drain. Install the diode across the fan with its striped end at 12 V. Use a mounted AO3400A and verify the fan startup current is within the supply and switch ratings. Use only a 3.3 V open-collector beam receiver with this wiring. RC522 SDA is the SPI select pin, not I2C data. Follow the wiring view for all connections.
3. Test without a mechanical load
Use USB for both ESP32 boards. Deploy motor firmware to the N16R8 and display firmware to the 7B using include/role.h. After USB firmware starts, turn on motor power. Tap A–H to select motors 1–8 and hold JOG to test each uncoupled motor separately. Open the motor board serial monitor at 115200 to check sensor readings, drops and card IDs.
- On-screen STOP is not an emergency stop. There are no travel limits, and motor holding torque is released on stop.
Review all connections
1. Connections between "motor" and "ESP32"
2. Connections between "supply" and "ESP32"
3. Connections between "driver" and "ESP32"
4. Connections between "fan" and "ESP32"
5. Connections between "diode" and "ESP32"
6. Connections between "fet" and "ESP32"
7. Connections between "dht" and "ESP32"
8. Connections between "beam" and "ESP32"
9. Connections between "bias1" and "ESP32"
10. Connections between "bias2" and "ESP32"
11. Connections between "bias3" and "ESP32"
12. Connections between "rfid" and "ESP32"
13. Connections between "dhtpull" and "ESP32"
14. Connections between "beampull" and "ESP32"
15. Connections between "gate" and "ESP32"
16. Connections between "gateoff" and "ESP32"
17. Connections between "motorSupply" and "ESP32"
18. Connections between "motor2" and "ESP32"
19. Connections between "driver2" and "ESP32"
20. Connections between "motor3" and "ESP32"
21. Connections between "driver3" and "ESP32"
22. Connections between "motor4" and "ESP32"
23. Connections between "driver4" and "ESP32"
24. Connections between "motor5" and "ESP32"
25. Connections between "driver5" and "ESP32"
26. Connections between "motor6" and "ESP32"
27. Connections between "driver6" and "ESP32"
28. Connections between "motor7" and "ESP32"
29. Connections between "driver7" and "ESP32"
30. Connections between "motor8" and "ESP32"
31. Connections between "driver8" and "ESP32"
32. Connections between "enableFet" and "ESP32"
33. Connections between "enableUp" and "ESP32"
34. Connections between "enableDown" and "ESP32"
35. Connections between "enableGate" and "ESP32"
36. Connections between "shift1" and "ESP32"
37. Connections between "inputDown1A" and "ESP32"
38. Connections between "inputDown1B" and "ESP32"
39. Connections between "inputDown1C" and "ESP32"
40. Connections between "inputDown1D" and "ESP32"
41. Connections between "inputDown1E" and "ESP32"
42. Connections between "inputDown1F" and "ESP32"
43. Connections between "inputDown1G" and "ESP32"
44. Connections between "inputDown1H" and "ESP32"
45. Connections between "bypass1" and "ESP32"
46. Connections between "shift2" and "ESP32"
47. Connections between "inputDown2A" and "ESP32"
48. Connections between "inputDown2B" and "ESP32"
49. Connections between "inputDown2C" and "ESP32"
50. Connections between "inputDown2D" and "ESP32"
51. Connections between "inputDown2E" and "ESP32"
52. Connections between "inputDown2F" and "ESP32"
53. Connections between "inputDown2G" and "ESP32"
54. Connections between "inputDown2H" and "ESP32"
55. Connections between "bypass2" and "ESP32"
56. Connections between "shift3" and "ESP32"
57. Connections between "inputDown3A" and "ESP32"
58. Connections between "inputDown3B" and "ESP32"
59. Connections between "inputDown3C" and "ESP32"
60. Connections between "inputDown3D" and "ESP32"
61. Connections between "inputDown3E" and "ESP32"
62. Connections between "inputDown3F" and "ESP32"
63. Connections between "inputDown3G" and "ESP32"
64. Connections between "inputDown3H" and "ESP32"
65. Connections between "bypass3" and "ESP32"
66. Connections between "shift4" and "ESP32"
67. Connections between "inputDown4A" and "ESP32"
68. Connections between "inputDown4B" and "ESP32"
69. Connections between "inputDown4C" and "ESP32"
70. Connections between "inputDown4D" and "ESP32"
71. Connections between "inputDown4E" and "ESP32"
72. Connections between "inputDown4F" and "ESP32"
73. Connections between "inputDown4G" and "ESP32"
74. Connections between "inputDown4H" and "ESP32"
75. Connections between "bypass4" and "ESP32"
Deploy the firmware
#include <Arduino.h>
#include <WiFi.h>
#include <WiFiUdp.h>
#include "role.h"
static const char *network = "Jog-7B-Panel";
static const char *password = "jog-7B-lime-43-frost";
static const IPAddress motorIP(192,168,4,1);
static constexpr uint16_t port = 29741;
static WiFiUDP udp;
static constexpr uint32_t magic = 0x37424A32;
struct Packet { uint32_t tag, seq; int32_t direction; uint32_t axis; };
static void sendPacket(IPAddress ip, uint16_t p, const Packet &msg) {
if (udp.beginPacket(ip, p)) {
udp.write(reinterpret_cast<const uint8_t *>(&msg), sizeof msg);
udp.endPacket();
}
}
#if DISPLAY_ROLE
#include <Wire.h>
#include <esp_lcd_panel_rgb.h>
#include <esp_lcd_panel_ops.h>
#include <esp_heap_caps.h>
static esp_lcd_panel_handle_t panel;
static constexpr int W = 1024, H = 600;
static constexpr int TOUCH_INT = 4;
static uint16_t *pixels;
static bool touchOK, ready;
static bool writeReg(uint8_t addr, uint16_t reg, uint8_t data) {
Wire.beginTransmission(addr);
if (addr == 0x5d) Wire.write(reg >> 8);
Wire.write(reg & 255); Wire.write(data);
return Wire.endTransmission() == 0;
}
static bool touchRead(uint16_t reg, uint8_t *data, size_t size) {
Wire.beginTransmission(0x5d);
Wire.write(reg >> 8); Wire.write(reg & 255);
if (Wire.endTransmission(false) || Wire.requestFrom(uint8_t(0x5d), size) != size) return false;
while (size--) *data++ = Wire.read();
return true;
}
static bool startPanel() {
Wire.begin(8, 9, 400000);
Wire.setTimeOut(15);
if (!writeReg(0x24, 2, 255)) return false;
delay(10);
// Waveshare 08_TOUCH: EXIO1 reset low, INT low, then release reset.
// EXIO6 remains high (panel supply); EXIO2 stays off until RGB starts.
pinMode(TOUCH_INT, OUTPUT);
if (!writeReg(0x24, 3, 0xd9)) return false;
delay(100); digitalWrite(TOUCH_INT, LOW); delay(100);
if (!writeReg(0x24, 3, 0xdb)) return false;
delay(200); pinMode(TOUCH_INT, INPUT);
uint8_t id[4]; touchOK = touchRead(0x8140, id, sizeof id) && !memcmp(id,"911",3);
esp_lcd_rgb_panel_config_t c{};
c.clk_src = LCD_CLK_SRC_DEFAULT;
c.timings.pclk_hz = 30000000;
c.timings.h_res = W; c.timings.v_res = H;
c.timings.hsync_pulse_width = 162; c.timings.hsync_back_porch = 152; c.timings.hsync_front_porch = 48;
c.timings.vsync_pulse_width = 45; c.timings.vsync_back_porch = 13; c.timings.vsync_front_porch = 3;
c.timings.flags.pclk_active_neg = 1;
c.data_width = 16; c.bits_per_pixel = 16; c.num_fbs = 2;
c.bounce_buffer_size_px = W * 10;
c.flags.fb_in_psram = 1;
c.hsync_gpio_num = 46; c.vsync_gpio_num = 3; c.de_gpio_num = 5; c.pclk_gpio_num = 7; c.disp_gpio_num = -1;
const int pins[] = {14,38,18,17,10,39,0,45,48,47,21,1,2,42,41,40};
memcpy(c.data_gpio_nums, pins, sizeof pins);
void *buffer = nullptr;
if (esp_lcd_new_rgb_panel(&c, &panel) != ESP_OK || esp_lcd_panel_init(panel) != ESP_OK ||
esp_lcd_rgb_panel_get_frame_buffer(panel, 1, &buffer) != ESP_OK) return false;
pixels = static_cast<uint16_t *>(buffer);
return writeReg(0x24, 3, 0xdf);
}
static void box(int x, int y, int w, int h, uint16_t color) {
for (int j=y; j<y+h; ++j) for (int i=x; i<x+w; ++i) pixels[j*W+i]=color;
}
// 5x7 uppercase bitmap glyphs, stored as seven five-bit rows.
static const uint8_t glyph[][7] = {
{14,17,17,31,17,17,17},{30,17,17,30,17,17,30},{14,17,16,16,16,17,14},{30,17,17,17,17,17,30},
{31,16,16,30,16,16,31},{31,16,16,30,16,16,16},{14,17,16,23,17,17,15},{17,17,17,31,17,17,17},
{14,4,4,4,4,4,14},{7,2,2,2,18,18,12},{17,18,20,24,20,18,17},{16,16,16,16,16,16,31},
{17,27,21,21,17,17,17},{17,25,21,19,17,17,17},{14,17,17,17,17,17,14},{30,17,17,30,16,16,16},
{14,17,17,17,21,18,13},{30,17,17,30,20,18,17},{15,16,16,14,1,1,30},{31,4,4,4,4,4,4},
{17,17,17,17,17,17,14},{17,17,17,17,17,10,4},{17,17,17,21,21,21,10},{17,17,10,4,10,17,17},
{17,17,10,4,4,4,4},{31,1,2,4,8,16,31},{0,4,4,31,4,4,0},{0,0,0,31,0,0,0}
};
static void label(int center, int y, const char *txt, int s) {
int x=center-(strlen(txt)*6*s-s)/2;
for (; *txt; ++txt,x+=6*s) {
int g= *txt=='+' ? 26 : *txt=='-' ? 27 : *txt-'A';
if (g<0 || g>=28) continue;
for(int r=0;r<7;r++) for(int c=0;c<5;c++) if(glyph[g][r] & (16>>c)) box(x+c*s,y+r*s,s,s,0xffff);
}
}
static unsigned axis, drawnAxis;
static void draw(bool link, int motion) {
box(0,0,W,H,0x10a4);
label(512,46,"MANUAL JOG",8);
label(512,138,!touchOK ? "TOUCH ERROR" : link ? "HOLD TO JOG" : "WAITING FOR MOTOR BOARD",4);
box(48,205,444,180,motion<0 ? 0x056b : 0x1b0f);
box(532,205,444,180,motion>0 ? 0x056b : 0x1b0f);
label(270,265,"JOG -",8); label(754,265,"JOG +",8);
for(unsigned i=0;i<8;i++) {
int x=48+i*116;
box(x,395,108,65,i==axis ? 0x056b : 0x1b0f);
char name[]={char('A'+i),0}; label(x+54,410,name,5);
}
box(48,475,928,80,0x9800); label(512,490,"STOP",7);
esp_lcd_panel_draw_bitmap(panel,0,0,W,H,pixels);
void *a=nullptr,*b=nullptr;
if (esp_lcd_rgb_panel_get_frame_buffer(panel,2,&a,&b)==ESP_OK)
pixels=static_cast<uint16_t *>(pixels==a ? b : a);
}
static uint32_t seq, lastSend, lastAck, lastPoll, lastTouch;
static bool acked, armed, linkWas;
static int command, shown=2;
void setup() {
Serial.begin(115200);
ready=startPanel();
if (!ready) { Serial.println("7B display initialization failed"); return; }
draw(false,0);
WiFi.mode(WIFI_STA); WiFi.setSleep(false); WiFi.begin(network,password);
udp.begin(port);
}
void loop() {
if (!ready) { delay(100); return; }
uint32_t now=millis();
while (udp.parsePacket()) {
Packet a{};
if (udp.remoteIP()==motorIP && udp.read(reinterpret_cast<uint8_t *>(&a),sizeof a)==sizeof a &&
a.tag==magic && uint32_t(seq-a.seq)<5) { acked=true; lastAck=now; }
}
bool link=WiFi.status()==WL_CONNECTED && acked && now-lastAck<220;
if (!link) { armed=false; command=0; }
if (touchOK && now-lastPoll>=16) {
lastPoll=now;
uint8_t state=0;
if (!touchRead(0x814e,&state,1)) { command=0; armed=false; }
else if (state&0x80) {
uint8_t pt[5]{}; int count=state&15;
bool valid=count!=1 || touchRead(0x814f,pt,sizeof pt);
valid=writeReg(0x5d,0x814e,0) && valid;
if (valid) lastTouch=now;
if (valid && count==0) { armed=link; command=0; }
else {
int x=pt[1]+256*pt[2],y=pt[3]+256*pt[4];
if(valid && count==1 && !command && armed && y>=395 && y<460 && x>=48 && x<976) {
axis=(x-48)/116; armed=false;
}
int target=0;
if(valid && count==1 && y>=205 && y<385) {
if(x>=48 && x<492) target=-1;
if(x>=532 && x<976) target=1;
}
if (!target || !link || (command && command!=target)) { armed=false; command=0; }
else if (armed) command=target;
}
}
}
if(now-lastTouch>110 && command) { command=0; armed=false; }
if (WiFi.status()==WL_CONNECTED && (now-lastSend>=35 || command!=shown)) {
lastSend=now; sendPacket(motorIP,port,{magic,++seq,command,axis});
}
if (link!=linkWas || command!=shown || axis!=drawnAxis) { drawnAxis=axis; draw(link,command); linkWas=link; shown=command; }
delay(1);
}
#else
#include <DHT.h>
#include <SPI.h>
#include <MFRC522.h>
static constexpr int dataPin=5, clockPin=6, latchPin=7, enablePin=8;
static void outputs(uint32_t bits) {
digitalWrite(latchPin,LOW);
for(int i=24;i>=0;i-=8) shiftOut(dataPin,clockPin,MSBFIRST,uint8_t(bits>>i));
digitalWrite(latchPin,HIGH);
}
static constexpr int fan=16, beam=10;
static DHT climate(9,DHT22);
static MFRC522 reader(14,15);
static uint32_t lastRun,lastStep,lastSense,drops,beamChanged;
static int motion;
static unsigned activeAxis;
static uint8_t phase[8];
static bool neutral,fanOn,blocked,rawBlocked;
static void stopMotor() { if(motion) outputs(0); motion=0; }
static void sensors(uint32_t now) {
bool raw=digitalRead(beam)==HIGH;
if(raw!=rawBlocked) { rawBlocked=raw; beamChanged=now; }
if(raw!=blocked && now-beamChanged>=10) {
blocked=raw;
if(blocked) Serial.printf("Drop %lu\n",(unsigned long)++drops);
}
if(motion) return;
if(now-lastSense>=2500) {
lastSense=now;
float h=climate.readHumidity(), t=climate.readTemperature();
if(isnan(t)||isnan(h)) { fanOn=true; Serial.println("DHT22 read failed; fan on"); }
else {
if(t>=30) fanOn=true;
else if(t<=28) fanOn=false;
Serial.printf("%.1f C, %.1f %% RH, fan %s\n",t,h,fanOn?"ON":"OFF");
}
digitalWrite(fan,fanOn);
}
if(reader.PICC_IsNewCardPresent() && reader.PICC_ReadCardSerial()) {
Serial.print("Card UID:");
for(byte i=0;i<reader.uid.size;i++) Serial.printf(" %02X",reader.uid.uidByte[i]);
Serial.println(); reader.PICC_HaltA();
}
}
void setup() {
Serial.begin(115200);
for(int pin:{enablePin,dataPin,clockPin,latchPin}) { digitalWrite(pin,LOW); pinMode(pin,OUTPUT); }
outputs(0);
digitalWrite(enablePin,HIGH);
digitalWrite(fan,LOW); pinMode(fan,OUTPUT);
pinMode(beam,INPUT); blocked=rawBlocked=digitalRead(beam)==HIGH;
climate.begin(); SPI.begin(12,13,11,14); reader.PCD_Init();
WiFi.mode(WIFI_AP);
WiFi.softAPConfig(motorIP,motorIP,IPAddress(255,255,255,0));
if (WiFi.softAP(network,password,6,1,1)) udp.begin(port);
}
void loop() {
uint32_t now=millis();
if (now-lastRun>=160 || WiFi.softAPgetStationNum()==0) { stopMotor(); neutral=false; }
for(int n=0;n<8 && udp.parsePacket();++n) {
Packet p{};
if (udp.read(reinterpret_cast<uint8_t *>(&p),sizeof p)!=sizeof p || p.tag!=magic || p.direction < -1 || p.direction > 1 || p.axis>=8) continue;
const auto ip=udp.remoteIP(); const auto remotePort=udp.remotePort();
if (!p.direction) { stopMotor(); neutral=true; }
else if (neutral && (!motion || (motion==p.direction && activeAxis==p.axis))) {
if (!motion) { lastStep=micros(); }
activeAxis=p.axis; motion=p.direction;
} else { stopMotor(); neutral=false; }
lastRun=millis();
sendPacket(ip,remotePort,{magic,p.seq,motion,activeAxis});
}
if (motion && uint32_t(micros()-lastStep)>=4000) {
lastStep=micros();
static constexpr uint8_t masks[]={1,3,2,6,4,12,8,9};
auto &step=phase[activeAxis];
step=(step+motion+8)%8;
outputs(uint32_t(masks[step])<<(4*activeAxis));
}
sensors(now);
delay(1);
}
#endifRemix 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.




