Reaction Timer Game

Test your reaction speed by pressing a button as quickly as possible when the LED turns on.

Components Needed

  • Arduino Uno
  • 1 LED
  • 220Ω Resistor
  • 1 Push Button
  • Breadboard
  • Jumper Wires
  • How It Works

    The Arduino waits for a random amount of time before turning on the LED. As soon as the LED lights up, the player must press the button as quickly as possible. The reaction time is measured and displayed in the Serial Monitor.

  • What You'll Learn

    ✅ Push Button Inputs

    ✅ Digital Outputs

    ✅ Random Delays

    ✅ Measuring Time

    ✅ Interactive Arduino Projects

  • Code

    const int ledPin = 8;
    const int buttonPin = 2;

    unsigned long startTime;

    void setup() {
    pinMode(ledPin, OUTPUT);
    pinMode(buttonPin, INPUT_PULLUP);

    Serial.begin(9600);

    randomSeed(analogRead(A0));
    }

    void loop() {

    digitalWrite(ledPin, LOW);

    int waitTime = random(2000, 7000);
    delay(waitTime);

    digitalWrite(ledPin, HIGH);

    startTime = millis();

    while (digitalRead(buttonPin) == HIGH) {
    // Waiting for button press
    }

    unsigned long reactionTime = millis() - startTime;

    digitalWrite(ledPin, LOW);

    Serial.print("Reaction Time: ");
    Serial.print(reactionTime);
    Serial.println(" ms");

    delay(3000);
    }