It remembers the pattern and checks your presses.
Arduino
The brain
sequence compare with input
Watch a growing LED sequence, then repeat it with matching buttons.

Pin connections
| Part 1 | Part 2 | |
|---|---|---|
Arduino pin 2 | → | Red button pin 1 |
Red button pin 2 | → | Arduino GND |
Arduino pin 3 | → | Green button pin 1 |
Green button pin 2 | → | Arduino GND |
Arduino pin 4 | → | Yellow button pin 1 |
Yellow button pin 2 | → | Arduino GND |
Arduino pin 5 | → | Blue button pin 1 |
Blue button pin 2 | → | Arduino GND |
Arduino pin 8 | → | Red resistor pin 2 |
Red resistor pin 1 | → | Red LED anode (+) |
Red LED cathode (-) | → | Arduino GND |
Arduino pin 9 | → | Green resistor pin 2 |
Green resistor pin 1 | → | Green LED anode (+) |
Green LED cathode (-) | → | Arduino GND |
Arduino pin 10 | → | Yellow resistor pin 2 |
Yellow resistor pin 1 | → | Yellow LED anode (+) |
Yellow LED cathode (-) | → | Arduino GND |
Arduino pin 11 | → | Blue resistor pin 2 |
Blue resistor pin 1 | → | Blue LED anode (+) |
Blue LED cathode (-) | → | Arduino GND |
Let's test your memory!
Watch the colors flash, then copy them back — one extra color every round.
This is just like the classic Simon toy that grows harder as you go.
The problem
You must check each press against a saved pattern, one color at a time.
Think of it like
Like the game "Simon says" — copy the pattern exactly or you are out.
It remembers the pattern and checks your presses.
Arduino
The brain
Press it for the red color in the pattern.
Red button
The red button
Press it for the green color in the pattern.
Green button
The green button
Press it for the yellow color in the pattern.
Yellow button
The yellow button
Press it for the blue color in the pattern.
Blue button
The blue button
It flashes when red is in the pattern.
Red LED
The red light
It flashes when green is in the pattern.
Green LED
The green light
It flashes when yellow is in the pattern.
Yellow LED
The yellow light
It flashes when blue is in the pattern.
Blue LED
The blue light
Keeps the red light safe.
Red resistor
The protector
Keeps the green light safe.
Green resistor
The protector
Keeps the yellow light safe.
Yellow resistor
The protector
Keeps the blue light safe.
Blue resistor
The protector
Play the pattern
It flashes the lights in order from the saved pattern.
showSequence();
Read your button
Each button stands for one color, so we know which one you pressed.
digitalRead(BTN_PINS[i]) == LOW
Did it match?
A wrong press ends the round; a right one adds a new color to the pattern.
if (i != sequence[step]) failPattern();
Then loop back to step 1
Follow these steps in order. Match the wires to the colors shown.
Place Arduino
Place the Arduino (uno) on the breadboard.
Arduino placed — ready to build!
Place Red button
Place the Red button (btn0) on the breadboard.
Place Green button
Place the Green button (btn1) on the breadboard.
Place Yellow button
Place the Yellow button (btn2) on the breadboard.
Place Blue button
Place the Blue button (btn3) on the breadboard.
Place Red LED
Place the Red LED (led0) on the breadboard.
Place Green LED
Place the Green LED (led1) on the breadboard.
Place Yellow LED
Place the Yellow LED (led2) on the breadboard.
Place Blue LED
Place the Blue LED (led3) on the breadboard.
Place Red resistor
Place the Red resistor (r0) on the breadboard.
Place Green resistor
Place the Green resistor (r1) on the breadboard.
Place Yellow resistor
Place the Yellow resistor (r2) on the breadboard.
Place Blue resistor
Place the Blue resistor (r3) on the breadboard.
Connect Arduino pin 2 to Red button (btn0) 1.l
Connect Arduino pin 2 to Red button (btn0) 1.l.
Connect Red button (btn0) 2.l to Arduino GND
Connect Red button (btn0) 2.l to Arduino GND.
Connect Arduino pin 3 to Green button (btn1) 1.l
Connect Arduino pin 3 to Green button (btn1) 1.l.
Connect Green button (btn1) 2.l to Arduino GND
Connect Green button (btn1) 2.l to Arduino GND.
Connect Arduino pin 4 to Yellow button (btn2) 1.l
Connect Arduino pin 4 to Yellow button (btn2) 1.l.
Connect Yellow button (btn2) 2.l to Arduino GND
Connect Yellow button (btn2) 2.l to Arduino GND.
Connect Arduino pin 5 to Blue button (btn3) 1.l
Connect Arduino pin 5 to Blue button (btn3) 1.l.
Connect Blue button (btn3) 2.l to Arduino GND
Connect Blue button (btn3) 2.l to Arduino GND.
Connect Arduino pin 8 to Red resistor (r0) 2
Connect Arduino pin 8 to Red resistor (r0) 2.
Connect Red resistor (r0) 1 to Red LED (led0) anode (+)
Connect Red resistor (r0) 1 to Red LED (led0) anode (+).
Connect Red LED (led0) cathode (-) to Arduino GND
Connect Red LED (led0) cathode (-) to Arduino GND.
Connect Arduino pin 9 to Green resistor (r1) 2
Connect Arduino pin 9 to Green resistor (r1) 2.
Connect Green resistor (r1) 1 to Green LED (led1) anode (+)
Connect Green resistor (r1) 1 to Green LED (led1) anode (+).
Connect Green LED (led1) cathode (-) to Arduino GND
Connect Green LED (led1) cathode (-) to Arduino GND.
Connect Arduino pin 10 to Yellow resistor (r2) 2
Connect Arduino pin 10 to Yellow resistor (r2) 2.
Connect Yellow resistor (r2) 1 to Yellow LED (led2) anode (+)
Connect Yellow resistor (r2) 1 to Yellow LED (led2) anode (+).
Connect Yellow LED (led2) cathode (-) to Arduino GND
Connect Yellow LED (led2) cathode (-) to Arduino GND.
Connect Arduino pin 11 to Blue resistor (r3) 2
Connect Arduino pin 11 to Blue resistor (r3) 2.
Connect Blue resistor (r3) 1 to Blue LED (led3) anode (+)
Connect Blue resistor (r3) 1 to Blue LED (led3) anode (+).
Connect Blue LED (led3) cathode (-) to Arduino GND
Connect Blue LED (led3) cathode (-) to Arduino GND.
Where the pattern lives
const int BTN_PINS[] = {2, 3, 4, 5};
const int LED_PINS[] = {8, 9, 10, 11};
const int NUM = 4;
const int MAX_LEN = 6;
int sequence[MAX_LEN];
int seqLen = 1;
int step = 0;
enum Phase { SHOW, INPUT };
Phase phase = SHOW;sequence holds the pattern; seqLen is how long it is right now and it grows as you win.
showSequence()
void showSequence() {
for (int i = 0; i < seqLen; i++) {
flash(sequence[i], 350);
delay(180);
}
}It plays the pattern by flashing the matching light for each color.
Checking your turn
void loop() {
if (phase == SHOW) {
showSequence();
step = 0;
phase = INPUT;
return;
}
for (int i = 0; i < NUM; i++) {
if (digitalRead(BTN_PINS[i]) == LOW) {
delay(180);
flash(i, 250);
if (i != sequence[step]) {
failPattern();
return;
}
step++;
if (step >= seqLen) {
seqLen++;
if (seqLen > MAX_LEN) {
seqLen = MAX_LEN;
}
sequence[seqLen - 1] = random(0, NUM);
phase = SHOW;
}
while (digitalRead(BTN_PINS[i]) == LOW) {
delay(10);
}
}
}
delay(20);
}On your turn, each press is checked against the saved pattern — that is the heart of Simon.
const int BTN_PINS[] = {2, 3, 4, 5};
const int LED_PINS[] = {8, 9, 10, 11};
const int NUM = 4;
const int MAX_LEN = 6;
int sequence[MAX_LEN];
int seqLen = 1;
int step = 0;
enum Phase { SHOW, INPUT };
Phase phase = SHOW;
void flash(int idx, int ms) {
digitalWrite(LED_PINS[idx], HIGH);
delay(ms);
digitalWrite(LED_PINS[idx], LOW);
delay(120);
}
void showSequence() {
for (int i = 0; i < seqLen; i++) {
flash(sequence[i], 350);
delay(180);
}
}
void failPattern() {
for (int blink = 0; blink < 3; blink++) {
for (int i = 0; i < NUM; i++) {
digitalWrite(LED_PINS[i], HIGH);
}
delay(200);
for (int i = 0; i < NUM; i++) {
digitalWrite(LED_PINS[i], LOW);
}
delay(200);
}
seqLen = 1;
sequence[0] = random(0, NUM);
phase = SHOW;
}
void setup() {
for (int i = 0; i < NUM; i++) {
pinMode(BTN_PINS[i], INPUT_PULLUP);
pinMode(LED_PINS[i], OUTPUT);
}
randomSeed(analogRead(0));
sequence[0] = random(0, NUM);
}
void loop() {
if (phase == SHOW) {
showSequence();
step = 0;
phase = INPUT;
return;
}
for (int i = 0; i < NUM; i++) {
if (digitalRead(BTN_PINS[i]) == LOW) {
delay(180);
flash(i, 250);
if (i != sequence[step]) {
failPattern();
return;
}
step++;
if (step >= seqLen) {
seqLen++;
if (seqLen > MAX_LEN) {
seqLen = MAX_LEN;
}
sequence[seqLen - 1] = random(0, NUM);
phase = SHOW;
}
while (digitalRead(BTN_PINS[i]) == LOW) {
delay(10);
}
}
}
delay(20);
}
Q1. Where does work that repeats go?
Q2. What happens when you press the wrong button?
Slow the pattern down — change the flash time 350 to 500 on line 18.
Hint: That's the flash(...) call on line 18.
Add a note (comment) on line 56 that says it checks for a wrong button.
Hint: That's the if (i != sequence[step]) line.
A line-by-line tour of the sketch — the same steps as in Robot Gurukul Studio.
Program overview
Big idea
Every Arduino program has a top part, a setup() part that runs once, and a loop() part that runs again and again.
In this project
The lights flash a color pattern. You press the matching buttons to copy it.
Tip
Read from the top to the bottom. Tap any word or line if you need help!
const int BTN_PINS[] = {2, 3, 4, 5};
const int LED_PINS[] = {8, 9, 10, 11};
const int NUM = 4;
const int MAX_LEN = 6;
int sequence[MAX_LEN];
int seqLen = 1;
int step = 0;
enum Phase { SHOW, INPUT };
Phase phase = SHOW;
void flash(int idx, int ms) {
digitalWrite(LED_PINS[idx], HIGH);
delay(ms);
digitalWrite(LED_PINS[idx], LOW);
delay(120);
}
void showSequence() {
for (int i = 0; i < seqLen; i++) {
flash(sequence[i], 350);
delay(180);
}
}
void failPattern() {
for (int blink = 0; blink < 3; blink++) {
for (int i = 0; i < NUM; i++) {
digitalWrite(LED_PINS[i], HIGH);
}
delay(200);
for (int i = 0; i < NUM; i++) {
digitalWrite(LED_PINS[i], LOW);
}
delay(200);
}
seqLen = 1;
sequence[0] = random(0, NUM);
phase = SHOW;
}setup()
Big idea
setup() runs one time when the board turns on.
In this project
It gets all 4 buttons and 4 lights ready, mixes up the randomness, and picks the first color.
Why here
Things we do only once go inside setup().
void setup() {
for (int i = 0; i < NUM; i++) {
pinMode(BTN_PINS[i], INPUT_PULLUP);
pinMode(LED_PINS[i], OUTPUT);
}
randomSeed(analogRead(0));
sequence[0] = random(0, NUM);
}loop()
Big idea
loop() runs again and again, forever.
In this project
It shows the pattern, then checks if your presses match it.
Why here
Things that repeat go inside loop().
void loop() {
if (phase == SHOW) {
showSequence();
step = 0;
phase = INPUT;
return;
}
for (int i = 0; i < NUM; i++) {
if (digitalRead(BTN_PINS[i]) == LOW) {
delay(180);
flash(i, 250);
if (i != sequence[step]) {
failPattern();
return;
}
step++;
if (step >= seqLen) {
seqLen++;
if (seqLen > MAX_LEN) {
seqLen = MAX_LEN;
}
sequence[seqLen - 1] = random(0, NUM);
phase = SHOW;
}
while (digitalRead(BTN_PINS[i]) == LOW) {
delay(10);
}
}
}
delay(20);
}
Try this: Change a number inside loop(), then press Run to see what happens.
pinMode
Big idea
pinMode tells a pin if it will listen or push power out.
In this project
It sets the button pins to listen and the light pins to push power out.
Why here
It goes in setup() because we only set it once.
pinMode(BTN_PINS[i], INPUT_PULLUP);
digitalWrite
Big idea
digitalWrite turns a pin ON or OFF.
In this project
It flashes the color lights on and off.
Why here
It is used to show the pattern and your presses.
digitalWrite(LED_PINS[idx], HIGH);
digitalRead
Big idea
digitalRead checks if a pin is ON or OFF.
In this project
It checks which color button you pressed.
Why here
It goes in loop() so we can react to your presses.
if (digitalRead(BTN_PINS[i]) == LOW) {analogRead
Big idea
analogRead reads a number from a pin, from 0 up to 1023.
In this project
It reads a wiggly number from an empty pin to mix up the randomness.
Why here
In setup() so the pattern is different each game.
randomSeed(analogRead(0));
delay
Big idea
delay means wait. Nothing else happens while it waits.
In this project
Short waits let you see each color flash on and off.
Why here
Between flashing the lights.
delay(ms);
random
Big idea
random picks a surprise number for you.
In this project
It picks the next color to add to the pattern.
Why here
When the game makes the pattern longer.
sequence[0] = random(0, NUM);