Memory game
Required items
-5v regulator kit (unneeded for Uno, required for Atmega328 chip only builds)
-5x7cm Pref Board (Optional)
-LEDx4(Red, Green, Blue and Yellow)
-1k ohm resistors x4
-Uno Clock Kit (unneeded for Uno, required for Atmega328 chip only builds)
Setting up the buttons
Stradle the buttons across the middle of the breadboard. By doing this, we will connect both sides of the breadboard for additional room and ease of use. Ensure that the legs that are connected( the two that create an open flow) are perpendicular to the power rails. You can test this by applying power to the button, connecting a 220 ohm resistor to a led and grounding the circuit. If the led lights up, you have placed the button correctly.
The buttons are connected to digital inputs 2-5. If you are using the AtMega328 micro-controller, the pins are the following:
Digital Input 2 = AtMega pin 4
Digital Input 3= AtMega pin 5
Digital Input 4= AtMega pin 6
Digital Input 5= AtMega pin 11
On the open pin, in-line with the digital input, ground the button with a 1k ohm resistor. This is known as a pull-down resistor. The resistor ensure that when the button isn't pressed, the circuit reads an input of 0, thus limiting false inputs. Connect the other side of the button to the power rail. When the button is pressed, the circuit for the digital input is complete and lets the game know when you have picked a color. Now we can move on to the LEDs.
Setting up the leds
A LED has a long leg and a short leg. The long leg is called the anode and the short one is the cathode. They are polarity sensitive. This means if you run negative power through a LED, you will ruin it. Always ensure that positive is connected to the anode (the long leg) and negative is connected to the cathode (short leg).
For our project, the digital pins will be our positive and we will connect the LED to ground using a 220 ohm resistor. The resistor limits the current that passes through the LED so it doesn't burn out. To make things easy, we will be connecting the LED in the same order we connected the buttons starting with digital pin 7 and ending with digital pin 10. The inputs are connected to the anode of each LED. If you are using the AtMega328 chip, here are the pin equivalent:
Digital Input 7 = AtMega pin 13
Digital Input 8 = AtMega pin 14
Digital Input 9 = AtMega pin 15
Digital Input 10= AtMega pin 16
Next we will be placing the 220 ohm resistors. Connect one end in line with the cathode of the LED and the other directly to the ground rail of the breadboard. And we are done! Next up: the buzzer.
Connecting the buzzer
The buzzer is really simple. All we have to do is connect the digital pin to the positive and the negative to the negative rail on the breadboard. We will be using digital pin 12, which is AtMega pin 18.
5v regulator and 16mhz crystal
If you are using the AtMega chip, you will need to step down the 9v battery to the 5v operating range of the chip. This circuit is fairly simple as well. If you want to test your circuit, i suggest buying a spare LED or two. Its better to ruin a 30 cent LED than a 3 buck micro controller. The L7805 regulator has 3 legs: the left is for the input voltage or Vin, the middle leg is for ground and the right leg is for the output voltage or Vout. The 9v battery is connected to the first and second leg. The rest of the circuit shares the ground line as well at the AtMega chip using pins 8 and 22. Vout is connected to the VCC pins of the AtMega (pins 7 and 20). Lastly, add the two 47µF capacitors. One capacitor will connect between Vin and Ground and the other will connect between Vout and ground.
In order to use the AtMega without complicated installing and placement of drivers and files, we will need to add an external 16mHz crystal. The crystal needs to be placed on the clock pins 9 and 10. Being right next to ground comes in handy when we install the 2 20pF capacitors. One capacitor will connect pin 9 to ground and the other will connect pin 10 to ground.
The Code
If you are using the Uno board (or any other variation) you can download the code from the link here and install it using the Arduino IDE. If you are using an AtMega, either purchase one with the code pre-programmed or use a serial to usb adapter or Uno board/ any other microcontroller. Remember, to get a chip pre-programmed you'll need to send a quote request to mrogers@quailstudio1.com. The cost will depend on the ammount of work needed (compiling and uploading for this tutorial will cost $0.25, developing and checking the code for bugs will be based on the complexity of the other project).
Final product
Here is a picture and video of what I put together to make this tutorial. You can buy a pref board to make everything stable and take it anywhere you go!
.png)














