Build it step by step
0 of 6 doneWire the buttons
One leg of each button to D2 and D3, the other to GND. The sketch turns on the internal pull-ups.
Add the LED
Anode through 220 Ω to D4, cathode to GND.
Add sound and display
Buzzer to D5 and GND. TM1637 CLK to D6, DIO to D7, power to 5V and GND.
Upload
Install the TM1637 library and upload the sketch.
Play a round
Wait for the LED. The first button wins and the display shows P1 or P2, then the time.
Test a false start
Press early and check the display shows F and the player number.
How do you build a two-player reaction duel?
After a random wait an LED lights and the first player to press their button wins, with the reaction time shown. Pressing early loses. You need Arduino Nano, LED 5 mm red, Resistor 220 Ω, Arcade push button 30 mm × 2, TM1637 4-digit display, Passive buzzer, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm). It takes 6 steps and about 45 minutes.
- Level
- Beginner
- Time
- About 45 min
- Parts
- 8
Parts list
- Development BoardsBuyArduino Nano × 1
- SemiconductorsBuyLED 5 mm red × 1
- PassivesBuyResistor 220 Ω × 1
- Switches
- DisplaysBuy
- Motors & ActuatorsBuyPassive buzzer × 1
- PrototypingBuy
- PrototypingBuy
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| Player 1 button | Nano D2 and GND | Uses the internal pull-up |
| Player 2 button | Nano D3 and GND | Uses the internal pull-up |
| Go LED anode through 220 Ω | Nano D4 | The signal to react to |
| Go LED cathode | GND | Return |
| Passive buzzer + / − | Nano D5 / GND | Sounds |
| TM1637 CLK / DIO | Nano D6 / D7 | Time display |
| TM1637 VCC / GND | Nano 5V / GND | Power |
Code
Arduino IDE, board "Arduino Nano" (processor ATmega328P, or ATmega328P (Old Bootloader) for clones). Install the library "TM1637" by Avishay Orpaz from the Library Manager.
Runs on a virtual Arduino Nano in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).
#include <TM1637Display.h> // library "TM1637" by Avishay Orpaz
const byte P1 = 2, P2 = 3, LED = 4, BUZ = 5;
TM1637Display disp(6, 7);
void setup() {
pinMode(P1, INPUT_PULLUP); pinMode(P2, INPUT_PULLUP);
pinMode(LED, OUTPUT);
disp.setBrightness(5);
randomSeed(analogRead(A0)); // an unconnected pin gives noise
}
byte pressed() { // 1 or 2 for a player, 0 for none
if (digitalRead(P1) == LOW) return 1;
if (digitalRead(P2) == LOW) return 2;
return 0;
}
void showWho(byte c1, byte player) {
uint8_t seg[4] = {c1, 0, 0, disp.encodeDigit(player)};
disp.setSegments(seg);
}
void loop() {
digitalWrite(LED, LOW);
uint8_t dash[4] = {0x40, 0x40, 0x40, 0x40};
disp.setSegments(dash);
while (pressed()) {} // wait until both buttons are released
delay(500);
unsigned long wait = random(2000, 6000), t0 = millis();
while (millis() - t0 < wait) {
byte p = pressed();
if (p) { // pressed before the LED: this player loses
tone(BUZ, 200, 400);
showWho(0x71, p); // F and the player number
delay(2500);
return;
}
}
digitalWrite(LED, HIGH);
unsigned long start = micros();
byte p = 0;
while (!(p = pressed())) {}
unsigned long ms = (micros() - start) / 1000;
digitalWrite(LED, LOW);
tone(BUZ, 1500, 150);
showWho(0x73, p); // P and the winner
delay(1500);
disp.showNumberDec(ms); // the winning time in milliseconds
delay(3500);
}Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| Wait for the LED, then press | Display shows P and the player number, then a time such as 245 |
| Press before the LED | A low beep and F with the player number |
| Press at the same time | The player checked first (player 1) wins, which is fine for a game |
| Typical times | Most people are between 180 and 350 ms |
If it does not work
The LED never lights
Check its direction and that its resistor goes to D4.
A press is never detected
Buttons must go between the pin and GND, and the sketch uses INPUT_PULLUP.
The display stays blank
Check CLK and DIO are on D6 and D7 and the library is installed.
Times always show 0
A button is stuck closed. Check wiring and that you released both before the round.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the two-player reaction duel?
Arduino Nano, LED 5 mm red, Resistor 220 Ω, Arcade push button 30 mm × 2, TM1637 4-digit display, Passive buzzer, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm).
How long does the two-player reaction duel take to build?
About 45 minutes for a beginner maker, in 6 steps.
How do I know the two-player reaction duel works?
Wait for the LED, then press: Display shows P and the player number, then a time such as 245. Press before the LED: A low beep and F with the player number. Press at the same time: The player checked first (player 1) wins, which is fine for a game.
The LED never lights: what should I check?
Check its direction and that its resistor goes to D4.
A press is never detected: what should I check?
Buttons must go between the pin and GND, and the sketch uses INPUT_PULLUP.
The display stays blank: what should I check?
Check CLK and DIO are on D6 and D7 and the library is installed.
Times always show 0: what should I check?
A button is stuck closed. Check wiring and that you released both before the round.
