Simon Says Memory Game (Arduino)
Repeat a growing sequence of lights and tones. A classic memory game with 4 LEDs, 4 buttons, and a buzzer.
Intermediate40 min
What you need
Wiring
Hover a pin or a wire to trace the connection.
Code
simon.ino
// Simon: repeat the growing light + tone sequence.
const int leds[4] = {2, 3, 4, 5};
const int btns[4] = {8, 9, 10, 11};
const int buzzer = 6;
const int notes[4] = {262, 330, 392, 523};
int seq[100];
int len = 0;
void flash(int i, int ms) {
digitalWrite(leds[i], HIGH);
tone(buzzer, notes[i], ms);
delay(ms);
digitalWrite(leds[i], LOW);
noTone(buzzer);
delay(150);
}
int waitForPress() {
while (true) {
for (int i = 0; i < 4; i++) {
if (digitalRead(btns[i]) == LOW) {
flash(i, 200);
while (digitalRead(btns[i]) == LOW) {} // wait for release
return i;
}
}
}
}
void setup() {
for (int i = 0; i < 4; i++) { pinMode(leds[i], OUTPUT); pinMode(btns[i], INPUT_PULLUP); }
pinMode(buzzer, OUTPUT);
randomSeed(analogRead(A0));
}
void loop() {
seq[len++] = random(4); // extend the sequence
for (int i = 0; i < len; i++) flash(seq[i], 400); // play it
for (int i = 0; i < len; i++) { // player repeats it
if (waitForPress() != seq[i]) { // wrong -> game over
for (int j = 0; j < 3; j++) { tone(buzzer, 150, 200); delay(300); }
len = 0; delay(1000); return; // restart
}
}
delay(800);
}
Steps
- Wire 4 LEDs on D2–D5 (each through 220Ω to GND) and 4 buttons on D8–D11 (other leg to GND).
- Wire the buzzer: + to D6, − to GND.
- Upload — watch the sequence, then press the buttons to repeat it.
- Each round adds one step. A wrong press buzzes and restarts.