Arduino LED Stoplight
Hello, my name is Shehraj. On this Instructable, I will be showing you how to create a stoplight with a pedestrian crossing button. In this project, the three LEDs will switch from red, green, and yellow automatically and after a certain amount of time. This project will also feature a button that can change the colour of the light on command. Now you know the purpose of this project, let's move on to what materials you will need.
Materials
For this project, you will need:
1, Arduino Uno x1
2. Breadboard x1 (optional but strongly recommended)
3. Assorted LEDs x3 (red, green, yellow)
4. Push Button x1
5. Varying Resistors x4 (x3 330 ohms, x1 10k ohms)
6. Simple Wires
Now that we have all the resources we need, we can move on to constructing this project.
Wiring
Here is a side-by-side look at the Tinker CAD model, and the real circuit. This is a simple circuit that does not require many components. Pins 2, 3, 4, and 5 were used from the Arduino.
In depth
1. Starting off, we will connect the power and ground to the breadboard. We should also connect the two power rails and the two ground rails with each other.
2. Next we can place all three LEDs and connect the cathodes to ground. The anodes will be connected to pins 2,3,4 for red, yellow, green respectively. Be sure to add a 330 ohm resistor before each LED is connected to either the Arduino or ground.
3. Our 3rd step is to connect the button. Place it and connect its bottom right leg to ground using a 10k ohm resistor. Connect the bottom left leg to power. Finally, connect the top right leg to pin 5 on the Arduino.
This is all we need to connect, but this circuit will not function on its own. To create the full stoplight affect, we will need to code in the Arduino program. Continue reading for the full code and an explanation.
A common mistake is cutting wires too short, make sure to not damage the breadboard.
Code
This code is very simple and here is a quick explanation on how it works. At the start of the code, we determined variables to allow us to use the Arduino pins. The void change() function is where the main work happens. In that function, The code changes the LED after a certain period of time. The code also includes comments to explain the purpose of each function, as well as how you can customize the code to your liking.
Always remember to include semi colons!
Code File
This is the code that was used for the project.
Downloads
Demonstration
Here is a video of the code and circuit functioning together.
Thank you for viewing this instructable.
Happy constructing!
(video quality may be poor due to compressed file)