LED Chaser

by 788246 in Circuits > Arduino

15 Views, 1 Favorites, 0 Comments

LED Chaser

Screenshot 2026-01-21 at 11.22.14 PM.png

Hello Ms, Edwards. I will be presenting my final project for grade 11 computer engineering. For our final project we were asked to create a "Arduino Uno project inspired by other projects and videos". After a period of research I selected to recreate a LED chaser game that was originally created by Vigas B . In order to play the game the lights will be flashing in consecutive order, there will then be a colour name on the serial monitor and your job is to press the push button once the colour stated on the serial monitor is on. When you are successful in catching the correct colour at the correct time the 7 segment display will increase or decrease your score.

Supplies

The supplies need to make this project include ....

  1. LEDs x 7
  2. 555 Timer x 1
  3. 7 Segment Timer x 1
  4. Johnson’s Decade Counter x 1
  5. Arduino x 1
  6. Capacitor x 1
  7. Potentiometer x 1
  8. Push Button x 1
  9. Resistors ( 330, 10k & 550 )
  10. Breadboard x 1
  11. Wires

Day #1

Screenshot 2026-01-21 at 9.56.53 PM.png
Screenshot 2026-01-21 at 11.31.43 PM.png
Screenshot 2026-01-21 at 11.32.07 PM.png

Research : After going through all the links provided by Ms. Edwards I was drawn to the tutorial of the original creator of this project and used his tinker cad display as well as his circuit diagram as my inspiration for this project. Up above in the picture section you will see this original Tinker Cad and his circuit diagram.


Getting Started After Research : After choosing what I wanted to complete I added the 5 main components to the breadboard, which would be the LEDs, Johnson's Decade Counter, Potentiometer, Push Button, and 555 Timer. I placed the components first because this would allow me to organize the layout of the breadboard and help me be more mindful of what I'm placing and where I'm placing it. Next, I connected the capacitor to the 555 timer, this is supposed to eventually control the speed of the LEDs and increase the speed of the game. Then I added a wire to eventually connect the push button to the Arduino, this will allow me to code the push button to eventually affect you score and tell us whether or not you have picked the correct colour. The last thing I did on this day was to add two wires at the end of the breadboard to ensure the components near the end of the board have access to GND and PWR.

Day #2

Screenshot 2026-01-21 at 10.33.45 PM.png

The majority of my second day on this project was spent connected the LEDs to the Johnsons Decade Counter and ensuring I was placing the wires in the correct position as well as focusing on making my wiring tidy and connecting the LEDs and the Johnsons Decade Counter help activate the LEDs at different times, ensuring no two lights are on at the same time, thus helping with the consistency and coding of the lights. Once I was happy with the wiring I moved onto placing resistors in the areas I missed on day #1.

Day #3

Screenshot 2026-01-21 at 11.05.51 PM.png

On the third day of the assignment I got started on adding the four 7 Segment timers that are mentioned and used in the original project, however I changed this decision in the future. The point of the 7 Segment timer is to show your score and whether or not you have completed that level. Since I used a mini breadboard for this portion of the assignment I had to connect the mini board to the bigger breadboards GND and PWR to insure the displays work. After finishing adding the correct wires to the 7 Segment display I begun working on the code. The first section of the code was made for me to introduce the variables of the assignment .


int led1 = 2;

int led2 = 3;

int led3 = 4;

int led4 = 5;

int led5 = 6;

int led6 = 7;

int led7 = 8;


// ---------- 7-SEGMENT PINS ----------

int a = 9;

int b = 10;

int c = 11;

int d = 12;

int e = 13;

int f = A1;

int g = A2;


// ---------- BUTTON ----------

const int button = A0;


// ---------- VARIABLES ----------

int score = 0;

long randColour;

int x = 0;

int initialMessage = 0;


The next second of code was meant to show which components are outputs and which are inputs


void setup()

{

Serial.begin(9600);

pinMode(led1, INPUT);

pinMode(led2, INPUT);

pinMode(led3, INPUT);

pinMode(led4, INPUT);

pinMode(led5, INPUT);

pinMode(led6, INPUT);

pinMode(led7, INPUT);

pinMode(button, INPUT);


pinMode(a, OUTPUT);

pinMode(b, OUTPUT);

pinMode(c, OUTPUT);

pinMode(d, OUTPUT);

pinMode(e, OUTPUT);

pinMode(f, OUTPUT);

pinMode(g, OUTPUT);

randomSeed(analogRead(0));

}


This next section of code is where the main code is run. This includes the messages shown on the serial monitor, the code for the push button, dictates the colour of the LEDs, and the score that is shown on the 7 Segment display.


/Loop function

//Here is where the main code is run, loops once the code is finished

void loop()

{

while (initialMessage==0)/*While loop for the inital message, only displays once on the serial monitor*/

{

Serial.println("Welcome to my LED chaser game. In this game, a colour will be displayed on the serial monitor.");

Serial.println("Your job is click the button when the LED chaser passes over that light.");

Serial.println("You win this game when you get 10 points. You lose when you reach -10 points.");

Serial.println("Each correct gets one point and each wrong takes away one point.");

Serial.println("Beware, the easy difficulty is already hard itself and you can make the game even harder with the potentiometer. Good Luck ");

Serial.println();

initialMessage++;/*Adds one to the variable so that the while loop cannot be open again*/

}

randColour = random(0,4);/*Generates a random number from 1-3 (including those) and sets that as the value for randColour*/


if (randColour == 1)/*If randColour equals 1, runs the code for the colour red*/

{

while(x==0)/*Conditional Loop so that the colour is only displayed once on the serial monitor*/

{

Serial.println("The colour you need to stop on is Red");

x++;

}

int buttonState = digitalRead(button);/*Sets button state to read the value of the pin connected to the button*/

if ((buttonState==HIGH)&&((digitalRead(led1)==HIGH)||(digitalRead(led4)==HIGH)||(digitalRead(led7)==HIGH)))/*If the button is pressed and either Led 1,4, and 7 are on, adds one to the score*/

{

delay(500);/*Add a delay so that you only get one pulse from the button*/

score = score+1;/*Adds one to the score*/

displayScore(score);/*Runs the displayScore function with the score as the parameter*/

Serial.print("Your score is ");

Serial.println(score);/*Prints the Score on the serial monitor*/

x=0;/*Sets x to 0 so that a new colour can be given*/

}

else if ((buttonState==HIGH)&&((digitalRead(led1)==LOW)||(digitalRead(led2)==HIGH)||(digitalRead(led3)==HIGH)||(digitalRead(led4)==LOW)||(digitalRead(led5)==HIGH)||(digitalRead(led6)==HIGH)||(digitalRead(led7)==LOW)))

{

score = score-1;

displayScore(score);

Serial.print("Your score is ");

Serial.println(score);

x=0;

}

}


else if (randColour == 2)

{

while (x==0)

{

Serial.println("The colour you need to stop on is Yellow");

x++;

}

int buttonState = digitalRead(button);

if ((buttonState==(HIGH))&&((digitalRead(led2)==HIGH)||(digitalRead(led5)==HIGH)))/*If the button is pressed and either Led 2 or 5 are on, adds one to the score*/

{

delay(500);

score = score+1;

displayScore(score);

Serial.print("Your score is ");

Serial.println(score);

x=0;

}

else if ((buttonState==HIGH)&&((digitalRead(led1)==HIGH)||(digitalRead(led2)==LOW)||(digitalRead(led3)==HIGH)||(digitalRead(led4)==HIGH)||(digitalRead(led5)== LOW)||(digitalRead(led6)==HIGH)||(digitalRead(led7)==HIGH)))

{ /*If any of the other LEDs are on, or if the listed ones off, then it subtracts one from the score*/

score = score-1;

displayScore(score);

Serial.print("Your score is ");

Serial.println(score);

x=0;

}

}


else if (randColour == 3)/

{

while(x==0)

{

Serial.println("The colour you need to stop on is Green");

x++;

}

int buttonState = digitalRead(button);

if ((buttonState==(HIGH))&&((digitalRead(led3)==HIGH)||(digitalRead(led6)==HIGH)))/*If the button is pressed and either led 3 or 6 are on, adds one to the score*/

{

delay(500);

score = score+1;

displayScore(score);

Serial.print("Your score is ");

Serial.println(score);

x=0;

}

else if ((buttonState==HIGH)&&((digitalRead(led1)==HIGH)||(digitalRead(led2)==HIGH)||(digitalRead(led3)==LOW)||(digitalRead(led4)==HIGH)||(digitalRead(led5)==HIGH)||(digitalRead(led6)==LOW)||(digitalRead(led7)==HIGH)))

{ /*If any of the other LEDs are on, or if the listed ones off, then it subtracts one from the score*/

score = score-1;

displayScore(score);

Serial.print("Your score is ");

Serial.println(score);

x=0;

}

}

if ((score==10)||(score==-10))/*If the score equals either 10 or -10, sets the score back to 0*/

{

score=0;

}

}


This next section of code is to further the code for the score that is shown on the 7 Segment display


{

pickNumber(0);

if (y<0)

{

dash();

}

else/

{

zero();

}

delay(500);

pickNumber(1);

pickNumber(abs(y));

delay(100);}


void displayScore(int y) {

pickNumber(y);

}

}


void pickNumber(int x)

{

switch(x)

{

default:

zero();

break;

case 1:

one();

break;

case 2:

two();

break;

case 3:

three();

break;

case 4:

four();

break;

case 5:

five();

break;

case 6:

six();

break;

case 7:

seven();

break;

case 8:

eight();

break;

case 9:

nine();

break;

}

}


The final portion of the code is for the numbers on the seven segment display and when they are shown


void zero() /*the 7-segment led display 0*/

{

digitalWrite(a, HIGH);

digitalWrite(b, HIGH);

digitalWrite(c, HIGH);

digitalWrite(d, HIGH);

digitalWrite(e, HIGH);

digitalWrite(f, HIGH);

digitalWrite(g, LOW);

}


void one() /*the 7-segment led display 1*/

{

digitalWrite(a, LOW);

digitalWrite(b, HIGH);

digitalWrite(c, HIGH);

digitalWrite(d, LOW);

digitalWrite(e, LOW);

digitalWrite(f, LOW);

digitalWrite(g, LOW);

}


void two() /*the 7-segment led display 2*/

{

digitalWrite(a, HIGH);

digitalWrite(b, HIGH);

digitalWrite(c, LOW);

digitalWrite(d, HIGH);

digitalWrite(e, HIGH);

digitalWrite(f, LOW);

digitalWrite(g, HIGH);

}


void three() /*the 7-segment led display 3*/

{

digitalWrite(a, HIGH);

digitalWrite(b, HIGH);

digitalWrite(c, HIGH);

digitalWrite(d, HIGH);

digitalWrite(e, LOW);

digitalWrite(f, LOW);

digitalWrite(g, HIGH);

}


void four() /*the 7-segment led display 4*/

{

digitalWrite(a, LOW);

digitalWrite(b, HIGH);

digitalWrite(c, HIGH);

digitalWrite(d, LOW);

digitalWrite(e, LOW);

digitalWrite(f, HIGH);

digitalWrite(g, HIGH);

}


void five() /*the 7-segment led display 5*/

{

digitalWrite(a, HIGH);

digitalWrite(b, LOW);

digitalWrite(c, HIGH);

digitalWrite(d, HIGH);

digitalWrite(e, LOW);

digitalWrite(f, HIGH);

digitalWrite(g, HIGH);

}


void six() /*the 7-segment led display 6*/

{

digitalWrite(a, HIGH);

digitalWrite(b, LOW);

digitalWrite(c, HIGH);

digitalWrite(d, HIGH);

digitalWrite(e, HIGH);

digitalWrite(f, HIGH);

digitalWrite(g, HIGH);

}


void seven() /*the 7-segment led display 7*/

{

digitalWrite(a, HIGH);

digitalWrite(b, HIGH);

digitalWrite(c, HIGH);

digitalWrite(d, LOW);

digitalWrite(e, LOW);

digitalWrite(f, LOW);

digitalWrite(g, LOW);

}


void eight() /*the 7-segment led display 8*/

{

digitalWrite(a, HIGH);

digitalWrite(b, HIGH);

digitalWrite(c, HIGH);

digitalWrite(d, HIGH);

digitalWrite(e, HIGH);

digitalWrite(f, HIGH);

digitalWrite(g, HIGH);

}


void nine() /*the 7-segment led display 9*/

{

digitalWrite(a, HIGH);

digitalWrite(b, HIGH);

digitalWrite(c, HIGH);

digitalWrite(d, HIGH);

digitalWrite(e, LOW);

digitalWrite(f, HIGH);

digitalWrite(g, HIGH);

}


void dash() /*the 7-segment led display - */

{

digitalWrite(a, LOW);

digitalWrite(b, LOW);

digitalWrite(c, LOW);

digitalWrite(d, LOW);

digitalWrite(e, LOW);

digitalWrite(f, LOW);

digitalWrite(g, HIGH);

Day #4

Screenshot 2026-01-21 at 11.22.14 PM.png

The night before the due date for this assignment I redid the layout of the LEDs to make space for the 7 Segment display, then added the final missing touches such as the wires at the back of the LEDs that connect them to a resistor. On the day of the assignment I connected all the components to the Arduino and plugged it in and updated the code based on the PIN numbers of the different components.