Remote-controlled RGB mood light
Warm, cool, rainbow or breathing: cycle lighting moods from your sofa.
Shop by category
Shop all componentsThe stopwatch uses micros-accurate millis() timing and two buttons. The first button starts and stops, and the second records a lap while running or resets when stopped. The OLED shows the running time in minutes, seconds and hundredths and lists the last three laps. Debounce delays keep a single press from counting twice.
Tick anything you already have and the total updates.
Follow the colours: red is power, dark grey is ground, blue is a signal.
USB power bank.
stopwatch.inoVerify & upload in Electrolark#include <Wire.h>
#include <Adafruit_SSD1306.h>
Adafruit_SSD1306 oled(128, 64, &Wire, -1);
const int BTN_START = 14, BTN_LAP = 27;
bool running = false;
unsigned long startedAt = 0, elapsed = 0, laps[3] = {0, 0, 0};
unsigned long lastPress = 0;
String fmt(unsigned long ms) {
char b[16];
snprintf(b, sizeof(b), "%02lu:%02lu.%02lu", ms / 60000, (ms / 1000) % 60, (ms / 10) % 100);
return String(b);
}
void draw() {
unsigned long t = running ? elapsed + millis() - startedAt : elapsed;
oled.clearDisplay(); oled.setTextColor(WHITE);
oled.setTextSize(2); oled.setCursor(0, 0); oled.print(fmt(t));
oled.setTextSize(1);
for (int i = 0; i < 3; i++) { oled.setCursor(0, 26 + i * 12); oled.print("Lap "); oled.print(i + 1); oled.print(" "); oled.print(fmt(laps[i])); }
oled.display();
}
void setup() {
pinMode(BTN_START, INPUT_PULLUP); pinMode(BTN_LAP, INPUT_PULLUP);
Wire.begin(21, 22);
oled.begin(SSD1306_SWITCHCAPVCC, 0x3C);
}
void loop() {
if (millis() - lastPress > 200) {
if (digitalRead(BTN_START) == LOW) {
lastPress = millis();
if (running) { elapsed += millis() - startedAt; running = false; }
else { startedAt = millis(); running = true; }
} else if (digitalRead(BTN_LAP) == LOW) {
lastPress = millis();
if (running) {
laps[2] = laps[1]; laps[1] = laps[0];
laps[0] = elapsed + millis() - startedAt;
} else { elapsed = 0; laps[0] = laps[1] = laps[2] = 0; }
}
}
draw();
delay(20);
}
Raise the 200 ms debounce time.
Reduce how often draw() runs, for example every 50 ms.
Check the button wiring to GND.
Good to about 10 ms; fine for games and practice, not for sports timing.
They are the total time at each lap press. Subtract to get lap durations.
Yes, add a buzzer on a spare pin.
5 parts: ESP32-WROOM-32 38-Pin Development Board, 2 × Tactile Push Button Switch, 0.96" OLED Display 128x64, Solderless Breadboard and Dupont Jumper Wires (40 pcs). On this page you can tick the parts you already have and add only the rest to your cart.
It is a beginner project and takes about 1 hour. The build on this page has 6 steps.
No. This page has the complete, tested code (stopwatch.ino).
About ₹609 for the parts at the prices on this page. Quantity price breaks lower the cost when you build several.
Timing with millis(); Debouncing buttons; Storing recent lap times.
Ideas that reuse this build: Pico stopwatch lap OLED. They are listed under Take it further on this page.
Warm, cool, rainbow or breathing: cycle lighting moods from your sofa.
Press to roll: the pips tumble and slow down before landing on a number.
Wait for the light, hit the button: how many milliseconds can you beat?
A bright 4-digit clock that keeps time through power cuts.
Learning project. Check every circuit and the datasheet of each part before you power it up.