Lights Game

by 752695 in Circuits > Arduino

29 Views, 1 Favorites, 0 Comments

Lights Game

IMG_4944[1].JPG

This project is an LED chaser project that shows a sequence of LED's chasing each other from left to right. There is a button and a seven segment display. This button when pressed is for stopping the led chaser in the exact middle. If the Blue led is hit the idea is that the seven segment display goes up by one. This project is a challenging project to code and create since the wiring can be quite tricky, but this is exactly what drew me into making an attempt into making this project.

Supplies

IMG_4942[1].JPG
IMG_4944[1].JPG

the supplies you will need are the following:

  1. 1 breadboard
  2. 9 leds
  3. 1 Arduino
  4. 9 330Ω resistors
  5. 1 10kΩ resistors(if you have higher it is better to use)
  6. 1 button
  7. 18 wires (9 for leds, 8 for seven segment, 1 for button)

Insert Leds

circuit (8).png

The first step of this is to insert your leds into your breadboard. A description of how your breadboard should look is a 5 to 8cm long rectangle with a bunch of holes in it to insert things like wires, resistors and in our case leds. You want to insert your leds with the long leg in the right side. You want to do for all of your leds that way once you put your resistors in, they line up and it looks neat and cleaner.

Add Wires

circuit (2).png

This step is also very brief and simple all you want to do is connect the wires from the short side of the led straight to the pins in the Arduino. You wanna start all the way far left connect the wire to the closest pin in the arduino that is not trx or rtx. That pin would be 2, afterwards you want to connect the next led to the closest pin which would be 3. You want to keep going until you connect all leds like I have in the schematic.

Add Button

circuit (3).png

after all of the steps, you want to add a button place one half of the button across the side and the other half on the other side that way the button looks better and takes less space on one side. In order to wire a button you need to connect the button to the positive using a red wire and use the highest ohm resistor you have on the other side of the button. In my case it is a 10k resistor.

Place Resistors on Leds

circuit (5).png

You want to place your 330Ω resistors on the long leg of the led, an easy way to understand it is to make sure the resistor is not going into the same leg as the wire. If your breadboard does not fully align like mine you can just rotate your resistors or use wires to connect it. When you connect the resistors make sure you connect it to ground and not power.

Add Seven Segment Display

circuit (6).png
FAAS96VM66HK1NG.jpg

Now we wanna connect our 7 segment display, this is done by placing our display on the left side away from the button where their is more space. Then we want to connect the top of the display to the rest of the pins on the led side. Which would be 11, 12 and 13. Then we will use the A pins for the remaining pins on the bottom half. We also have to make sure to connect our resistors to the middle of the 7 segment display on either side both connected to ground. After this your circuit is fully built

Connect to Ground

circuit (7).png

Then you wanna take a black wire and connect it to ground in the Arduino and then bring that to the ground railing on the breadboard and connect it their. This will give power to the circuit and without this the circuit will not function.

Coding

Screenshot 2025-01-22 082742.png

You want to code using the Arduino software and your code for the leds should look something alone the lines of this


void loop()

{

digitalWrite(greenLed,HIGH);

delay(100);

digitalWrite(greenLed,LOW);

digitalWrite(redLed,HIGH);

delay(100);

digitalWrite(redLed,LOW);

digitalWrite(redLed2, HIGH);

delay(100);

digitalWrite(redLed2,LOW);

digitalWrite(redLed3, HIGH);

delay(100);

digitalWrite(redLed3,LOW);

digitalWrite(blueLed,HIGH);

delay(100);

digitalWrite(blueLed,LOW);

digitalWrite(redLed4,HIGH);

delay(100);

digitalWrite(redLed4,LOW);

digitalWrite(redLed5, HIGH);

delay(100);

digitalWrite(redLed5,LOW);

digitalWrite(redLed6, HIGH);

delay(100);

digitalWrite(redLed6,LOW);

digitalWrite(greenLed2, HIGH)

}


If we look at this code from the top we can see what this code is saying. This code is telling us digitalWrite(greenLed, HIGH). This means that the first green led is going to be on since HIGH means on. Then we are adding a delay before we run almost the exact same code again but instead of running HIGH we are running LOW. What this does is turn the Leds off after the delay. You may ask, what if we just run the code without a delay like this?


digitalWrite(greenLed,HIGH);

digitalWrite(greenLed,LOW);


Since computers run code at lightning speeds we will not get an Led chaser and just get leds turning on and off in no specific order. However, if we add the delay in the middle it tells the computer to stop for the time period set then proceed to the next code. If you noticed at the top this is also in the void loop function which means that all code inside the brackets of the function will run on repeat for as long as you run the code.

Downloads