Whack-a-Mole! (No Code!)

2,499

20

4

Hello World! I have returned from the non-posting abyss and I'm back at it again with another Instructable! Today, I'm going to explain to you how, using the only the fundamentals of circuitry, WITHOUT ANY CODE, to build Whack-a-Mole! You get 30 seconds to hit as many moles as you can. My Whack-a-Mole features 3 different speed levels which are controlled by a switch. Also, there is another game mode where if you hit the button when the light isn't on, you will lose a point! In this Instructable, I will explain how I made the basic whack-a-mole game (without the speeds and levels) using basics of digital logic, the different chips that are necessary to build Whack-a-Mole, and what truth tables are used for. I learned all of the content in this Instructable through an excellent summer program at Cooper Union and built this project in a team of three so be sure to check out their awesomeness here! I hope you get to take away at least one thing from this Instructable!

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: Quick Intro to Digital Electronics

In the world of circuits, the primary number system is base 2, more commonly known as binary, where the only values can be 1 or 0. The meaning of each 1 and 0 is arbitrary. Typically, 1 is assigned as true and 0 is assigned as false; however, since the meaning of each is decided by the creator of the program and is arbitrary, 0 can mean true and 1 false. In digital logic, we utilize the black/white nature of 1, when connected to a voltage, and 0, when connected to ground, to make circuits. We use them in two ways: combinational and sequential logic.

Combinational logic is when the output depends purely on the present inputs. As seen in the slide above, there are 6 basic logic functions in combinational logic (similar to the 4 basic functions in math: addition, subtraction, multiplication, and division). These 6 functions are AND, OR, NOR, NOT, NAND, and XOR. These functions can have any number of inputs (depends on the chip you use) but depending on which function you choose, the inputs will be compared differently. For example, using an AND logic gate, when both inputs are 1, the output will be 1; otherwise, the output will be zero (which is when both inputs are 0 or at least one is 0). In the OR gate, if at least one input is 1, then the output is 1; else, 0. For the XOR gate, if and only if one input is 1, then the output is 1, but if both inputs are 1 or both inputs are 0 then the output is 0. The NOT gate simply inverts any input, so if the input is 1 then the output is 0 and vice versa. NOR and NAND logic gates are simply AND and OR inverted respectively. In the slide above, the tables below each symbol for the functions are called truth tables and display the inputs and outputs of the chip. Columns A and B represent inputs and column Z represents the output. Now that you know the basics, let me explain to you another chip that uses combinational logic: a multiplexer (MUX). A MUX chip can have 8 inputs and one output and that one output is decided by the user through the address pins. Basically, the eight input pins are each assigned a number in binary from 0-8 (for example 000 is zero and 001 is one) and then the number that is inputted to the 3 address pins (again in binary) is compared to the binary numbers assigned to each pin. The one input of the 8 inputs pins that matches the address line number is then selected to be the singular output of the MUX. the Mux is the first diagram above. More info here.

Sequential logicis basically where the output depends on the current and the previous input. The chips used in sequential logic, since the output depends on the previous input, have some form of memory involved. Sequential logic typically deals with timing devices, memory, and random number generators. A 555 timer, which will be used extensively in Whack-a-Mole, is a sequential circuit which can have two modes: astable and monostable. An astable 555 timer continuously pulses a 1 (a square wave where the highs are 1 and the lows are 0) at a speed depending on the resistors and capacitors used by the creator. The square wave with the astable circuit is shown above. A monostable timer sends a high (1) for some time then turns off sending a continuous 0 until it's triggered again. More info on sequential logic here.

Now that you have this basic knowledge, let’s get into the parts needed for this project! (Btw if you have no idea what’s going on make sure to check the linked websites and here https://www.electronics-tutorials.ws/sequential/s... )

Step 2: Chips Chips and More CHIPS!

Parts

Since there isn’t any code involved, we are going to need a bunch of chips ranging from AND gates to up/down counters. Don’t worry if you never heard of any of these chips before. If you type their part number online, you will find a DATASHEET(extremely helpful) describing what the function of each pin is assigned to and what it does. I recommend buying 7-10 chips for each since sometimes they’re either defective or I guarantee you will break one by mistake (I’m speaking from a lot of experience of stepping on chips). Only get the 4xxx series since they run on the most standard voltages (around 5V). Here's a good website to buy all these chips.

Combinational Logic Chips:

AND (chip #) 4081

NOT 4069

OR 4071

Mux/DeMux 4051

4543 Driver for 7 segment displays

Sequential Logic Chips:

555 timer

D flip-flops 4013

Up/down counter 4029

Once you get the chips, you’ll just need to get the breadboards (I used 11 but I’ll describe a way to do it with 8), solid stranded wires, 8 LED arcade buttons (for 8 moles), andfour 7 segment displays, you’ll be good to go!

Other necessities:

Assorted resistors and capacitors

Wire Strippers (for the wires if not using jumper cables)

Tactile button (to start the game and to test the circuit in place of the arcade buttons)

Must debounce ALL buttons!! Look at the example above. If you don't debounce buttons, then when you press the button, instead of it being triggered once, it will be triggered multiple times!! Think about dropping a ball. It doesn't smoothly land; instead, it bounces a couple of times then stops. That's what button does and since we don't want that we use a bunch of resistors and capacitors to debounce a button.

Buzzer for game over

Optional:

3D printer for the moles and hammer

Proto-board to mount the 7 segment LEDs

Laser cutter for the mole stand

Step 3: Designing the Circuit

This game is divided into 3 core parts: a pseudo-random number generator (pRNG) for the moles, scoreboard, and countdown (and the speed/mode selector, but I'm only going to explain how to make basic whack-a-mole). Briefly, this is how it will work. Once you hit the start button, the pRNG will be generating one random mole at a time. When the player hits the button at the same time as the light, a pulse will be sent to the scoreboard making it count up by one. This will go on until the timer hits zero making the buzzer go off and freezing all mechanisms. Let’s start building the pRNG!

Step 4: Can Moles Really Be Random??

Since nothing is truly random, we will make something as close to random as we can, hence the prefix pseudo. For the timing of our pRNG (which will be fed into the clock pins of the D Flip-Flops), we will need to create an astable 555 timer firing at a speed of 1 second (or however fast you want the moles to appear). This website provides the capacitor and resistor values necessary to build this speed along with a circuit diagram. Make sure to test if it works first using an LED. The light should flash for turn on then turn off and the time between when the two times the LED lights up should be 1 second, not the time LED is on.

CHECK DATASHEETS!!!

SEARCH UP THE PART #

Once the astable timer works, build the pRNG following the diagram above. Connect the output of the astable timer to the clocks of the D flip-flops. The pRNG is made of 5 D flip-flops with an XOR to create the randomness. Each flip-flop stores one bit of information. So, the pseudo-random number generator will have 5 bits, which means it will generate 32 values; except, we don’t want 32 moles. Instead, we will take only 3 bits from the pRNG and feed those into the address pins of the 4051 Mux/DeMux. But first, follow the diagram above to build the pRNG. The 4013 chips have 2 D flip-flops on each chip: one on the left and one on the right. RESET, SET, and VSS connect to ground while VDD connects to power. Once you finish, make sure the pRNG works by connecting LEDs to each Q output (DATASHEET!). Sometimes you need to jump-start the pRNG by connecting any Q briefly to power.

To have only eight moles, this time the 4051 will act as Demultiplexer (the opposite of a MUX) where the one input is always connected to 1 (power) and the address pins will decide which of the eight output pins to have that 1 be sent to. So, connect a wire from 3 different Qs (3 different D flip flops) from the pRNG and put them into the address pins of the DeMux (E, VEE, GND connect to ground, VCC connect to power, any Y is an output, any S is an address pin, and Z is the first input). Put an LED (with a resistor) to each output and you will see the eight moles flashing every second (or whatever the speed is of your astable timer). Congrats you created the moles!

Step 5: It's the Final Countdown

For the countdown and scoreboard, we will be mainly using 4029 up/down counters which apparently can count in decimal as well as binary. In my original project I did something overly complicated by counting in binary but halfway through the project I realized I can count in decade (decimal) using these counters. CHECK THE DATASHEETS

First, for the countdown, you will need an astable timer to be connected to both clocks running at 1 second. Then once that works, get two 4029 chips and set them up connecting VDD to power; VSS, Binary/decade, up/down, and all the JAMs on one chip to ground. On the second chip, connect everything the same except connect Jam 1 and 2 to power the rest to ground. The first chip carry in pin is connected to ground. Carry out of the first chip is connected to the carry in pin of the second chip. Connect the present enable of both chips to a DEBOUNCED button which will act as a start button. To have the game stop, you will need some logic to stop the 555 timer. So, get some 4071 OR chips and compare all the Q outputs of the 4029 chips, so basically when it reaches 0, all the OR gate logic will output 0, which is the only time it will output 0. Take that output and place it into the reset pin of the 555 timer taking out the power wire that was there. Now you have the countdown!

Step 6: Scoreboard!

First, let’s deal with a way to register hitting the moles at the same time as the LED. To connect the buttons, solder wires to each pin that is sticking out of the button. There will be two pairs: one is connected to a gray box the and the other on the side of the gray box. The pair on the outside of the gray box is for the LED and the other is for the button. The mole lights up when a 1 is outputted to the LED. A DEBOUNCED button outputs a 1 when pressed (depending on how it’s wired). Since we have two 1’s when they’re hit at the same time, we can use an AND gate to output a 1 when both are hit. So, AND all the buttons and lights together. Then OR all of their outputs together so when at least one is hit together at the same time, there will be an output of 1 (you can compare more than two inputs by ORing the outputs). This output pulse will be fed into the clock of the scoreboard.

For the scoreboard, you do everything almost the same as the countdown. Two 4029 counter chips connect the same except all the JAMS are grounded, up/down is connected to power, and the clock is connected to the ORed output of all the buttons with LEDs. No astable timer is necessary and make sure to connect the same button from the countdown to this preset enable as well. Now you have the scoreboard!

To test each of these circuits you can use LEDS connected to each Q of the 4029 but each number will be in binary. To display it on a 7 segment LED, you need to 4543 driver. Latch disable, phase, and VDD connected to power. Blanking and vss connected to ground. To display the number of one chip, the A pin is connected to Q1, B to Q2, C to Q3, and D to Q4. Then using the datasheet of the 7 seg LED, connect the lowercase letters from the 4543 to their respective pins on the display. Repeat as necessary for each 4029 chip.

Step 8: Buzz Buzz Buzz

Now the buzzer is an active buzzer which works when voltage runs through it. So, you will need to create a monostable timer so that when the countdown reaches 0, it will buzz only once instead of staying on. Use this website with its circuit diagram and resistor values to decide how long you would like the buzzer to sound. Connect the power of the buzzer to the output of the timer. To trigger the sound, first invert (using a 4069 NOT chip) the output of the OR’ed 0’s of the countdown and take that output and it to connect the trigger pin. Now you have Whack-a-Mole!

Since my team had some time leftover we decided to add the extra speeds and the point deduction mode. If you would like to do that think about using some XOR gates and some other logic. It’s not overly complicated so you should be able to get it. If you know how to solder, get some protoboards and solder the score and countdown so you can see it easily when you play. To make the case get some wood, cut holes, and voila stand for the moles! I used a laser cutter, but do it any way you prefer. For the 3D printed moles, go online, search up a 3D mole, cut the body off, and print only the head and glue it on the button.

If you're having trouble, remember that's part of any circuit design. Literally, almost all my time was spent debugging this project. The design is the easy part, finding what's wrong when you build it is the challenge.

In the end, I enjoyed this project very much and hope you did too. I definitely learned a lot from doing this and should have too. Please feel free to post comments, questions, or suggestions! Thanks!

Participated in the
Game Life Contest

Recommendations

• Large Motors Class

13,130 Enrolled

4 Discussions

hello, can u show the schematic diagram for that project using circuit wizard or ISIS? please, thank you