Simon Says Memory Game using Arduino Uno – Complete Guide with Code

Simon Says Memory Game with Arduino Uno – Complete Guide with Code | MakeMindz

Simon Says Memory Game with Arduino Uno

4 colour-coded LEDs, musical tones, progressive difficulty, and button debouncing — all simulated in Wokwi.

· By MakeMindz

4 LEDs + 4 Buttons Piezo Buzzer ~50 min Intermediate

🔬 No hardware needed — run the full game in your browser

▶ Open Wokwi Simulation
// 00

What You'll Build

Arduino flashes a growing LED sequence — repeat it exactly or it's game over!

🎲

Random Sequences

Unpredictable patterns via random(0,4)

🔘

Debouncing

50ms millis() filter prevents false triggers

🎵

Musical Tones

C, E, G, B — a real C major arpeggio

📈

Difficulty

Speed increases every 5 rounds

⏱️

Timeout

5-second response window per press

🧠

State Logic

Boolean flags manage game flow

// 02

Parts List

All available as virtual parts in Wokwi — or build on a real breadboard!

01

Arduino UNO

Runs game logic — generates sequences, reads buttons, drives outputs

02

4× LEDs (Red / Green / Blue / Yellow)

One per colour — flash to show the sequence the player must repeat

03

4× 220Ω Resistors

One per LED — limits current to protect LEDs and Arduino pins

04

4× Push Buttons

Colour-matched to LEDs — player presses to repeat the sequence

05

Piezo Buzzer

Plays a unique musical tone for each colour during playback and input

06

Breadboard + Wires

For physical builds — all connections also work in Wokwi digitally

// 03

Wiring

Pin configuration for all components

Component Pin Notes
LED Red2220Ω series
LED Green3220Ω series
LED Blue4220Ω series
LED Yellow5220Ω series
Btn Red6INPUT_PULLUP
Btn Green7INPUT_PULLUP
Btn Blue8INPUT_PULLUP
Btn Yellow9INPUT_PULLUP
🔊 Buzzer10(+) to pin, (−) GND
💡 INPUT_PULLUP The Arduino internally connects the pin to 5V through a resistor. Button = LOW when pressed, HIGH when released. No external resistor needed!

How to load the circuit in Wokwi

1

New Project

Go to wokwi.com → New Project → Arduino UNO. Log in with Google to save your project.

2

Paste diagram.json

Click the diagram.json tab → select all → delete → paste the JSON below → Ctrl+S

diagram.json — paste into Wokwi
{
  "version": 1,
  "author": "Claude",
  "editor": "wokwi",
  "parts": [
    { "type": "wokwi-arduino-uno", "id": "uno", "top": 0, "left": 0, "attrs": {} },
    { "type": "wokwi-led", "id": "led1", "top": -86.4,  "left": -134.6, "attrs": { "color": "red" } },
    { "type": "wokwi-led", "id": "led2", "top": -86.4,  "left": -48.2,  "attrs": { "color": "green" } },
    { "type": "wokwi-led", "id": "led3", "top": -86.4,  "left": 38.2,   "attrs": { "color": "blue" } },
    { "type": "wokwi-led", "id": "led4", "top": -86.4,  "left": 124.6,  "attrs": { "color": "yellow" } },
    { "type": "wokwi-resistor", "id": "r1", "top": -28.8, "left": -124.8, "attrs": { "value": "220" } },
    { "type": "wokwi-resistor", "id": "r2", "top": -28.8, "left": -38.4,  "attrs": { "value": "220" } },
    { "type": "wokwi-resistor", "id": "r3", "top": -28.8, "left": 48,     "attrs": { "value": "220" } },
    { "type": "wokwi-resistor", "id": "r4", "top": -28.8, "left": 134.4,  "attrs": { "value": "220" } },
    { "type": "wokwi-pushbutton", "id": "btn1", "top": 179,   "left": -144,   "attrs": { "color": "red" } },
    { "type": "wokwi-pushbutton", "id": "btn2", "top": 182.4, "left": -57.6,  "attrs": { "color": "green" } },
    { "type": "wokwi-pushbutton", "id": "btn3", "top": 182.4, "left": 28.8,   "attrs": { "color": "blue" } },
    { "type": "wokwi-pushbutton", "id": "btn4", "top": 182.4, "left": 115.2,  "attrs": { "color": "yellow" } },
    { "type": "wokwi-buzzer", "id": "bz1", "top": 249.6, "left": 268.2, "attrs": {} }
  ],
  "connections": [
    [ "led1:A", "r1:1",      "green", ["v0"] ],
    [ "r1:2",  "uno:2",     "green", ["v0"] ],
    [ "led1:C", "uno:GND.1", "black", ["v0"] ],
    [ "led2:A", "r2:1",      "green", ["v0"] ],
    [ "r2:2",  "uno:3",     "green", ["v0"] ],
    [ "led2:C", "uno:GND.1", "black", ["v0"] ],
    [ "led3:A", "r3:1",      "green", ["v0"] ],
    [ "r3:2",  "uno:4",     "green", ["v0"] ],
    [ "led3:C", "uno:GND.1", "black", ["v0"] ],
    [ "led4:A", "r4:1",      "green", ["v0"] ],
    [ "r4:2",  "uno:5",     "green", ["v0"] ],
    [ "led4:C", "uno:GND.1", "black", ["v0"] ],
    [ "btn1:1.l", "uno:6",     "blue",  ["v0"] ],
    [ "btn1:2.l", "uno:GND.2", "black", ["v0"] ],
    [ "btn2:1.l", "uno:7",     "blue",  ["v0"] ],
    [ "btn2:2.l", "uno:GND.2", "black", ["v0"] ],
    [ "btn3:1.l", "uno:8",     "blue",  ["v0"] ],
    [ "btn3:2.l", "uno:GND.2", "black", ["v0"] ],
    [ "btn4:1.l", "uno:9",     "blue",  ["v0"] ],
    [ "btn4:2.l", "uno:GND.2", "black", ["v0"] ],
    [ "bz1:1",   "uno:10",    "green", ["v0"] ],
    [ "bz1:2",   "uno:GND.3", "black", ["v0"] ]
  ],
  "dependencies": {}
}
⚠️ Important Copy the full JSON including the opening and closing { } braces or Wokwi will throw a parse error.
3

Paste sketch.ino

Switch to the sketch.ino tab and paste the full Arduino code. Hit ▶ to run!

// 04

The Code

Key sections explained

① Pin Arrays & Game State

sketch.ino — definitions
// Arrays let us loop over all 4 colours
const int LED_PINS[]    = {2, 3, 4, 5};
const int BUTTON_PINS[] = {6, 7, 8, 9};
const int BUZZER_PIN    = 10;

// C major arpeggio: C, E, G, B
const int TONES[] = {262, 330, 392, 494};

const int MAX_SEQUENCE   = 50;
const int INITIAL_SPEED  = 500;
const int SPEED_DECREMENT = 20;
const int MIN_SPEED       = 200;

int  sequence[MAX_SEQUENCE];
int  sequenceLength = 0;
int  currentSpeed   = INITIAL_SPEED;
bool gameActive     = false;

② Button Debounce Logic

sketch.ino — waitForButtonPress()
int waitForButtonPress() {
  unsigned long startTime = millis();

  while (millis() - startTime < 5000) {
    for (int i = 0; i < 4; i++) {
      int reading = digitalRead(BUTTON_PINS[i]);

      if (reading != lastButtonState[i])
        lastDebounceTime[i] = millis();

      if ((millis()-lastDebounceTime[i]) > 50) {
        if (reading == LOW) {
          while (digitalRead(BUTTON_PINS[i])==LOW)
            delay(10);      // wait for release
          return i;
        }
      }
      lastButtonState[i] = reading;
    }
  }
  return -1;  // timeout
}

③ Difficulty Ramp

sketch.ino — level up every 5 rounds
if (sequenceLength % 5 == 0) {
  level++;
  currentSpeed = max(MIN_SPEED,
    currentSpeed - SPEED_DECREMENT);
  levelUpAnimation();
}
// 05

Key Concepts

Programming patterns taught by this project

A — Arrays

Storing the Sequence

Two arrays hold the generated sequence and pin numbers. A single for loop replaces writing the same code 4 times — digitalWrite(LED_PINS[i], HIGH) works for any colour just by changing i.

B — randomSeed()

True Randomness

Without seeding, random() produces the same sequence every reset. randomSeed(analogRead(A0)) uses electrical noise on an unconnected pin — different every time, just like real random number generators in embedded systems.

C — Boolean Flags

State Machine Design

The gameActive boolean controls which code branch runs. This is a fundamental pattern in robotics — the device behaves differently based on its current state.

D — millis() Timeout

Non-Blocking Timer

millis() - startTime < 5000 is non-blocking — unlike delay(5000), the code keeps polling all 4 buttons inside the timeout window, so no press is ever missed.

// 06

Sound System

Each colour plays a real note — together they form a C major arpeggio!

Red
262 Hz
Note: C (Middle C)
Green
330 Hz
Note: E
Blue
392 Hz
Note: G
Yellow
494 Hz
Note: B
EventFreqPattern
✅ Correct800 Hz3× short beeps
🎉 Level Up659 HzAll LEDs flash
❌ Game Over200 Hz3× slow pulses
🎮 WelcomeC→BAscending arpeggio
// 09

Quick Quiz

Answer these before submitting your project!

Q1 Why does the code use randomSeed(analogRead(A0)) in setup()?
An unconnected analog pin picks up random electrical noise — this makes each game unique!
Q2 What does button debouncing prevent?
Mechanical button contacts bounce rapidly on press. The 50ms filter ignores any changes shorter than that window.
Q3 When a button using INPUT_PULLUP is pressed, what does digitalRead() return?
INPUT_PULLUP holds the pin HIGH by default. Pressing the button connects it to GND, pulling it LOW — so you check for LOW in code.
Q4 Which musical notes correspond to the four colours?
262 Hz (C), 330 Hz (E), 392 Hz (G), 494 Hz (B) — a C major 7th arpeggio. That's why the game sounds pleasant!
Q5 How does the game's difficulty increase over time?
Speed ramps from 500ms down to 200ms (never faster), AND the sequence gets one step longer each round — double difficulty!
Simon Says Memory Game · Arduino + Wokwi
makemindz.com

Comments

try for free