Build it step by step
0 of 7 doneTest each button and LED
Light each LED when its button is pressed.
Show the score
Count up on the TM1637.
Add the random mole
Light one button at a time.
Add the timer
Shrinking window.
Add sounds
Hit and miss tracks.
Add game over
Flash all buttons after three misses.
Build the box
Five holes and a display window.
How do you build a whack-a-mole arcade game?
Five lit arcade buttons pop on at random and you hit them before they go out, faster each round. You need Arduino Nano, Push button 16 mm metal (momentary, LED) × 5, TM1637 4-digit display, DFPlayer Mini MP3 module, Speaker 8 Ω 0.5 W, SanDisk microSD card 32 GB (A1, Class 10) and Resistor 1 kΩ. It takes 7 steps and about 150 minutes.
- Level
- Intermediate
- Time
- About 150 min
- Parts
- 7
Parts list
- Development BoardsBuyArduino Nano × 1
- SwitchesArcade LED buttons work too
- DisplaysBuy
- InterfacesBuy
- Motors & ActuatorsBuy
- SBC AccessoriesBuy
- PassivesBuyResistor 1 kΩ × 1
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| Button LEDs | Nano D2 to D6, each through 220 Ω | Light each button |
| Buttons | Nano A0 to A4 to ground (internal pull-ups) | Hit inputs |
| TM1637 CLK and DIO | Nano D7 and D8 | Score display |
| DFPlayer RX | Nano D11 through 1 kΩ | Sound commands |
| DFPlayer TX | Nano D10 | Status |
| DFPlayer SPK pins | 8 Ω speaker | Sound |
| All VCC and GND | Nano 5V and GND | Power from USB |
Code
Each round lights one random button and gives you a shrinking window to press it; hits shorten the window by 40 ms down to a floor of 350 ms, and three misses end the game. Put two short sounds on the DFPlayer's microSD card named 0001.mp3 for a hit and 0002.mp3 for a miss. The 1 kΩ in the DFPlayer RX line stops the Nano's 5 V signal from overdriving it. Arduino IDE, board "Arduino Nano" (try the Old Bootloader option if the upload fails). Keep the sound at a comfortable level for children, and use a box with rounded corners.
Runs on a virtual Arduino Nano in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).
// Whack-a-mole: hit the lit button before time runs out. Libraries: TM1637Display, DFRobotDFPlayerMini.
#include <TM1637Display.h>
#include <SoftwareSerial.h>
#include <DFRobotDFPlayerMini.h>
const int LED[5] = {2, 3, 4, 5, 6};
const int BTN[5] = {A0, A1, A2, A3, A4};
TM1637Display disp(7, 8);
SoftwareSerial sw(10, 11);
DFRobotDFPlayerMini dfp;
int score = 0, misses = 0, window = 1500;
void setup() {
for (int i = 0; i < 5; i++) { pinMode(LED[i], OUTPUT); pinMode(BTN[i], INPUT_PULLUP); }
disp.setBrightness(5);
sw.begin(9600);
if (dfp.begin(sw)) dfp.volume(15);
randomSeed(analogRead(A5));
disp.showNumberDec(0);
}
void loop() {
int m = random(5);
digitalWrite(LED[m], HIGH);
unsigned long start = millis();
bool hit = false;
while (millis() - start < (unsigned long)window) {
if (digitalRead(BTN[m]) == LOW) { hit = true; break; }
}
digitalWrite(LED[m], LOW);
if (hit) { score++; window = max(350, window - 40); dfp.play(1); }
else { misses++; dfp.play(2); }
disp.showNumberDec(score);
if (misses >= 3) { // game over: flash every button
for (int k = 0; k < 4; k++) {
for (int i = 0; i < 5; i++) digitalWrite(LED[i], HIGH);
delay(250);
for (int i = 0; i < 5; i++) digitalWrite(LED[i], LOW);
delay(250);
}
score = 0; misses = 0; window = 1500; disp.showNumberDec(0);
}
delay(random(300, 900));
}Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| Hit in time | Score goes up and the window shortens |
| Miss | Miss sound plays |
| Three misses | All buttons flash and the game resets |
| Sound | Clear and not too loud |
If it does not work
No sound
Check the file names on the card and the RX resistor.
Buttons stuck
Check the ground wires.
Display blank
Check CLK and DIO order.
Game too fast
Raise the starting window.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the whack-a-mole arcade game?
Arduino Nano, Push button 16 mm metal (momentary, LED) × 5, TM1637 4-digit display, DFPlayer Mini MP3 module, Speaker 8 Ω 0.5 W, SanDisk microSD card 32 GB (A1, Class 10) and Resistor 1 kΩ. Push button 16 mm metal (momentary, LED) × 5: Arcade LED buttons work too.
How long does the whack-a-mole arcade game take to build?
About 150 minutes for a intermediate maker, in 7 steps.
How do I know the whack-a-mole arcade game works?
Hit in time: Score goes up and the window shortens. Miss: Miss sound plays. Three misses: All buttons flash and the game resets.
No sound: what should I check?
Check the file names on the card and the RX resistor.
Buttons stuck: what should I check?
Check the ground wires.
Display blank: what should I check?
Check CLK and DIO order.
Game too fast: what should I check?
Raise the starting window.
