Build it step by step
0 of 8 doneTest one LED
Wire the red LED with its resistor to D2 and run a one-line blink.
Add the other three LEDs
Same pattern on D3, D4 and D5.
Wire the four buttons
Each between a pin and GND.
Add the buzzer
Between D10 and GND.
Upload the sketch
You should see a start-up sweep.
Play three rounds
Check the order and the sounds.
Try a wrong press
Check the game-over flash.
Mount it on a card or box
Match each button to its LED.
How do you build a simon-style memory game?
Four coloured LEDs flash a growing pattern that you repeat on four buttons, with a different beep for each colour. You need Arduino Uno R3, LED 5 mm red, LED 5 mm green, LED 5 mm blue, LED 5 mm yellow, Tactile push button 6 mm × 4, Passive buzzer, Resistor 220 Ω × 4, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm). It takes 8 steps and about 120 minutes.
- Level
- Beginner
- Time
- About 120 min
- Parts
- 10
Parts list
- Development BoardsBuyArduino Uno R3 × 1
- SemiconductorsBuyLED 5 mm red × 1
- SemiconductorsBuyLED 5 mm green × 1
- OptoelectronicsBuyLED 5 mm blue × 1
- SemiconductorsBuyLED 5 mm yellow × 1
- SwitchesBuy
- Motors & ActuatorsBuyPassive buzzer × 1
- PassivesBuyResistor 220 Ω × 4
- PrototypingBuy
- PrototypingBuy
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| Red LED plus | Uno D2 through a 220 ohm resistor, minus to GND | Colour 1 |
| Green LED plus | Uno D3 through a 220 ohm resistor, minus to GND | Colour 2 |
| Blue LED plus | Uno D4 through a 220 ohm resistor, minus to GND | Colour 3 |
| Yellow LED plus | Uno D5 through a 220 ohm resistor, minus to GND | Colour 4 |
| Four buttons, one side each | Uno D6, D7, D8, D9, other side to GND | Internal pull-ups, pressed reads LOW |
| Passive buzzer plus and minus | Uno D10 and GND | Different tone per colour |
| Uno A0 | Leave unconnected | Floating pin gives a random seed |
Code
The Uno keeps the pattern in an array. Each round it adds one random colour, replays the whole pattern with a different tone per LED, then waits for you to press the same buttons in order. A wrong press, or no press for five seconds, plays a low tone and flashes all LEDs, and the game starts again from one colour. The playback speeds up as the pattern grows, and a complete 24-step run counts as a win. Buttons use the Uno's internal pull-ups, so each one connects a pin to ground and a press reads LOW. The random seed comes from the unconnected A0 pin, so each game is different. Each LED has its own 220 ohm resistor, which keeps the current near 10 mA, well inside the Uno's limit. Use the passive buzzer, which makes the different notes. An active buzzer would make only one sound. Setup: Arduino IDE, board "Arduino Uno". No extra libraries are needed.
Runs on a virtual Arduino Uno in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).
const uint8_t LED[4] = {2, 3, 4, 5};
const uint8_t BTN[4] = {6, 7, 8, 9};
const uint8_t BUZ = 10;
const int TONE_HZ[4] = {262, 330, 392, 523}; // C, E, G, high C
const uint8_t MAX_LEN = 24;
uint8_t seq[MAX_LEN];
uint8_t len = 0;
void flash(uint8_t i, unsigned int ms) {
digitalWrite(LED[i], HIGH);
tone(BUZ, TONE_HZ[i]);
delay(ms);
noTone(BUZ);
digitalWrite(LED[i], LOW);
delay(80);
}
// Returns the button number that was pressed, or -1 after the timeout.
int waitPress(unsigned long timeoutMs) {
unsigned long t0 = millis();
while (millis() - t0 < timeoutMs) {
for (uint8_t i = 0; i < 4; i++) {
if (digitalRead(BTN[i]) == LOW) {
digitalWrite(LED[i], HIGH);
tone(BUZ, TONE_HZ[i]);
while (digitalRead(BTN[i]) == LOW) { } // hold the light and tone until release
noTone(BUZ);
digitalWrite(LED[i], LOW);
delay(40); // simple debounce
return i;
}
}
}
return -1;
}
void gameOver() {
tone(BUZ, 120, 600);
for (uint8_t k = 0; k < 3; k++) {
for (uint8_t i = 0; i < 4; i++) digitalWrite(LED[i], HIGH);
delay(200);
for (uint8_t i = 0; i < 4; i++) digitalWrite(LED[i], LOW);
delay(200);
}
len = 0;
delay(1000);
}
void setup() {
for (uint8_t i = 0; i < 4; i++) {
pinMode(LED[i], OUTPUT);
pinMode(BTN[i], INPUT_PULLUP);
}
pinMode(BUZ, OUTPUT);
randomSeed(analogRead(A0));
// Start-up sweep so you know it is alive
for (uint8_t i = 0; i < 4; i++) flash(i, 120);
delay(500);
}
void loop() {
if (len < MAX_LEN) seq[len++] = random(4);
unsigned int ms = max(120, 420 - len * 14); // gets faster as the pattern grows
delay(400);
for (uint8_t k = 0; k < len; k++) flash(seq[k], ms);
for (uint8_t k = 0; k < len; k++) {
int p = waitPress(5000); // five seconds to answer
if (p != seq[k]) { gameOver(); return; }
}
if (len == MAX_LEN) { // you won: celebrate and restart
for (uint8_t i = 0; i < 4; i++) flash(i, 100);
for (uint8_t i = 0; i < 4; i++) flash(3 - i, 100);
len = 0;
delay(1000);
} else {
delay(500);
}
}Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| Power on | LEDs sweep once with four notes |
| Round 1 | One LED flashes, then you repeat it |
| Press the wrong button | Low tone, all LEDs flash, restart |
| Wait 5 seconds without pressing | Same game-over |
| Play to step 6 | Playback is noticeably faster |
If it does not work
Nothing happens
Check the USB cable and board selection.
A button is always pressed
The wire goes to the wrong pin or the button is rotated.
No sound
Check the buzzer polarity and that it is a passive type.
LED dim or off
LED the wrong way round, or a missing resistor.
Same pattern every game
A0 is connected to something, leave it floating.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the simon-style memory game?
Arduino Uno R3, LED 5 mm red, LED 5 mm green, LED 5 mm blue, LED 5 mm yellow, Tactile push button 6 mm × 4, Passive buzzer, Resistor 220 Ω × 4, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm).
How long does the simon-style memory game take to build?
About 120 minutes for a beginner maker, in 8 steps.
How do I know the simon-style memory game works?
Power on: LEDs sweep once with four notes. Round 1: One LED flashes, then you repeat it. Press the wrong button: Low tone, all LEDs flash, restart.
Nothing happens: what should I check?
Check the USB cable and board selection.
A button is always pressed: what should I check?
The wire goes to the wrong pin or the button is rotated.
No sound: what should I check?
Check the buzzer polarity and that it is a passive type.
LED dim or off: what should I check?
LED the wrong way round, or a missing resistor.
