Memory Game

by 982418 in Circuits > Arduino

14 Views, 0 Favorites, 0 Comments

Memory Game

Memory1 (1).jpg
Memory game.jpg

This project is an interactive Arduino-based memory game inspired by the classic game "Simon Says." It uses LEDs, buttons, a buzzer, and servo motors to create a fun and challenging experience. The player watches a random sequence of lights and sounds, then tries to repeat the pattern by pressing the correct buttons in the right order.

To make the game more engaging, we added sound effects using a piezo buzzer and physical feedback using two servo motors. When the player gets the pattern right, a green flag (servo) is raised. If the player makes a mistake, a red flag is raised and a “game over” sound plays. This game helps improve memory, focus, and reaction time, while also demonstrating how to combine electronic components and code logic in a creative way.

Supplies

Screenshot 2025-06-15 182852.png


  1. 5 buttons
  2. 4 LEDs
  3. 9 resistors
  4. 1 piezo buzzer
  5. 2 servo motors
  6. 1 Arduino Uno
  7. 1 breadboard
  8. Jumper wires

Screenshot 2025-06-15 182451.png

Description:

In this step, 5 push buttons are added across the breadboard. These will be used to trigger actions like turning on LEDs, playing sound, or moving the servos. The buttons are placed over the middle gap so each side can connect to a different row, making it easier to wire them up later.

What Was Added:

  1. 5 push buttons placed evenly across the breadboard’s center
  2. Spaced out to allow room for wires and resistors later


Screenshot 2025-06-15 183345.png

Description:

Now 4 LEDs are added to the lower part of the breadboard. These LEDs will light up when certain buttons are pressed. Each LED has a current-limiting resistor to prevent it from burning out. The LEDs are aligned so they match the buttons vertically for a clean layout.

What Was Added:

  1. 4 LEDs placed in line with the buttons
  2. 4 resistors connected to the cathode (negative leg) of each LED, then to ground
  3. Wires or gaps prepared for connection to Arduino output pins


Screenshot 2025-06-15 183430.png

Description:

Here, more resistors are added for the buttons. These are likely pull-down resistors, which make sure the Arduino reads a LOW signal when the buttons are not pressed. The circuit now includes all 9 resistors needed.

What Was Added:

  1. 5 resistors connected to the buttons (1 per button)
  2. All 9 resistors are now on the breadboard (4 for LEDs + 5 for buttons)
  3. Buttons are almost ready to be wired to Arduino pins

Screenshot 2025-06-15 183532.png

Description:

The piezo buzzer is now added to the breadboard. It will be used to play sounds when a button is pressed or when the servos move. Some initial wiring is also done here to connect components to the correct rows.

What Was Added:

  1. Piezo buzzer placed near the right or bottom of the breadboard
  2. Wires begin connecting buttons and LEDs to nearby rows
  3. Preparing the board for connection to the Arduino

Screenshot 2025-06-15 183622.png

Description:

Now the Arduino Uno is placed beside the breadboard and connected with jumper wires. The circuit is taking shape, but no servos have been added yet — only LEDs, buttons, the buzzer, and resistors are connected at this stage.

What Was Added:

  1. Arduino connected to breadboard using jumper wires
  2. Wires going from buttons and LEDs to digital pins
  3. Power and ground lines from Arduino to the breadboard
  4. Still no servo motors yet


Screenshot 2025-06-15 183921.png

Description:

All wiring between components is now complete. The piezo, buttons, and LEDs are fully connected. This is the last step in the physical build before uploading the code to the Arduino.

What Was Added:

  1. Final jumper wires between inputs/outputs and Arduino
  2. All 5 buttons, 4 LEDs, piezo buzzer, and 9 resistors are wired
  3. Power and ground confirmed
  4. Ready for coding
  5. No servo motors included in the physical build

Screenshot 2025-06-15 184002.png

Description:

This is the final hardware setup before testing. Everything except the servo motors is included on the breadboard. This step involves checking for errors, cleaning up wiring, and preparing for code upload.

What Was Added:

  1. Final check of all wiring
  2. Everything is ready to be tested
  3. Still no servo motors added

Screenshot 2025-06-15 174411.png

Description:

This is the final digital circuit design created in Tinkercad. It includes all components, including two servo motors, which are not shown in the physical breadboard yet. This diagram shows how everything should be connected: the buttons, LEDs, piezo buzzer, resistors, jumper wires, and servos.

What Was Added (Only in this digital diagram):

  1. 5 buttons connected to digital input pins
  2. 4 LEDs connected to output pins with resistors
  3. 9 total resistors (4 for LEDs, 5 for buttons)
  4. 1 piezo buzzer connected to a digital pin
  5. 2 servo motors connected to PWM pins (e.g., 9, 7)
  6. Jumper wires, power, and ground connections


Code Description for Arduino Memory Game

This code creates a “Simon Says”-style memory game using 5 buttons, 4 LEDs, 1 buzzer, and 2 servo motors. The game shows a pattern of lights and sounds, and the player has to repeat the same pattern by pressing the matching buttons. If the player is right, they move to the next level. If they’re wrong, the game resets.

🔧 Main Components the Code Uses:

  1. 4 LEDs (Green, Yellow, Blue, Red) – light up in the pattern
  2. 5 Buttons – 1 to start the game, and 4 for repeating the pattern
  3. 1 Piezo Buzzer – plays different tones for each LED and a sound when you lose
  4. 2 Servo Motors
  5. One green servo moves when the answer is correct (a "flag up" motion)
  6. One red servo moves when the answer is wrong

🧠 How the Code Works:

🔹 Setup (in setup()):

  1. Sets all pins for LEDs, buttons, and buzzer
  2. Turns off all LEDs and resets all servos to angle 0
  3. Attaches the two servo motors to their pins
  4. Uses randomSeed() to make the LED pattern different every time

🔹 Loop (in loop()):

  1. Waits for the start button to be pressed
  2. Once pressed, sets CURRENT_LEVEL to 1 to begin the game

🔹 Pattern Display (generate_led_sequence()):

  1. Picks a random LED to add to the sequence
  2. Lights up and plays a sound for each LED in the pattern
  3. Uses different tones for each LED color using the buzzer

🔹 Player Input (read_btn_sequence()):

  1. Waits for the player to press buttons to match the LED sequence
  2. Checks if the button pressed matches the pattern
  3. If the pattern is correct:
  4. Moves the correct servo (green flag goes up)
  5. Increases the level and makes the game faster
  6. If the pattern is wrong:
  7. Lights up all LEDs
  8. Plays a “game over” sound
  9. Moves the incorrect servo (red flag goes up)
  10. Resets the level and speed

Extra Details:

  1. Uses tone() to play different sounds for each LED
  2. Uses a small delay (btn_delay) to debounce button presses
  3. play_melody() is used to play a mini song when the player loses
  4. The sequence is stored in an array called sequence[]
  5. The difficulty increases each round by making the pattern faster

🎮 Example Game Flow:

  1. Press the Start button
  2. The Arduino shows a sequence like: Red → Blue
  3. You press the Red and Blue buttons in the same order
  4. If correct:
  5. Green LED flashes
  6. Buzzer plays a sound
  7. Servo with green flag moves
  8. Level increases
  9. If incorrect:
  10. All LEDs turn on
  11. “Lose” melody plays
  12. Red flag servo moves
  13. Game resets


Components

Screenshot 2025-06-15 192436.png

https://docs.google.com/document/d/13Hjr77UcTZLzBgj4--nssp-z8rCD7GPAIyPCLG5b3_0/edit?usp=sharing

Copy and paste this link in google to see where to buy the components.