Supplier photo of an assembled radio kit with a purple circuit board, telescopic antenna and clear case.
Supplier photo
Temu affiliate offer ยท Project idea

Build a radio

Soldering required. Check the supplied parts and board revision.

View kit on Temu

Tricky Circuit may earn a commission through these links. Product ideas have not been bench-tested by Tricky Circuit and are not verified lesson parts lists.

๐ŸŽฒ Retro Game: Guess the Number


๐Ÿ”ง Components Needed

  • Arduino Board (e.g., Arduino Uno or Arduino R4)
  • I2C LCD 1602 Display
  • Jumper Wires
  • Breadboard (optional)

๐Ÿ“Œ Wiring Connections

  1. I2C LCD 1602 Display:
    • VCC: โ†’ Arduino 5V
    • GND: โ†’ Arduino GND
    • SDA: โ†’ Arduino A4 (on Uno) or corresponding SDA pin
    • SCL: โ†’ Arduino A5 (on Uno) or corresponding SCL pin

Note: The typical I2C address for these displays is 0x27. Verify with an I2C scanner if needed.


๐Ÿ’ป Code Example

This sketch uses the LiquidCrystal_I2C library. It will generate a random number between 1 and 100, then prompt you (via the Serial Monitor) to enter guesses. Based on your input, the LCD displays hints like โ€œToo High!โ€ or โ€œToo Low!โ€ until you guess correctly.

#include <LiquidCrystal_I2C.h>

// ----- LCD Settings -----
LiquidCrystal_I2C lcd(0x27, 16, 2);  // I2C address 0x27, 16 columns, 2 rows

// Global game variables
int secretNumber;
bool gameOver = false;

void setup() {
  // Initialize Serial Monitor
  Serial.begin(9600);
  while (!Serial) { ; }  // Wait for Serial to initialize (if needed)
  
  // Initialize LCD
  lcd.init();
  lcd.backlight();
  
  // Welcome message on LCD
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Guess The Number");
  lcd.setCursor(0, 1);
  lcd.print("1-100");
  
  // Seed random generator using an unconnected analog pin
  randomSeed(analogRead(0));
  
  // Generate secret number between 1 and 100
  secretNumber = random(1, 101);
  
  // Prompt in Serial Monitor
  Serial.println("Welcome to 'Guess The Number'!");
  Serial.println("I'm thinking of a number between 1 and 100.");
  Serial.println("Enter your guess:");
}

void loop() {
  if (Serial.available() > 0 && !gameOver) {
    int guess = Serial.parseInt();
    if (guess == 0) return; // Skip if no valid number entered
    
    // Clear LCD for new message
    lcd.clear();
    
    if (guess < secretNumber) {
      lcd.setCursor(0, 0);
      lcd.print("Too Low!");
      Serial.println("Too Low! Try again:");
    } 
    else if (guess > secretNumber) {
      lcd.setCursor(0, 0);
      lcd.print("Too High!");
      Serial.println("Too High! Try again:");
    } 
    else {
      lcd.setCursor(0, 0);
      lcd.print("Correct!");
      lcd.setCursor(0, 1);
      lcd.print("You Win!");
      Serial.println("Correct! You win!");
      gameOver = true;
    }
    
    // Wait a moment before next input
    delay(1500);
    
    // If game not over, re-prompt on LCD
    if (!gameOver) {
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("Guess 1-100");
      Serial.println("Enter your next guess:");
    }
  }
}

๐Ÿ“‹ How It Works

  • Game Initialization:
    • The LCD shows a welcome message (“Guess The Number”) and indicates the range (1-100).
    • A random secret number is generated using random(1, 101).
  • User Input via Serial Monitor:
    • The player enters guesses in the Serial Monitor.
    • The code reads these guesses using Serial.parseInt().
  • Feedback Mechanism:
    • If the guess is too low or too high, the LCD and Serial Monitor provide feedback (e.g., โ€œToo Low!โ€ or โ€œToo High!โ€).
    • Once the correct number is guessed, a congratulatory message is displayed, and the game ends.
  • Display Update:
    • The LCD updates after each guess, ensuring that messages are clear even on the small 16ร—2 screen.

๐ŸŽฏ Enhancements & Ideas

  • Reset Button:
    • Add a push button to reset the game without restarting the Arduino.
  • Score Keeping:
    • Track the number of guesses and display the score.
  • Multiple Levels:
    • Introduce levels where the number range increases as the player wins.
  • Custom Characters:
    • Use custom characters on the LCD for fun icons (e.g., smiley faces when winning).

Enjoy building your retro, text-based game on the Arduino with the I2C LCD 1602! If you have any questions or need further tweaks, feel free to ask. Happy gaming! ๐Ÿ˜Š๐ŸŽฎโœจ

Temu affiliate offer

Optional accessory for this article

The parts list makes the breadboard optional: it can simply provide accessible junctions for the display wiring. This Temu offer contains four 400-point boards; the controller, display and wires are separate.

Some links below are Temu affiliate links. Tricky Circuit may earn a commission if you buy through them.

YIDI 400-point solderless breadboards, 4-pack โ€” view Temu offer

๐Ÿ“กBroadcast the signal โ€” amplify the connection.

Leave a Reply

Temu affiliate offers

Find your next electronics project

Explore these do-it-yourself project kits. Check the selected option, included parts and instructions on each offer.

Tricky Circuit may earn a commission if you buy through these Temu affiliate links. These are product ideas; they have not been bench-tested by Tricky Circuit and are not verified lesson parts lists.

Supplier photo of an assembled infinity mirror light cube illuminated on a dark background.

Supplier product photo

Build an infinity light cube

Listing specifies 5-volt direct current. Soldering required; battery and glue not included.

View kit on Temu

Supplier photo of a breadboard, jumper wires and assorted electronic components in a plastic storage case.

Supplier product photo

Try breadboard experiments

Breadboard, wires and assorted parts. Arduino controller board not included.

View kit on Temu

Supplier photo of an assembled blue surface-mount soldering practice board with a circular ring of small lights.

Supplier product photo

Solder a chasing-light board

Surface-mount soldering practice. Battery and battery holder not included.

View kit on Temu