Health
Reminder mug
A sleeve for your mug that counts every sip and reminds you to drink when you have gone too long without one.
- Medium
- about 50 min
- ESP32-C3
- 8 parts
- 8 wires
- 67 lines of code
ESP32 packs are built on real parts: the simulator runs Arduino Uno circuits only.
Idea
It cannot see water. It notices the mug being tipped, which is nearly always a sip. Choosing a cheap clue that is good enough is half of sensor design.
Before you start
Take the sleeve off before washing the mug, and keep the electronics away from spills.
What you learn
Counting events from a switch, and measuring how long since the last one.
How it works
input
Tilt switch
decides
ESP32-C3
output
OLED 0.96 in
Buzzer
Powered with 5 V through the board's USB-C port.
A reference design. The sketch is compiled with the real ESP32 toolchain, and its pins are checked against the wiring table automatically. It has not yet been built and tested on real parts by us, so wire it on the bench and run the checks before you build it into a case. Real modules vary: follow the labels printed on yours, not their position in the picture.
Parts
0 of 8 ready
No prices here: they change by shop and by week. Buy each part by its name and the note beside it.
You also need
A computer with Arduino IDE 2 installed (free)
3D wiring
One jumper per step, with the USB cable unplugged. Several wires may share 3V3, 5V or GND: the expansion board or breadboard gives each its own pin.
Step 0 of 8
Lay out the parts
Seat the board on its expansion board or breadboard and lay the modules out round it. Nothing is connected yet.
All connections
reminder-mug.ino
// Reminder mug
// Fixed to the side of your mug. Each time you tip the mug to drink it counts
// a sip, and if you have not drunk for a while it reminds you.
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
const int PIN_TILT_A = 3;
const int PIN_OLED_SDA = 6;
const int PIN_OLED_SCL = 7;
const int PIN_BUZZER_POS = 10;
const unsigned long REMIND_AFTER_MS = 30UL * 60UL * 1000UL; // 30 minutes
Adafruit_SSD1306 oled(128, 64, &Wire, -1);
unsigned long lastSip = 0;
int sips = 0;
bool wasTilted = false;
unsigned long nextNag = 0;
void setup() {
// The tilt switch joins the pin to GND while the mug stands upright.
pinMode(PIN_TILT_A, INPUT_PULLUP);
pinMode(PIN_BUZZER_POS, OUTPUT);
Wire.begin(PIN_OLED_SDA, PIN_OLED_SCL);
oled.begin(SSD1306_SWITCHCAPVCC, 0x3C);
oled.setTextColor(SSD1306_WHITE);
lastSip = millis();
}
void loop() {
bool tilted = digitalRead(PIN_TILT_A) == HIGH;
if (tilted && !wasTilted) {
sips++;
lastSip = millis();
nextNag = 0;
}
wasTilted = tilted;
unsigned long since = millis() - lastSip;
bool late = since > REMIND_AFTER_MS;
oled.clearDisplay();
oled.setTextSize(1);
oled.setCursor(0, 0);
oled.printf("Sips today: %d", sips);
oled.setTextSize(2);
oled.setCursor(0, 22);
if (late) {
oled.print("Drink now!");
} else {
unsigned long left = (REMIND_AFTER_MS - since) / 60000UL + 1;
oled.printf("%lu min", left);
oled.setTextSize(1);
oled.setCursor(0, 48);
oled.print("until the next sip");
}
oled.display();
if (late && millis() >= nextNag) {
tone(PIN_BUZZER_POS, 988, 150);
delay(200);
tone(PIN_BUZZER_POS, 1319, 250);
nextNag = millis() + 60000UL; // then once a minute until you drink
}
delay(100);
}
Libraries
- Adafruit GFX Library: install it from Sketch > Include Library > Manage Libraries.
- Adafruit SSD1306: install it from Sketch > Include Library > Manage Libraries.
Uploading
First time with an ESP32: in Arduino IDE open Boards Manager, search “esp32” and install “esp32 by Espressif Systems”.
- Open the sketch in Arduino IDE.
- Plug the board in with the USB-C cable.
- Tools > Board > ESP32C3 Dev Module (USB CDC On Boot: Enabled), then Tools > Port and choose the board's port.
- Press Upload (the arrow). Wait for “Done uploading”.