Illustration: at a kitchen table two players race for their buttons; the red LED in the middle is lit.Games
Illustration (made with AI): roughly what the finished project looks like.

A Two-Player Reaction Game

An LED lights at a random moment. Whoever presses their button first wins. Built from Student Kit parts in 45 minutes.

Difficulty
Beginner
Time
45 min
Age
10+
Parts
6, 6 on the site

Adapted from “Button (Built-in Examples)” by Arduino. Licence: CC BY-SA 4.0. This translation is shared under the same licence. The parts list and the tips are RoboHub's.

Variations

Choose a variation and the parts list updates.

Instructions

  1. Buttons

    Connect two buttons between pins 2 and 3 and ground. The code turns on the internal pull-up resistors.

    D2 is the board's digital pin 2, GND is ground. Red wires are power, black ground, the other colours signals (on a real servo the ground wire is often brown). In the steps, what a step adds is in colour and what is already connected in grey.

    • Button A 1 → Arduino D2
    • Button A 2 → Arduino GND
    • Button B 1 → Arduino D3
    • Button B 2 → Arduino GND
  2. LED and buzzer

    The LED goes to pin 7 through a 330 Ω resistor, the buzzer to pin 8.

    D2 is the board's digital pin 2, GND is ground. Red wires are power, black ground, the other colours signals (on a real servo the ground wire is often brown). In the steps, what a step adds is in colour and what is already connected in grey.

    • Red LED + → 330 ΩArduino D7
    • Red LED − → Arduino GND
    • Buzzer + → Arduino D8
    • Buzzer − → Arduino GND
  3. Upload the code

    The code waits a random time, then lights the LED and checks which button was pressed first.

    Arduino C++
    const int LED = 7, BUZZER = 8;
    const int BTN_A = 2, BTN_B = 3;
    
    void setup() {
      pinMode(LED, OUTPUT);
      pinMode(BTN_A, INPUT_PULLUP);
      pinMode(BTN_B, INPUT_PULLUP);
      Serial.begin(9600);
      randomSeed(analogRead(A0));
    }
    
    void loop() {
      digitalWrite(LED, LOW);
      delay(random(2000, 6000));           // a random wait
      digitalWrite(LED, HIGH);
      tone(BUZZER, 1500, 100);
    
      while (true) {
        if (digitalRead(BTN_A) == LOW) { Serial.println("A wins"); break; }
        if (digitalRead(BTN_B) == LOW) { Serial.println("B wins"); break; }
      }
      delay(2000);
    }
  4. Play

    Open the Serial Monitor (9600): it shows who won.

    Illustration: a breadboard with a button at each end, a lit red LED and a buzzer in the middle.

    Illustration, made with AI

  • Lights and displays
    Beginner45 min10+

    Pedestrian Crossing with a Button

    Cars have green until a pedestrian presses the button. Then the cars get red, the pedestrians get green and a buzzer ticks, just like at a real crossing.

    6/6 parts on the site
  • Games
    Beginner40 min8+

    A Little Button Piano

    Five buttons, five notes: C, D, E, F and G. Press a button and the buzzer plays its note, enough for simple tunes.

    5/5 parts on the site
  • Sensors
    Beginner1 h10+

    Parking Sensor with Sound and Lights

    An ultrasonic sensor measures the distance. Three LEDs show how close the obstacle is, and the buzzer beeps faster the closer you get.

    6/6 parts on the site