Photon Dodge

by Crazy_ Whale in Circuits > Gadgets

40 Views, 0 Favorites, 0 Comments

Photon Dodge

1000034549.jpg
Photon Dodge #tech #IoT #Esp32 #nodemcu #child #mini project #game #gameplay #arduinotraining

Photon Dodge is a fast-paced reflex game built around a 16×2 LCD display. Unlike traditional LCD games that use only one row, this game transforms both rows into independent racing lanes. A glowing "photon" travels across the screen and the player must press the correct button when it reaches the strike zone.

Supplies

1000034533.jpg

Components Used:

Breadboard X 1

ESP32 development board X 1

16×2 LCD with I2C Module X 1

Push buttons X 2

Active buzzer X 1

Jumper Wires X 1

USB Cable X 1

Step 1: Understanding the Game

The LCD acts like a two-lane race track.

  1. Top row = Lane 1
  2. Bottom row = Lane 2

A photon appears on one of the lanes and moves from left to right.

Controls

ButtonFunction

Button A

Hit photon on top row

Button B

Hit photon on bottom row

Rules

  1. Start with 3 lives.
  2. Hit the photon when it reaches the last columns.
  3. Successful hit = score increases.
  4. Miss = lose one life.
  5. Speed increases continuously.
  6. Game ends when all lives are lost.


How It Works

The ESP32:

  1. Generates a random lane.
  2. Creates a photon at column 0.
  3. Moves the photon every few milliseconds.
  4. Checks whether the player pressed the correct button.
  5. Updates score and lives.
  6. Increases speed after successful hits.
  7. Shows Game Over and waits for restart.


Circuit Diagram

ChatGPT Image Jun 21, 2026, 05_43_18 PM.png

Connections

Buttons

Button ESP32 Pin

Top Lane Button GPIO13

Bottom Lane Button GPIO12

Connect the other side of each button to GND.

Buzzer

BuzzerESP32

+ GPIO25

- GND

LCD I2C Module

LCD ESP32

VCC 5V

GND GND

SDA GPIO21

SCL GPIO22


Build the Hardware

  1. Place the ESP32 on the breadboard.
  2. Connect the LCD module.
  3. Add two push buttons.
  4. Connect one side of each button to GND.
  5. Connect the buzzer to GPIO25.
  6. Verify all wiring before powering the circuit.


Create Custom Characters

Two custom LCD characters are used:

Photon Character

*
***
*****
*****
***
*

Heart Character

Used to display remaining lives.

* *
*****
*****
***
*

These characters are stored inside the LCD memory using:

lcd.createChar();

Initialize the System

During startup:

  1. Buttons are configured as INPUT_PULLUP.
  2. LCD is initialized.
  3. Backlight is enabled.
  4. Custom characters are loaded.
  5. Random number generator is seeded.
  6. First photon is spawned.

randomSeed(analogRead(34));
lcd.init();
lcd.backlight();
spawnPhoton();

Photon Generation

A random lane is selected:

photonRow = random(0,2);

Possible values:

  1. 0 = Top lane
  2. 1 = Bottom lane

The photon starts from:

photonCol = 0;


Photon Movement

The game uses a non-blocking timer based on:

millis()

Every few milliseconds:

photonCol++;

The photon moves one column to the right.

This makes animation smooth and responsive.

Strike Zone Detection

The last columns of the LCD act as the strike zone:

bool inZone = (photonCol >= 13 && photonCol <= 15);

When the photon reaches this area, the player must press the correct button.

Button Detection

Top button:

pressed(BTN_TOP)

Bottom button:

pressed(BTN_BOT)

Since INPUT_PULLUP is used:

LOW = Pressed
HIGH = Released

Successful Hit

If the player presses the correct button inside the strike zone:

score++;

A short beep is generated:

tone(BUZZ,1500,80);

The speed becomes faster:

speedDelay = max(150, speedDelay - 12);

Then another photon appears.

Missing a Photon

If the photon leaves the display:

photonCol > 15

The player loses one life:

lives--;

An error tone is played:

tone(BUZZ,200,250);

A new photon is then generated.

Game Over Screen

When:

lives == 0

The display shows:

GAME OVER
Score: XX

The buzzer plays a low tone and waits for the player to press any button to restart.

Main Program Loop

The game continuously repeats:


Upload the Code

  1. Open Arduino IDE.
  2. Install the LiquidCrystal_I2C library.
  3. Select your ESP32 board.
  4. Select the COM port.
  5. Upload the sketch.
  6. Press reset.

Your game is ready!

Features

  1. Uses both LCD rows as independent lanes
  2. Random photon spawning
  3. Smooth movement using custom characters
  4. Dynamic speed increase
  5. Score counter
  6. Three lives system
  7. Sound effects with buzzer
  8. Game Over screen
  9. Automatic restart
  10. Non-blocking code using millis()


Future Improvements

  1. Double Photon Mode
  2. Spawn photons on both rows simultaneously.
  3. Combo Multiplier
  4. Consecutive hits increase score multiplier.
  5. High Score Memory
  6. Store highest score using EEPROM.

Power-Ups

  1. Slow Motion
  2. Extra Life
  3. Shield

OLED Version:

  1. Upgrade to a 128×64 OLED display.

Joystick Control:

  1. Replace buttons with a joystick.

RGB LEDs:

  1. Add visual effects for hits and misses.


Conclusion

Photon Dodge transforms a simple 16×2 LCD into a miniature arcade machine. By using both rows as independent lanes, custom characters, sound effects, and adaptive speed control, the game provides surprisingly engaging gameplay while demonstrating important, embedded programming concepts such as state machines, timers, random number generation, and non-blocking animation.

If you enjoyed this project, consider adding EEPROM high-score storage, double-photon mode, or RGB lighting effects to create your own portable LCD arcade console.