Arduino Memory Game

by 761202 in Circuits > Arduino

161 Views, 0 Favorites, 0 Comments

Arduino Memory Game

IMG_9364.jpg

This is an arduino memory game. It flashes a sequence of LEDs (starting at 1 and increasing the more you get it right) and you have the push the corresponding push buttons. If you get the sequence right, your score increases by 1. If you get the sequence wrong, you lose 1 life. You have 5 lives in total. Once you lose all your lives, the game is over.

I got the idea of making this game after seeing another instructable on a similar game. I added my own touches to the game and made my own code entirely from scratch to make a game I enjoyed playing. While making this game, I researched a lot of different coding techniques to try to make my code as effective as possible (such as continue and break statements) and did a lot of debugging to have it work without any errors.

Gather Materials

IMG_9369 (3).jpg

The materials required for this project are:

  • 7x 330 Ohms Resistors
  • 4x Push Buttons
  • Green LED
  • Yellow LED
  • Blue LED
  • Red LED
  • RGB LED (the one used in this project is a common anode)
  • 7 Segment Display (the one used in this project is a common anode)
  • Breadboard
  • Arduino Uno

Wiring

IMG_9367.jpg

The picture above is a picture of how the wiring should look when it's all completed. In more detail:


LEDs: The cathode of the LEDs is connected to ground through a 330 ohms resistor. The anode is connected to their respective pins on the arduino.

RGB LED: Since it is a common anode, the common leg is connected to power through a 330 ohms resistor. The red and green legs are connected to the arduino. In this project, only a red and green light is required so the blue leg doesn't need to be wired.

Push buttons: On one side, the push button are connected to ground. On the other, they are connected to the arduino pins.

7 segment display: The common legs of the 7 segment display are connected to power (because they are a common anodes) through 330 ohms resistors. The legs a, b, c, d, e, f, and g are connected to their respective pins on the arduino.


Make sure both sides of the breadboard have power and ground by adding the wires connecting each side of the breadboard

Code

You can download the code by clicking the link below. The code has comments to help you understand.

Video of Game Working

Attached is a video of the memory game working. It's sped up, so in real life the LEDs will flash slower then they do in the video.