Project showcase

# A Simple Simon Says Game © GPL3+

This lesson aims to show how to make a simple Arduino based Simon Says light game.

• 53,731 views
• 39 respects

## Components and supplies

 Arduino UNO
×1
 Breadboard 830 points with Wire Kit
×1
 10 Red Led 5mm
×1
 10 Yellow Led 5mm
×1
 10 Green Led 5mm
×1
 10 Blue Led 5mm
×1
 5 PushButton 6x6
×1
 10 jumper wires 100mm male
×1

### 1. How does it work?

When the button attached to A4 pin is pressed a sequence is generated and the software wait for the same sequence. If the two sequence are different the LEDs will blink for three times very fast otherwise the sequence is correct. If the sequence is correct the game goes ahead and the difficulty and velocity are incremented.

The two sequence are stored in two vectors and compared.

### 2. Schematic

Here is the schematic:

### 3. The code

Here is the code:

``````<p>/*This sketch is a simple version of the famous Simon Says game. You can use it and improved it adding<br />
levels and everything you want to increase the diffuculty!</p>
<p>There are five buttons connected to A0, A1, A2, A3 and A4.<br />
The buttons from A0 to A3 are used to insert the right sequence while A4 to start the game.</p>
<p>When a wrong sequence is inserted all the leds will blink for three time very fast otherwhise the<br />
inserted sequence is correct.</p>
Hardware needed:<br />
5x pushbuttons<br />
1x Blue led<br />
1x Yellow led<br />
1x Red led<br />
1x Green Led<br />
4x 1k resistors<br />
4x 10k resisors<br />
10x jumpers<br />
*/</p>
<p>const int MAX_LEVEL = 100;<br />
int sequence[MAX_LEVEL];<br />
int your_sequence[MAX_LEVEL];<br />
int level = 1;</p>
<p>int velocity = 1000;</p>
<p>void setup() {<br />
pinMode(A0, INPUT);<br />
pinMode(A1, INPUT);<br />
pinMode(A2, INPUT);<br />
pinMode(A3, INPUT);</p>
<p>pinMode(2, OUTPUT);<br />
pinMode(3, OUTPUT);<br />
pinMode(4, OUTPUT);<br />
pinMode(5, OUTPUT);</p>
<p>digitalWrite(2, LOW);<br />
digitalWrite(3, LOW);<br />
digitalWrite(4, LOW);<br />
digitalWrite(5, LOW);<br />
}</p>
<p>void loop()<br />
{<br />
if (level == 1)<br />
generate_sequence();//generate a sequence;</p>
<p>if (digitalRead(A4) == LOW || level != 1) //If start button is pressed or you're winning<br />
{<br />
show_sequence();    //show the sequence<br />
get_sequence();     //wait for your sequence<br />
}<br />
}</p>
<p>void show_sequence()<br />
{<br />
digitalWrite(2, LOW);<br />
digitalWrite(3, LOW);<br />
digitalWrite(4, LOW);<br />
digitalWrite(5, LOW);</p>
<p>for (int i = 0; i < level; i++)<br />
{<br />
digitalWrite(sequence[i], HIGH);<br />
delay(velocity);<br />
digitalWrite(sequence[i], LOW);<br />
delay(200);<br />
}<br />
}</p>
<p>void get_sequence()<br />
{<br />
int flag = 0; //this flag indicates if the sequence is correct</p>
<p>for (int i = 0; i < level; i++)<br />
{<br />
flag = 0;<br />
while(flag == 0)<br />
{<br />
{<br />
digitalWrite(5, HIGH);<br />
your_sequence[i] = 5;<br />
flag = 1;<br />
delay(200);<br />
if (your_sequence[i] != sequence[i])<br />
{<br />
wrong_sequence();<br />
return;<br />
}<br />
digitalWrite(5, LOW);<br />
}</p>
{<br />
digitalWrite(4, HIGH);<br />
your_sequence[i] = 4;<br />
flag = 1;<br />
delay(200);<br />
if (your_sequence[i] != sequence[i])<br />
{<br />
wrong_sequence();<br />
return;<br />
}<br />
digitalWrite(4, LOW);<br />
}</p>
{<br />
digitalWrite(3, HIGH);<br />
your_sequence[i] = 3;<br />
flag = 1;<br />
delay(200);<br />
if (your_sequence[i] != sequence[i])<br />
{<br />
wrong_sequence();<br />
return;<br />
}<br />
digitalWrite(3, LOW);<br />
}</p>
{<br />
digitalWrite(2, HIGH);<br />
your_sequence[i] = 2;<br />
flag = 1;<br />
delay(200);<br />
if (your_sequence[i] != sequence[i])<br />
{<br />
wrong_sequence();<br />
return;<br />
}<br />
digitalWrite(2, LOW);<br />
}</p>
<p>}<br />
}<br />
right_sequence();<br />
}</p>
<p>void generate_sequence()<br />
{<br />
randomSeed(millis()); //in this way is really random!!!</p>
<p>for (int i = 0; i < MAX_LEVEL; i++)<br />
{<br />
sequence[i] = random(2,6);<br />
}<br />
}<br />
void wrong_sequence()<br />
{<br />
for (int i = 0; i < 3; i++)<br />
{<br />
digitalWrite(2, HIGH);<br />
digitalWrite(3, HIGH);<br />
digitalWrite(4, HIGH);<br />
digitalWrite(5, HIGH);<br />
delay(250);<br />
digitalWrite(2, LOW);<br />
digitalWrite(3, LOW);<br />
digitalWrite(4, LOW);<br />
digitalWrite(5, LOW);<br />
delay(250);<br />
}<br />
level = 1;<br />
velocity = 1000;<br />
}</p>
<p>void right_sequence()<br />
{<br />
digitalWrite(2, LOW);<br />
digitalWrite(3, LOW);<br />
digitalWrite(4, LOW);<br />
digitalWrite(5, LOW);<br />
delay(250);</p>
<p>digitalWrite(2, HIGH);<br />
digitalWrite(3, HIGH);<br />
digitalWrite(4, HIGH);<br />
digitalWrite(5, HIGH);<br />
delay(500);<br />
digitalWrite(2, LOW);<br />
digitalWrite(3, LOW);<br />
digitalWrite(4, LOW);<br />
digitalWrite(5, LOW);<br />
delay(500);</p>
<p>if (level < MAX_LEVEL);<br />
level++;</p>
<p>velocity -= 50; //increase difficulty<br />
}</p>
``````

## Code

##### Code snippet #1Arduino
```/*This sketch is a simple version of the famous Simon Says game. You can use it and improved it adding
levels and everything you want to increase the diffuculty!

There are five buttons connected to A0, A1, A2, A3 and A4.
The buttons from A0 to A3 are used to insert the right sequence while A4 to start the game.

When a wrong sequence is inserted all the leds will blink for three time very fast otherwhise the
inserted sequence is correct.

Hardware needed:
5x pushbuttons
1x Blue led
1x Yellow led
1x Red led
1x Green Led
4x 1k resistors
4x 10k resisors
10x jumpers
*/

const int MAX_LEVEL = 100;
int sequence[MAX_LEVEL];
int your_sequence[MAX_LEVEL];
int level = 1;

int velocity = 1000;

void setup() {
pinMode(A0, INPUT);
pinMode(A1, INPUT);
pinMode(A2, INPUT);
pinMode(A3, INPUT);

pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);

digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
}

void loop()
{
if (level == 1)
generate_sequence();//generate a sequence;

if (digitalRead(A4) == LOW || level != 1) //If start button is pressed or you're winning
{
show_sequence();    //show the sequence
}
}

void show_sequence()
{
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);

for (int i = 0; i < level; i++)
{
digitalWrite(sequence[i], HIGH);
delay(velocity);
digitalWrite(sequence[i], LOW);
delay(200);
}
}

void get_sequence()
{
int flag = 0; //this flag indicates if the sequence is correct

for (int i = 0; i < level; i++)
{
flag = 0;
while(flag == 0)
{
{
digitalWrite(5, HIGH);
your_sequence[i] = 5;
flag = 1;
delay(200);
if (your_sequence[i] != sequence[i])
{
wrong_sequence();
return;
}
digitalWrite(5, LOW);
}

{
digitalWrite(4, HIGH);
your_sequence[i] = 4;
flag = 1;
delay(200);
if (your_sequence[i] != sequence[i])
{
wrong_sequence();
return;
}
digitalWrite(4, LOW);
}

{
digitalWrite(3, HIGH);
your_sequence[i] = 3;
flag = 1;
delay(200);
if (your_sequence[i] != sequence[i])
{
wrong_sequence();
return;
}
digitalWrite(3, LOW);
}

{
digitalWrite(2, HIGH);
your_sequence[i] = 2;
flag = 1;
delay(200);
if (your_sequence[i] != sequence[i])
{
wrong_sequence();
return;
}
digitalWrite(2, LOW);
}

}
}
right_sequence();
}

void generate_sequence()
{
randomSeed(millis()); //in this way is really random!!!

for (int i = 0; i < MAX_LEVEL; i++)
{
sequence[i] = random(2,6);
}
}
void wrong_sequence()
{
for (int i = 0; i < 3; i++)
{
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
digitalWrite(5, HIGH);
delay(250);
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
delay(250);
}
level = 1;
velocity = 1000;
}

void right_sequence()
{
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
delay(250);

digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
digitalWrite(5, HIGH);
delay(500);
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
delay(500);

if (level < MAX_LEVEL);
level++;

velocity -= 50; //increase difficulty
}
```

## Schematics

#### Author

##### Arduino_Scuola
• 32 projects
• 138 followers

July 8, 2016

#### Members who respect this project

and 36 others

See similar projects
you might like

#### Breadboard to PCB Part 1 - Making the Simon Says Game

Project tutorial by Katie Kristoff and Monica Houston

• 16,957 views
• 39 respects

#### Arduino Simple Simon Says

Project tutorial by Metonymy

• 12,709 views
• 13 respects

#### A Simple Reflex Game

Project tutorial by rowan07

• 7,773 views
• 8 respects

#### Gravity Simon Game

Project showcase by plcrpbqr

• 2,729 views
• 8 respects

#### Make an Arduino Memory Game

Project tutorial by Jeremie

• 44,531 views