Lights and displaysPedestrian 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.
GamesAn LED lights at a random moment. Whoever presses their button first wins. Built from Student Kit parts in 45 minutes.
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.
Choose a variation and the parts list updates.
Connect two buttons between pins 2 and 3 and ground. The code turns on the internal pull-up resistors.
The LED goes to pin 7 through a 330 Ω resistor, the buzzer to pin 8.
The code waits a random time, then lights the LED and checks which button was pressed first.
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);
}Open the Serial Monitor (9600): it shows who won.

Illustration, made with AI
Illustration: at a kitchen table two players race for their buttons; the red LED in the middle is lit.
Step 4: Play
Lights and displaysCars 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.
GamesFive buttons, five notes: C, D, E, F and G. Press a button and the buzzer plays its note, enough for simple tunes.
SensorsAn ultrasonic sensor measures the distance. Three LEDs show how close the obstacle is, and the buzzer beeps faster the closer you get.