Health
Drink-water coaster
A coaster that weighs your water bottle. A bar of light shows how much is left, and flashes when the level has not dropped for an hour.
- Hard
- about 80 min
- ESP32-S3
- 6 parts
- 7 wires
- 65 lines of code
ESP32 packs are built on real parts: the simulator runs Arduino Uno circuits only.
Idea
It knows you drank because the bottle got lighter. A load cell bends by a hair under weight, and the amplifier turns that into a number you calibrate with a known weight.
What you learn
Weighing with a load cell, calibrating, and detecting a change rather than a value.
How it works
input
Load cell + HX711
decides
ESP32-S3
output
LED stick
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 6 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 7
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
water-coaster.ino
// Drink-water coaster
// Weighs your bottle. The bar of light shows how much water is left, and
// flashes if the level has not dropped for an hour.
#include "HX711.h"
#include <Adafruit_NeoPixel.h>
const int PIN_SCALE_DT = 5;
const int PIN_SCALE_SCK = 6;
const int PIN_STICK_DIN = 16;
// Calibrate: put a known weight on, and change this until the grams are right.
const float CALIBRATION = 420.0;
const float EMPTY_BOTTLE_G = 30.0; // your bottle with no water in it
const float FULL_WATER_G = 500.0; // the water in a full bottle
const float SIP_G = 15.0; // a drop of at least this is a sip
const unsigned long REMIND_AFTER_MS = 60UL * 60UL * 1000UL;
const int LED_COUNT = 8;
HX711 scale;
Adafruit_NeoPixel stick(LED_COUNT, PIN_STICK_DIN, NEO_GRB + NEO_KHZ800);
float lastWater = -1;
unsigned long lastSip = 0;
void showLevel(float water, bool remind) {
int lit = constrain((int)round(water / FULL_WATER_G * LED_COUNT), 0, LED_COUNT);
bool blinkOff = remind && (millis() / 400) % 2 == 0;
for (int i = 0; i < LED_COUNT; i++) {
uint32_t colour = remind ? stick.Color(160, 60, 0) : stick.Color(0, 80, 160);
stick.setPixelColor(i, i < lit && !blinkOff ? colour : 0);
}
stick.show();
}
void setup() {
stick.begin();
stick.setBrightness(60);
stick.show();
scale.begin(PIN_SCALE_DT, PIN_SCALE_SCK);
scale.set_scale(CALIBRATION);
scale.tare(); // start with the coaster empty
lastSip = millis();
}
void loop() {
if (!scale.wait_ready_timeout(500)) return;
float grams = scale.get_units(5);
if (grams < EMPTY_BOTTLE_G / 2) {
// The bottle is off the coaster: someone is probably drinking.
stick.clear();
stick.show();
delay(200);
return;
}
float water = max(0.0f, grams - EMPTY_BOTTLE_G);
if (lastWater < 0) lastWater = water;
if (lastWater - water >= SIP_G) lastSip = millis(); // it got lighter: a sip
if (water - lastWater >= SIP_G) lastSip = millis(); // refilled
lastWater = water;
showLevel(water, millis() - lastSip > REMIND_AFTER_MS);
delay(200);
}
Libraries
- HX711 (by Bogdan Necula): install it from Sketch > Include Library > Manage Libraries.
- Adafruit NeoPixel: 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 > ESP32S3 Dev Module, then Tools > Port and choose the board's port.
- Press Upload (the arrow). Wait for “Done uploading”.