RO EN

Arduino Reflex Game with 16x2 LCD and Button

01/24/2026

This project describes the implementation of an Arduino-based reflex game designed to measure a user's reaction time to a visual signal displayed on an LCD. The system uses an Arduino Uno, a 16x2 LCD with I2C interface, and a push button for user interaction.

After startup, the display shows a waiting message, followed by a visual cue after a random delay. When the cue appears, the user presses the button and the system calculates and displays the reaction time in milliseconds. Button presses made before the signal are detected and reported accordingly.

The game logic and display control are implemented using Arduino IDE, relying on a dedicated LCD library and internal timing functions to manage delays and time measurement.

Required components

Hardware

  • Arduino Uno (or compatible board)

  • 16x2 LCD with I2C module

  • Push button

  • Jumper wires

  • Breadboard (optional)

  • USB cable

Hardware connections

LCD 16x2 I2C

  • GND GND
  • VCC 5V
  • SDA A4
  • SCL A5

Push button

  • One pin D2
  • Other pin GND

The button is configured using the Arduino's internal pull-up resistor.

Code:

#include <Wire.h>

#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 16, 2);

const int buttonPin = 2;

unsigned long startTime;

unsigned long reactionTime;

void setup() {

pinMode(buttonPin, INPUT_PULLUP);

lcd.init();

lcd.backlight();

randomSeed(analogRead(A0));

lcd.setCursor(0, 0);

lcd.print("Reflex Master");

lcd.setCursor(0, 1);

lcd.print("Press to start");

}

void loop() {

if (digitalRead(buttonPin) == LOW) {

delay(300);

playRound();

}

}

void playRound() {

lcd.clear();

lcd.setCursor(0, 0);

lcd.print("Wait...");

unsigned long waitTime = random(2000, 5000);

unsigned long startWait = millis();

while (millis() - startWait < waitTime) {

if (digitalRead(buttonPin) == LOW) {

tooEarly();

return;

}

}

lcd.clear();

lcd.setCursor(0, 0);

lcd.print("PRESS NOW!");

startTime = millis();

while (digitalRead(buttonPin) == HIGH);

reactionTime = millis() - startTime;

showReactionTime();

}

void tooEarly() {

lcd.clear();

lcd.setCursor(0, 0);

lcd.print("Too early!");

delay(2000);

}

void showReactionTime() {

lcd.clear();

lcd.setCursor(0, 0);

lcd.print("Reaction time:");

lcd.setCursor(0, 1);

lcd.print(reactionTime);

lcd.print(" ms");

delay(3000);

}