Remote-controlled RGB mood light
Warm, cool, rainbow or breathing: cycle lighting moods from your sofa.
Shop by category
Shop all componentsAfter a random wait of two to six seconds the buzzer sounds and the OLED shows GO. The first player to press wins the round and gets a point; pressing before the beep loses it. The random delay comes from the ESP32's hardware random number generator. Both buttons use the built-in pull-up resistors, so the wiring is just a button and a ground wire for each player.
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 or charger.
reaction_game.inoVerify & upload in Electrolark#include <Wire.h>
#include <Adafruit_SSD1306.h>
Adafruit_SSD1306 oled(128, 64, &Wire, -1);
const int BTN_A = 14, BTN_B = 27, BUZZER = 25;
int scoreA = 0, scoreB = 0;
void show(const char* msg) {
oled.clearDisplay(); oled.setTextColor(WHITE);
oled.setTextSize(2); oled.setCursor(0, 0); oled.print(msg);
oled.setTextSize(1); oled.setCursor(0, 50); oled.printf("A %d B %d", scoreA, scoreB);
oled.display();
}
void setup() {
pinMode(BTN_A, INPUT_PULLUP); pinMode(BTN_B, INPUT_PULLUP); pinMode(BUZZER, OUTPUT);
Wire.begin(21, 22);
oled.begin(SSD1306_SWITCHCAPVCC, 0x3C);
}
void loop() {
show("Get ready");
unsigned long wait = 2000 + (esp_random() % 4000);
unsigned long start = millis();
while (millis() - start < wait) {
if (digitalRead(BTN_A) == LOW) { scoreB++; show("A too early!"); delay(2000); return; }
if (digitalRead(BTN_B) == LOW) { scoreA++; show("B too early!"); delay(2000); return; }
}
digitalWrite(BUZZER, HIGH); show("GO!"); delay(150); digitalWrite(BUZZER, LOW);
while (true) {
if (digitalRead(BTN_A) == LOW) { scoreA++; show("A wins!"); break; }
if (digitalRead(BTN_B) == LOW) { scoreB++; show("B wins!"); break; }
}
delay(2500);
}
A wire is touching GND; check the button wiring.
Check the OLED I2C wires.
Check the pin and whether your module is active or passive.
Yes, both buttons are read in the same loop; the difference is microseconds.
Yes, subtract the GO time from the press time and show milliseconds.
Add a third button and pin.
6 parts: ESP32-WROOM-32 38-Pin Development Board, 2 × Tactile Push Button Switch, 0.96" OLED Display 128x64, Buzzer Module 3.3–5V, 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 (reaction_game.ino).
About ₹636 for the parts at the prices on this page. Quantity price breaks lower the cost when you build several.
Random delays with esp_random(); Detecting which of two buttons was first; Penalising early presses.
Ideas that reuse this build: Pico reaction game. 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.