Whac-A-Mole

by jpabla in Circuits > Arduino

90 Views, 0 Favorites, 0 Comments

Whac-A-Mole

Screen Shot 2024-02-13 at 11.36.59 AM.png
Whac-A-Mole with Arduino Uno

This simple circuit and program allows users to play a quick game of Whac-A-Mole.



As a beginner in the world of Arduino and circuitry, I was looking to utilize my creativity to stretch the limits of what is possible with just a few LEDs and a button. I especially wanted the breadboard to solely contain simple elements that any beginner can grasp. The real magic lies in how these elements are woven together in code to make a fun, interactive game based on the classic arcade game.


To inspire how I approached this project, I took advantage of Arduino's many example sketches and basic tutorials. The real-life Whac-A-Mole tests your reaction time to visual stimuli. To mimic this, I had a blue LED act as our "mole" and a button or photoresistor allow players to test their reactions. With some extra work, I was able to create a score board, text descriptions, and light sequences.


Follow along with your Arduinos to get started and try and make your own version! Each step will have a circuit diagram and code linked. Go into each file to get heavily documented code that explains how each step functions in depth.

Supplies

  • Arduino Uno
  • Breadboard
  • Four LEDs
  • Photoresistor/LDR
  • Button
  • 4 430 Ohm resistors
  • 1 10000 Ohm resistor

LED Setup

Screen Shot 2024-02-13 at 11.52.23 AM.png
IMG_8655.png

I started with the most basic step in setting up an LED attached to a bread board and Arduino.


Follow the circuit image above and upload the attached code to get a program that lights up the LED periodically.


Downloads

Button Setup

Screen Shot 2024-02-13 at 11.55.07 AM.png

In our next step, we begin to make our creation interactive. By adding in a button, we find a way for the player to provide input.


The circuit above and corresponding program linked allow for a user to push the button, triggering the LED to light up.

Downloads

Photoresistor Setup

Screen Shot 2024-02-13 at 11.58.28 AM.png
IMG_8658.png

In personally building this project, I found the button I was using to be a bit too sticky. Whac-a-Mole is a game of speed, so I opted for a different design. I used a photoresistor, otherwise known as an LDR to register input. A photoresistor measures the amount of light that is shone on it. Touching the LDR will interrupt light sources. We can register this change to simulate a button.


The circuit above and corresponding program achieve the same thing we saw in step 2, this time with an LDR.

Multiple LEDs

Screen Shot 2024-02-13 at 12.02.08 PM.png
Screen Shot 2024-02-13 at 12.02.15 PM.png
IMG_8664.png

In this step, we flesh out our circuit fully. All we have left to do is add on more LEDs, exactly how we did in earlier steps. From there, our program links those LEDs to our interactive input as we had in steps 2 and three. Our circuit is now complete! I included two versions here, one if you used the button and another if you stuck with the LDR.

Coding the Game

Finally, we put together all of our pieces and code up the game.


The file for my implementation is attached with heavy documentation to make sure you understand each part.


The general intuition as to how this game represents Whac-a-Mole is as follows: The blue light is our "mole." It flashes randomly in the same way the mole pops out of a hole randomly. As we press our button, we simulate whacking the hole with a sledgehammer. When the light is on and we press the button, it's like successfully hitting the mole with our hammer. Our red, yellow, and green LEDs work as our scoreboard to keep track of how many hits we've registered. Three hits in this case result in a win.


Some things to look out for:

  • A score counter initialized at the beginning and continuously updated.
  • If-Else statements to handle different scores and corresponding LEDs.
  • LEDs lighting up at different parts of the game as an opening sequence and celebratory end.
  • The use of print statements to give the player information on their progress.

Downloads

Future Steps

This implementation of this game is in its most basic stage. Given more time and resources, I would love to have a bigger breadboard with several blue LEDs to simulate multiple holes for a mole to come out of. Beyond that, looking for a better button or LDR that can allow a user to be a bit more rough would help with a more robust product.