মূল বিষয়বস্তুতে যান
Back to Projects
BeginnerArduino Uno R3
30 minutes build

Reaction timer game

A random wait, a light, a beep — and how fast can you press?

Interactive Simulation

Reaction timer gamearduino-uno
Open in Lab
UNOATmega328P: The 8-bit AVR microcontroller that runs your sketch (16 MHz, 32 KB flash, 2 KB RAM).ATmega328PUSB-B: USB connection for uploading sketches and for the Serial Monitor. Also powers the board (5 V).DC jack: Barrel jack for 7–12 V from a battery pack or adapter (centre positive).ATmega16U2: Converts USB to serial for uploads and Serial.print().RESET: Restarts your sketch from the beginning (setup() runs again).L (D13): Built-in LED connected to pin 13 (LED_BUILTIN).ON: Power indicator.5 V regulator: Turns 7–12 V from VIN/jack into a steady 5 V.16 MHz: Clock source: the microcontroller runs 16 million cycles per second.ICSP: In-circuit programming header (SPI). Used to burn a bootloader; not needed for normal uploads.220 Ω+

Required Components Checklist

Assembly Steps

1

Wire it

Button between pin 2 and GND, LED with resistor on pin 9, buzzer between pin 8 and GND.

2

Random delay

random(1500, 4000) waits a different time each round so you can't guess.

3

Measure

Store millis() when the LED turns on and subtract it when the button goes LOW.

Arduino Sketch

const int BUTTON = 2, LED = 9, BUZZER = 8;

void setup() {
  pinMode(BUTTON, INPUT_PULLUP);
  pinMode(LED, OUTPUT);
  Serial.begin(9600);
  randomSeed(analogRead(A1)); // noise from an unconnected pin
  Serial.println("Get ready... press the button when the LED lights!");
}

void loop() {
  delay(random(1500, 4000));
  if (digitalRead(BUTTON) == LOW) {
    Serial.println("Too early! Let go and wait for the light.");
    while (digitalRead(BUTTON) == LOW) delay(10);
    return;
  }
  digitalWrite(LED, HIGH);
  tone(BUZZER, 880, 80);
  unsigned long start = millis();
  while (digitalRead(BUTTON) == HIGH) {
    if (millis() - start > 3000) break;
  }
  unsigned long reaction = millis() - start;
  digitalWrite(LED, LOW);
  if (reaction > 3000) Serial.println("Too slow — try again.");
  else {
    Serial.print("Reaction time: ");
    Serial.print(reaction);
    Serial.println(" ms");
  }
  while (digitalRead(BUTTON) == LOW) delay(10);
}

Challenges & Extensions

Ready to take this project further? Try these challenges:

  • •Keep the best time of the session.
  • •Make it a two-player game with a second button.
  • •Show a rating: under 250 ms = lightning.