Automated Ultrasonic Whack-A-Mole Game
by Balpreet Singh in Circuits > Arduino
29 Views, 1 Favorites, 0 Comments
Automated Ultrasonic Whack-A-Mole Game
This project is a homemade, arcade-style Whack-A-Mole game built using an Arduino Uno microcontroller. It is a fun, fast-paced electronic game designed to test your real-world reaction times using a combination of active sensors, physical buttons, target lights, sound effects, and a digital scoreboard. The system is programmed to act like a smart machine that automatically switches between two stages. It starts in an idle Standby Mode where a solid red light stays turned on to show the game is resting. In the background, an ultrasonic distance sensor acts like invisible radar, constantly casting sound waves into the room to see if a player is nearby. The exact moment you wave your hand close to the sensor, the red light shuts off, the buzzer plays a lively startup melody, and the Arduino instantly switches the system into active Gameplay Mode.
Once the game begins, the computer randomly chooses one of three target LEDs to light up. You have to quickly look at which light turned on and smash the matching tactile push button directly underneath it before a hidden background stopwatch timer runs out. To make the game exciting and competitive, it features a built-in speed booster mechanic. Every single time you hit the correct button, the code automatically slashes 300 milliseconds off your reaction window, causing the lights to flash faster and faster the higher your score climbs. Your live score is tracked in real-time from 0 up to 9 on a 7-segment digital display screen.
Because this specific scoreboard is a Common Anode hardware component, it operates using inverted logic, meaning it works completely backward from normal lights. Instead of sending positive power to turn the screen lines on, the code is programmed to pull the microcontroller pins down to Ground to light up each segment. If you press the wrong button, or if your hands are too slow and the background stopwatch timer expires, the game triggers an instant Game Over. It plays a low, sad buzzer tone, clears your score screen straight back to zero, and locks itself back into Standby Mode until the next player steps up. If you can survive the extreme speed increases and successfully press your way all the way to a maximum score of 9, a green victory light flashes rapidly to celebrate your win before the system safely resets back to the starting line.
Supplies
To build this project, you will need the following electronic components:
- 1x Arduino Uno Microcontroller (and a USB cable to power it)
- 1x Large Breadboard
- 1x HC-SR04 Ultrasonic Distance Sensor (to detect your hand)
- 1x 7-Segment Display (Common Cathode) (to show the live score)
- 3x Push Buttons (your game controllers)
- 5x LEDs (3 for the game targets, 1 Green for winning a round, 1 Red for losing/standby)
- 1x Piezo Buzzer (for game sound effects)
- Resistors: 10k ohm resistors for the buttons and 330 ohm resistors to protect the LEDs and display segments.
- Many Jumper Wires (to connect everything)
Gather Your Pieces
First, collect all the parts you need to build the game. You will need the Arduino computer board to act as the brain, a plastic breadboard to plug things into, and lots of colorful wires. For the game pieces, gather one ultrasonic sensor that works like eyes, three buttons to press, a sound buzzer, and five little LED light bulbs. Finally, grab one square number screen to show your score.
Give the Board Power
To make everything work, you have to share electricity across the board. Run a wire from the Arduino's power pin to the long red line on the side of the breadboard, and another wire to the long blue line. Because the breadboard has two different sides, make sure to use two wires to jump across the middle gap to connect the left side lines straight to the right side lines so the whole board has power.
Plug in the Sensor
Next, push the ultrasonic sensor down into the board. This part acts like radar to see your hand. Connect its power pin to the red line and its ground pin to the blue line. Then, use two jumper wires to link its middle data pins straight into pins 6 and 7 on the Arduino board so it can talk to the brain.
Add the Target Lights and Buttons
Now, line up your three buttons on the board so you can press them. Connect one side of each button to the power rail, and wire the other side to pins 2, 3, and 4 on the Arduino. Right above each button, poke a colored target light bulb into the board. Wire the long leg of each light to pins 8, 9, and 10, and put the short leg into the blue ground line using a small resistor.
Connect the Scoreboard Screen
Put your square scoreboard screen right in the middle of the board. Because this is a Common Anode screen, it shares one positive wire. Connect its middle pin with a resistor straight into the positive red power line. Then, run wires from its individual segment pins into pins A0, A1, A2, A3, A4, A5, and pin 5 on your Arduino so it can draw the numbers.
Complete Your Code and Upload the Code
The last step is to give the Arduino its code instructions. The code tells the computer to keep a red light on until the sensor sees your hand wave close by. Once your hand wakes up the game, the code plays a happy song and starts choosing target lights completely at random. It tells the scoreboard to count your points every time you hit the right button, and it shrinks the timer to make the game move faster and faster until you win!
Here is the link from where i get knowledge about some parts of my code:-
this is the tinkercad circuit link:
click this link to watch the video of testing:
Link to the video of game testing