Can someone verify my reaction time game?

First post! I’m a complete beginner in Arduino with very little coding knowledge. Can someone tell me what’s wrong with my circuit? I’m building a reaction time game, and the code was generated by ChatGPT.

code:

#include <LiquidCrystal.h>

// LCD pins: RS, E, D4, D5, D6, D7
LiquidCrystal lcd(8, 9, 10, 11, 12, 13);

// LEDs on pins 2, 3, 4, 5
const int leds[4] = {2, 3, 4, 5};

// Buttons on A0 and A1
const int button1 = A0;  
const int button2 = A1;

// Contrast pin
const int contrastPin = 6;

// Game variables
int currentLED = -1;
unsigned long ledOnTime = 0;
bool ledActive = false;
int roundCount = 0;
const int TOTAL_ROUNDS = 5;
int scores[5];
bool gameRunning = false;

void setup() {
  Serial.begin(9600);
  
  // Set LCD contrast (important for Tinkercad!)
  analogWrite(contrastPin, 100);
  
  delay(100);
  
  // Initialize LCD
  lcd.begin(16, 2);
  
  delay(100);
  
  // Setup LEDs
  for(int i = 0; i < 4; i++) {
    pinMode(leds[i], OUTPUT);
    digitalWrite(leds[i], LOW);
  }
  
  // Setup buttons
  pinMode(button1, INPUT_PULLUP);
  pinMode(button2, INPUT_PULLUP);
  
  randomSeed(analogRead(5));
  
  // Welcome screen
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Reaction Game");
  lcd.setCursor(0, 1);
  lcd.print("Press button");
  
  delay(2000);
  
  // Wait for button press to start
  while(digitalRead(button1) == HIGH && digitalRead(button2) == HIGH) {
    delay(100);
  }
  
  delay(500); // Debounce
  gameRunning = true;
  roundCount = 0;
}

void loop() {
  if(!gameRunning) return;
  
  // Check if all rounds completed
  if(roundCount >= TOTAL_ROUNDS) {
    showResults();
    gameRunning = false;
    return;
  }
  
  // Start new round
  playRound();
}

void playRound() {
  // Show round number
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Round ");
  lcd.print(roundCount + 1);
  lcd.print("/");
  lcd.print(TOTAL_ROUNDS);
  lcd.setCursor(0, 1);
  lcd.print("Wait...");
  
  // Random wait time (1-3 seconds)
  long waitTime = random(1000, 3000);
  delay(waitTime);
  
  // Turn LED on for 500ms
  currentLED = random(0, 4);
  digitalWrite(leds[currentLED], HIGH);
  
  // Display message
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("PRESS NOW!");
  
  // Record LED on time
  ledOnTime = millis();
  
  // Keep LED on for 500ms
  delay(500);
  digitalWrite(leds[currentLED], LOW);
  
  // Wait for button press (max 5 seconds)
  unsigned long buttonWaitStart = millis();
  bool buttonPressed = false;
  unsigned long reactionTime = 0;
  
  while(millis() - buttonWaitStart < 5000) {
    if(digitalRead(button1) == LOW || digitalRead(button2) == LOW) {
      reactionTime = millis() - ledOnTime;
      buttonPressed = true;
      break;
    }
    delay(10);
  }
  
  // Show result
  lcd.clear();
  
  if(buttonPressed) {
    lcd.setCursor(0, 0);
    lcd.print("Time:");
    lcd.setCursor(0, 1);
    lcd.print(reactionTime);
    lcd.print(" ms");
    
    scores[roundCount] = reactionTime;
    
    Serial.print("Round ");
    Serial.print(roundCount + 1);
    Serial.print(" - Time: ");
    Serial.print(reactionTime);
    Serial.println(" ms");
  } else {
    lcd.setCursor(0, 0);
    lcd.print("TOO SLOW!");
    lcd.setCursor(0, 1);
    lcd.print("No response");
    
    scores[roundCount] = 9999;
  }
  
  delay(2000);
  
  roundCount++;
  
  // Wait before next round
  if(roundCount < TOTAL_ROUNDS) {
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Round ");
    lcd.print(roundCount + 1);
    lcd.setCursor(0, 1);
    lcd.print("Get ready...");
    delay(2000);
  }
}

void showResults() {
  // Calculate best and average
  int bestTime = 9999;
  int totalTime = 0;
  int validScores = 0;
  
  for(int i = 0; i < TOTAL_ROUNDS; i++) {
    if(scores[i] < 9999) {
      if(scores[i] < bestTime) bestTime = scores[i];
      totalTime += scores[i];
      validScores++;
    }
  }
  
  int avgTime = (validScores > 0) ? totalTime / validScores : 0;
  
  // Screen 1: Average
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("GAME OVER!");
  lcd.setCursor(0, 1);
  lcd.print("Avg: ");
  lcd.print(avgTime);
  lcd.print("ms");
  
  delay(3000);
  
  // Screen 2: Best
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Best Time:");
  lcd.setCursor(0, 1);
  lcd.print(bestTime);
  lcd.print(" ms");
  
  delay(3000);
}

With all the wire being the same color and looking like a rats nest, it's hard to tell what is connected to what.

And that is what's wrong. You cannot ask an AI to do something that you can't do yourself.

Why?

Because you can't tell when it's making stuff up.

There is no royal road to learning.

Do you considered it as a guarantee of the code quality? :slight_smile:

Popular project!

The web search phrase "arduino reaction time game" will turn up lots of working examples.

One of which the AI may well have stolen, with or without embellishments. Who knows?

The circuit doesn't match your code. I see a four button in the schematic and only two button in the code.

Also, correct me if I'm wrong. The game consists of the fact that at a random time one of four LEDs lights up - and the user must press not just any button, but precisely the button corresponding to this LED. You have a randomly selected diode in your code, but there is no check for the pressed button

Oh no :face_with_open_eyes_and_hand_over_mouth: did ChatGPT make a mistake?

If you want to learn, starting with the Arduino Cookbook and the Electronics Cookbook both by O'Reilly is a good place to begin.

Updated circuit link and schematic diagram are provided below

Dazzling Allis-Sango-4.pdf (7.4 KB)

Did the code compile? I am looking at it on a cell phone so it is a little hard to read. But i think i saw an extra bracket.

Welcome! It’s hard to spot the issue without seeing the wiring and code, but double-check that all grounds are common and the pins in your code match the physical connections. Posting a clear photo of the circuit and the sketch will make it much easier for others to help you debug it.

what prevents me from holding all the buttons low ?