|
Arduino Nano R3 |
x 1 | |
|
I2C 16x2 Arduino LCD Display Module |
x 1 | |
|
LED |
x 10 | |
|
Buzzer |
x 1 | |
|
Pushbutton |
x 2 | |
|
Resistor 10k ohm |
x 2 | |
|
Resistor, 470 ohm |
x 10 |
![]() |
Soldering iron (generic) |
|
![]() |
Solder Wire, Lead Free |
|
![]() |
arduino IDEArduino
|
DIY simple HUNTER Led Game with Arduino
Some time ago I presented you a simple to make, but interesting game, a 1D version simulation of "Pong game" made with Arduino and 10 LEDs. This time I'm going to use the same hardware with minimal pinout changes to show you how to make an equally fun and addictive game known as "Hunter". The goal of the game is to press a button at the moment when a pre-defined LED is lit and we get a point.
This is a modified version of the Hunter, with two LEDs marked as the target. The Target LEDs are Blue, and the arrows indicate the direction of movement in which they are active. The LEDs "move" in the style of the Night Rider effect, where the first target (LED) is active when moving from left to right, and the second one vice versa, from right to left.
Information about the game and the score is displayed on the 16x2 LCD Display.
The first level is the easiest, and in each subsequent level the speed of movement of the LEDs increases. For each level we have 10 seconds to hit the target. With each passed level we get one point. If we fail to hit a target within 10 seconds, the game ends, the score is displayed on the screen, and after three seconds a new game begins. The movement of the LEDs, hitting the target, and the end of the game are followed by corresponding different sounds generated by a small buzzer.
As I mentioned before, the game is very simple to make and contains only a few components:
- Arduino Nano microcontroller board
- I2C LCD Display 16x2
- 10 LEDs
- 2 Buttons (only one is enough, but in this case they are connected in parallel because they remained from the previous project)
- Buzzer
- And ten resistors of 470 ohms to limit the current of the LEDs
I should mention here that you can also use only one resistor for all the LEDs. Namely, in this project, more than one diode is never lit at one time. In this special case, we connect the anodes directly to the Arduino pins and the cathodes to each other, and through a series resistor of 470 ohms to ground (the negative pole). Schematic diagrams for this case is given below.
Аnd now let's see how this device works in reality: At the start of the game the LEDs start to move from left to right and vice versa in the style of effect night rider. Now you need to press one of the buttons at the moment when one of the blue target Leds is lit. If we did it successfully, we go to the next level, where the Leds moves with higher speed. If we fail to hit the target in 10 seconds, the game ends and the final score appears, and after three seconds a new game starts.
And finally a short conclusion:
This is a custom version of the Hunter game with 10 LED and LCD display to show the score, followed by various sound effects. It was made on the basis of a previous project, where the same hardware and box were used, and only the Arduino code was changed. In the next period I will try to make another interesting game, while again using the same hardware configuration from the previous two projects.
#include <Wire.h> #include <LiquidCrystal_I2C.h> // Initialize the LCD, set the address to 0x27 or 0x3F depending on your module LiquidCrystal_I2C lcd(0x27, 16, 2); // 16 columns, 2 rows // Pin setup int ledPins[] = {4, 5, 6, 7, 8, 9, 10, 11, 12, 13}; // Pins for the 8 LEDs int buttonPin = 2; // Pin for the button int buzzerPin = 3; // Pin for the piezo buzzer int middleLED = 5; // The middle LED position (adjust if needed) int direction = 1; // Initial direction (1 = forward, -1 = backward) int currentLED = 0; // Start at the first LED int level = 1; // Start at level 1 int delayTime = 300; // Initial delay time for LED movement (in ms) int score = 0; // Player score int levelTime = 10; // Time allowed for each level (in seconds) unsigned long startTime; // Time when the level starts unsigned long lastMoveTime = 0; // Time when the LEDs last moved unsigned long lastToneTime = 0; // Time to control the duration of the tone unsigned long buttonDebounceTime = 0; // For button debouncing unsigned long debounceDelay = 50; // Debounce delay in milliseconds int lastRemainingTime = -1; // To track the last displayed time int lastLevel = -1; // To track the last displayed level int lastScore = -1; // To track the last displayed score bool buttonPressed = false; bool tonePlaying = false; // Flag to indicate whether the tone is currently playing bool gameEnded = false; // Flag to indicate the end of the game // Function to play a tone non-blocking void startTone(int frequency) { tone(buzzerPin, frequency); // Start playing the tone tonePlaying = true; // Set tone playing flag lastToneTime = millis(); // Record when the tone started } void stopTone() { noTone(buzzerPin); // Stop playing the tone tonePlaying = false; // Reset tone playing flag } void setup() { // Initialize the LCD lcd.init(); lcd.backlight(); lcd.clear(); lcd.setCursor(0, 0); lcd.print("HUNTER Game"); delay(2000); // Display the welcome message for 2 seconds // Pin configurations for (int i = 0; i < 10; i++) { pinMode(ledPins[i], OUTPUT); // Set all LED pins as outputs } pinMode(buttonPin, INPUT_PULLUP); // Set button pin as input with pullup pinMode(buzzerPin, OUTPUT); // Set buzzer pin as output Serial.begin(9600); // Start serial for debugging Serial.println("Welcome to the Knight Rider Hunter Game!"); lcd.clear(); displayStatus(); // Display the initial level, score, and time startTime = millis(); // Record when the level starts lastMoveTime = millis(); // Initialize the last move time } void loop() { // If the game has ended, stop further operations if (gameEnded) { return; } // Check if the timer has expired unsigned long elapsedTime = (millis() - startTime) / 1000; int remainingTime = levelTime - elapsedTime; // If time has run out, end the game if (remainingTime <= 0) { endGame(); // Call the function to end the game return; // Stop further execution } // Handle LED movement (non-blocking using millis) if (millis() - lastMoveTime >= delayTime) { moveLED(); lastMoveTime = millis(); // Reset the last move time startTone(1000); // Start playing the 1000Hz tone when moving LED } // Stop the tone after 50ms if (tonePlaying && millis() - lastToneTime >= 50) { stopTone(); // Stop the tone after 50ms } // Check if the button is pressed (with debouncing) int buttonState = digitalRead(buttonPin); if (buttonState == LOW && millis() - buttonDebounceTime > debounceDelay) { buttonDebounceTime = millis(); // Reset debounce timer if (currentLED == middleLED) { Serial.println("You win this level!"); score++; // Increase score for a successful hit startTone(2000); // Play victory tone delay(500); // Play for 500ms stopTone(); levelUp(); // Go to the next level } else { Serial.println("Missed! Try again."); startTone(500); // Play fail sound delay(300); // Play for 300ms stopTone(); } delay(500); // Short pause after button press } // Update LCD with the remaining time and score only if there's a change if (remainingTime != lastRemainingTime || level != lastLevel || score != lastScore) { displayStatus(); lastRemainingTime = remainingTime; lastLevel = level; lastScore = score; } } // Function to move the LEDs void moveLED() { // Turn off all LEDs for (int i = 0; i < 10; i++) { digitalWrite(ledPins[i], LOW); } // Light up the current LED digitalWrite(ledPins[currentLED], HIGH); // Move the LED in the current direction currentLED += direction; // Reverse direction if we reach the end of the LED array if (currentLED == 9 || currentLED == 0) { direction = -direction; } } // Function to advance to the next level void levelUp() { level++; // Increase the level delayTime -= 30; // Decrease delay time to make LEDs move faster // Ensure delayTime doesn't go below a certain threshold (e.g., 50 ms) if (delayTime < 50) { delayTime = 50; } Serial.print("Level Up! Now at Level: "); Serial.println(level); Serial.print("New LED Speed (ms): "); Serial.println(delayTime); // Play level-up sound startTone(1500); // Play a tone at 1.5kHz delay(300); // Play for 300ms stopTone(); delay(1000); // Give a 1-second pause before starting the next level // Reset the timer for the next level startTime = millis(); } // Function to display the current level, score, and remaining time void displayStatus() { // Calculate the remaining time in seconds unsigned long elapsedTime = (millis() - startTime) / 1000; // Convert to seconds int remainingTime = levelTime - elapsedTime; // Calculate the remaining time // Ensure the remaining time does not go negative if (remainingTime < 0) { remainingTime = 0; } lcd.setCursor(0, 0); lcd.print("Lvl:"); lcd.print(level); lcd.setCursor(6, 0); lcd.print("Time:"); lcd.print(remainingTime); // Correctly print the remaining time in seconds // Clear any leftover characters by overwriting with a space if (remainingTime < 10) { lcd.print(" "); // Overwrite the extra digit when remainingTime is a single digit } lcd.setCursor(0, 1); lcd.print("Score:"); lcd.print(score); } // Function to end the game when the timer runs out void endGame() { gameEnded = true; // Set the flag to end the game // Turn off all LEDs for (int i = 0; i < 8; i++) { digitalWrite(ledPins[i], LOW); } // Display "End Game" and the final score on the LCD lcd.clear(); lcd.setCursor(0, 0); lcd.print("End Game"); lcd.setCursor(0, 1); lcd.print("Score:"); lcd.print(score); // Play a sound to indicate the game has ended startTone(300); // Play a low tone delay(1000); // Play for 1 second stopTone(); // Wait for 3 seconds before starting a new game delay(3000); // Restart the game resetGame(); } // Function to reset the game and start a new one void resetGame() { gameEnded = false; // Reset the game end flag score = 0; // Reset the score to 0 level = 1; // Reset the level to 1 delayTime = 300; // Reset the delay time for LED movement startTime = millis(); // Reset the timer // Clear the LCD and display the initial status lcd.clear(); displayStatus(); Serial.println("New game started!"); // Restart the LED movement immediately lastMoveTime = millis(); }

DIY simple HUNTER Led Game with Arduino

Raspberry Pi 5 7 Inch Touch Screen IPS 1024x600 HD LCD HDMI-compatible Display for RPI 4B 3B+ OPI 5 AIDA64 PC Secondary Screen(Without Speaker)
BUY NOW
ESP32-S3 4.3inch Capacitive Touch Display Development Board, 800×480, 5-point Touch, 32-bit LX7 Dual-core Processor
BUY NOW
Raspberry Pi 5 7 Inch Touch Screen IPS 1024x600 HD LCD HDMI-compatible Display for RPI 4B 3B+ OPI 5 AIDA64 PC Secondary Screen(Without Speaker)
BUY NOW- Comments(0)
- Likes(0)

- 0 USER VOTES
- YOUR VOTE 0.00 0.00
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
More by Mirko Pavleski
-
DIY ESP32 Bioresonance Rife Machine with ZAPPER function Rife machine therapy is an alternative treatment developed by Dr. Royal Raymond Rife in the 1930s. H...
-
Arduino VFO Project with a Large LCD Display A Variable Frequency Oscillator (VFO) is an electronic oscillator whose output frequency can be adj...
-
Exploring the Tesla Coil Driver Board, Full Review & Test Results Some time ago I presented you a video in which I analyzed a super cheap Tesla Coil driver that cost...
-
Arduino Eatrthquake alarm and protection system with D7S seismic Sensor Earthquakes are extremely common events around the world. On average, there are fifty earthquakes a...
-
Review and Comparison of Three Inexpensive Metal Detector Kits A metal detector is a device used to detect the presence of metal objects in the ground or other ma...
-
How to make simple Arduino RGB Led strip VU Meter VU meter or volume unit meter is a device intended for visual presentation of the audio signal. It ...
-
Arduino 3D Printed self Balancing Cube Self-balancing devices are electronic devices that use sensors and motors to keep themselves balanc...
-
OpenWebRX - Simplest Rasprberry Pi + RTLSDR Web SDR Radio Software-Defined Radio is a radio communication system where components that have traditionally bee...
-
Colorful Arduino Tetris Game - WS2812B LED Matrix Tutorial Tetris is a puzzle video game created in 1985 by Alexey Pajitnov. Players manipulate falling geomet...
-
Ultra cheap Ultrasonic levitation Device - functionality and testing Ultrasonic levitation is phenomenon where objects are suspended in mid-air using the power of sound ...
-
DIY -Spirit PI- ESP32 + Smartphone Sensitive Metal Detector Pulse Induction (PI) metal detector operates on a principle based on sending short pulses of electr...
-
ESP32 Analog style VU meter with GC9A01 Round Dispalys + Peak Meters A typical VU meter measures audio signals and displays them with a visual indicator. In the classic...
-
Arduino two weel self Balancing Robot Self Balancing Robot is device that can balance itself from falling to the ground. Its function is ...
-
ELECROW CrowPanel ESP32 4.2” E-paper Wi-Fi Info-Dispaly Project An e-paper display (also known as an electronic paper display or E Ink display) is a type of screen...
-
ESP32 Fluid simulation on 16x16 Led Matrix Fluid simulation is a way of replicating the movement and behavior of liquids and gases in differen...
-
Simple GU50 VTTC Tesla Coil with MOT (25+cm Spark) Vacuum Tube Tesla Coils are a common choice for homebuilders for several practical reasons. At Soli...
-
Hourglass ESP8266 Code A hourglass, also known as an sand clock, is a device used to measure the passage of time. It consi...
-
Tug of War Arduino Game on WS2812 Led strip A Tug of War is a classic team-based game where two opposing teams compete to pull a rope in opposi...
-
DIY ESP32 Bioresonance Rife Machine with ZAPPER function Rife machine therapy is an alternative treatment developed by Dr. Royal Raymond Rife in the 1930s. H...
-
Arduino VFO Project with a Large LCD Display A Variable Frequency Oscillator (VFO) is an electronic oscillator whose output frequency can be adj...
-
Exploring the Tesla Coil Driver Board, Full Review & Test Results Some time ago I presented you a video in which I analyzed a super cheap Tesla Coil driver that cost...
-
Arduino Eatrthquake alarm and protection system with D7S seismic Sensor Earthquakes are extremely common events around the world. On average, there are fifty earthquakes a...
-
Review and Comparison of Three Inexpensive Metal Detector Kits A metal detector is a device used to detect the presence of metal objects in the ground or other ma...
-
How to make simple Arduino RGB Led strip VU Meter VU meter or volume unit meter is a device intended for visual presentation of the audio signal. It ...
-
Arduino 3D Printed self Balancing Cube Self-balancing devices are electronic devices that use sensors and motors to keep themselves balanc...
-
OpenWebRX - Simplest Rasprberry Pi + RTLSDR Web SDR Radio Software-Defined Radio is a radio communication system where components that have traditionally bee...
-
Colorful Arduino Tetris Game - WS2812B LED Matrix Tutorial Tetris is a puzzle video game created in 1985 by Alexey Pajitnov. Players manipulate falling geomet...
-
Ultra cheap Ultrasonic levitation Device - functionality and testing Ultrasonic levitation is phenomenon where objects are suspended in mid-air using the power of sound ...
-
DIY -Spirit PI- ESP32 + Smartphone Sensitive Metal Detector Pulse Induction (PI) metal detector operates on a principle based on sending short pulses of electr...
-
ESP32 Analog style VU meter with GC9A01 Round Dispalys + Peak Meters A typical VU meter measures audio signals and displays them with a visual indicator. In the classic...
-
Commodore 64 1541-II 1581 Floppy Disk Drive C64 Power Supply Unit USB-C 5V 12V DIN connector 5.25
161 1 3 -
Easy to print simple stacking organizer with drawers
87 0 0 -
-
-
-
Modifying a Hotplate to a Reflow Solder Station
1134 1 6 -
MPL3115A2 Barometric Pressure, Altitude, and Temperature Sensor
636 0 1 -
-
Nintendo 64DD Replacement Shell
494 0 2 -
V2 Commodore AMIGA USB-C Power Sink Delivery High Efficiency Supply Triple Output 5V ±12V OLED display ATARI compatible shark 100W
1438 4 3