It’s been a while since my last Arduino-related blog, in fact my last project post was way back at the end of May, shortly after this website went live, with my arduino crypto fear and greed index desktop trinket thing. This is particularly bad form given the name of this blog and my original intentions when creating it—but hey, that’s how things go—it’s become more of a place for everything and anything that I want to write about since, which suits me.
I had some time on my hands last night and wanted a simple evening project using bits and pieces I already had knocking around the house, which led me here—to my attempt at whipping up a simple Simon-like game using an Arduino Uno R3 and a couple of unused components that I still had in my ELEGOO Arduino starter kit while I wait for a few more components to be delivered for another project (watch this space for more on that).
As someone who is also relatively new to Arduino, I would definitely recommend a project like this for anyone looking to move beyond the simple blinking LED project and on to something a little more complex, without getting into all the weird and wonderful sensors out there before you’re quite ready for them. While this post gives you everything you need to remake this project yourself, this first draft of it may be a little scrappy – so if anything is unclear or you have any questions, please let me know in the comments. I’m aiming to give it a bit of a further revision shortly.
With all that out of the way, let’s get into this project—starting with a demo of the project in action.
The project in action
What you’ll need
- 1x blue LED
- 1x green LED
- 1x red LED
- 1x yellow LED
- 8 x 1k resistors
- 4 x tactile push buttons
- 1 x breadboard
- 1 x Arduino Uno R3
- …a bunch of jumper wires
Wiring guide

While the image above should be fairly self explanatory, the pinout for this project is as follows:
//LEDs
#define blueLED 13
#define greenLED 11
#define redLED 9
#define yellowLED 7
//BUTTONS
#define blueBtn 12
#define greenBtn 10
#define redBtn 8
#define yellowBtn 6
The code
As anyone who has read any of my previous posts, I’m not much of an explanations and tutorial kind of guy. That said, I’ll do my best to provide a brief overview and summary on how this works, as well as providing the full .ino file at the end of this section—so here goes.
- A number between 1 and 4 is generated, which is used to determine which LED will be next in the sequence
- This number is added to an array on integers—named “sequence”—which is used to compare user button inputs against, to confirm the sequence input by the user is correct
- And then it does a few additional things—like blink LEDs together if the sequence is incorrect and cycle through them if user wins
There are a couple of things you’ll want to define yourself, such as number of rounds and when to increase the game speed. I tried to keep this faithful to the original game, with a total of 35 rounds, but you can customise these as you like in this part of the code.
#define totalRounds 35
#define increaseSpeedEveryNth 9
Another thing you’ll want to keep in mind, especially if you want to increase the number of rounds, is to tweak the “gameSpeed” settings—which is calculated in the main loop, removing 100 from it when the iteration is divisible by the “increaseSpeedEveryNth” value. You’ll also want to adjust the values in the processBtnPress() and reset() functions, as these will change the gameSpeed value as the game progresses.
I’ve included snippets for each of the sections of the code mentioned in the paragraph above for reference.
loop()
else if(count % increaseSpeedEveryNth == 0){
gameSpeed-=200;
}
processBtnPress()
if(sequence[btnPress] == btn){
ledOn(btn);
delay(gameSpeed/4);
ledOff(btn);
}
reset()
gameSpeed = 800;
With those brief notes out of the way, you can find the full .ino file below for reference.
simon_game.ino
#define blueLED 13
#define greenLED 11
#define redLED 9
#define yellowLED 7
#define blueBtn 12
#define greenBtn 10
#define redBtn 8
#define yellowBtn 6
#define ledCount 4
#define totalRounds 35
#define increaseSpeedEveryNth 9
int gameState = 1;
int gameSpeed = 800;
int count = 0;
int btnPress = 0;
int sequence[totalRounds];
int btnPressCount = 0;
int sequenceState = 0;
int ledArray[ledCount] = { blueLED, greenLED, redLED, yellowLED };
int btnArray[ledCount] = { blueBtn, greenBtn, redBtn, yellowBtn };
void setup() {
for (int i = 0; i < ledCount; i++) {
pinMode(ledArray[i], OUTPUT);
pinMode(btnArray[i], INPUT);
}
}
void ledOn (int led){
digitalWrite(ledArray[led-1], HIGH);
}
void ledOff (int led){
digitalWrite(ledArray[led-1], LOW);
}
void processBtnPress(int btn) {
if(sequence[btnPress] == btn){
ledOn(btn);
delay(gameSpeed/4);
ledOff(btn);
}
else {
lose();
}
btnPress++;
}
void win(){
for(int i = 0; i < 5; i++) {
for(int i = 0; i < sizeof(ledArray)/sizeof(ledArray[0]); i++) {
ledOn(i+1);
delay(50);
ledOff(i+1);
delay(50);
}
}
reset();
delay(2000);
}
void lose() {
for(int i = 0; i < 3; i++) {
for(int i = 0; i < sizeof(ledArray)/sizeof(ledArray[0]); i++) {
ledOn(i+1);
}
delay(250);
for(int i = 0; i < sizeof(ledArray)/sizeof(ledArray[0]); i++) {
ledOff(i+1);
}
delay(250);
}
reset();
delay(2000);
}
void clearSequence() {
for(int i = 0; i < sizeof(sequence)/sizeof(sequence[0]); i++) {
sequence[i] = ' ';
}
}
void reset() {
clearSequence();
count = 0;
btnPress = 0;
gameSpeed = 800;
gameState = 0;
}
void loop() {
if(gameState == 0) {
if(count == sizeof(sequence)/sizeof(sequence[0])){
win();
}
else if(count % increaseSpeedEveryNth == 0){
gameSpeed-=200;
}
sequence[count] = random(1, 5);
for(int i = 0; i <= count; i++)
{
Serial.print(sequence[i]);
}
Serial.println(' ');
for(int i = 0; i <= count; i++) {
ledOn(sequence[i]);
delay(gameSpeed);
ledOff(sequence[i]);
delay(gameSpeed);
}
count++;
gameState = 1;
}
else if(gameState == 1){
if(btnPress == count){
btnPress = 0;
gameState = 0;
delay(2000);
}
else {
if(digitalRead(btnArray[0]) == HIGH || digitalRead(btnArray[1]) == HIGH || digitalRead(btnArray[2]) == HIGH || digitalRead(btnArray[3]) == HIGH) {
if(digitalRead(btnArray[0]) == HIGH){
processBtnPress(1);
}
else if(digitalRead(btnArray[1]) == HIGH){
processBtnPress(2);
}
else if(digitalRead(btnArray[2]) == HIGH){
processBtnPress(3);
}
else if(digitalRead(btnArray[3]) == HIGH){
processBtnPress(4);
}
delay(250);
}
}
}
}
Summing it up
If you’re new to Arduino and are looking for your next project after some of the more basic options, like the simple blinking LED—this could be a good choice, as it ups the level of complexity without throwing much more in the way of hardware into the mix. I thoroughly enjoyed making this—it was a good couple of hours well spent.
This project is especially good to do with kids—as creating a game out of components really helps to bring Arduino to life, being a lot more engaging than many other projects in or around the same skill level. While I didn’t involve mine too much in the build and coding, mostly due to their still being pretty young, I did hand it over to my 4-year-old to have a play with—which she got to grips with and enjoys pretty quickly.
Well that’s it. I hope you’ve enjoyed this project and found the post helpful. If you’ve got any questions, comments or feedback, I’d love to hear from you in the comments. Additionally, as someone who is still relatively new to this, if you’ve got tips and pointers on how I can go about improving my code, I’d also welcome these in the comments. Thanks for reading!
Thank you brother
No worries! Thanks for reading.
This looks like a fun project to advance my coding. TY Sir!
No worries! Happy to help – it’s all about helping each other get better at it. Thanks for reading.