If you want to get your hands dirty with a few LEDs and resistors, and while adding a switch with a pull down resistor and play around with the code, then we can discuss the project named Arduino traffic light controller. This project is based on the idea that how two traffic light board control traffic in a one way junction.
For this, one Arduino Uno board and red, green and yellow LED are used in the project. Apart from that, a breadboard, resistors for the LEDs, Connecting wires, a pushbutton switch and a high value resistor is required
Wiring
The quick schematic, made up in Fritzing is very simple. The three LEDs are wired with resistors to three separate input pins, and all of them are connected to the ground.
Programming
For the function to be set up, the red, yellow and green LEDs are particularly specified as output mode and variables created are to be represented as the pin numbers. Separate function for changing the lights are created. The programming and the codes includes figuring out the minute logic details that presents the biggest problem. Here, the key to being a good programmer is to look at any process carefully and break it down into its fundamental steps.
Upload and run, once done with the codes and a working traffic light that changes every 15 seconds can be seen. Now update the circuit diagram to add in a pushbutton for pedestrians to change the light whenever they like.
The switch will have a high-impedance 10k resistor attached to it, which is called a pull down resistor. A switch is responsible for the current flow but in a logic circuit, the current should be always flowing in either a high or low state. Therefore, assume that a pushbutton switch that isn’t actually being pushed would be defined as being in a low state, but in fact it’s said to be ‘floating’, because no current is being drawn at all.
It is possible that a false reading will occur in the floating state as it fluctuates with electrical interference. When the switch is closed, a pull down resistor keeps a small amount of current flowing and hence ensure an accurate low state reading.
By adding some new variables to the start of the app, read the state of the pushbutton switch and only change the lights when it’s activated. It means that the loop part of the code will not focus on changing of the lights every 15 seconds and change when the lights are activated.
In the setup function a new line is added to make the switch as an input and a single line to start the traffic lights in the green stage. After changing the entire loop function, wait for 15 seconds to ensure that traffic lights don’t change for at least that duration. Exactly15 seconds later, the loop restarts and with each restart, read the state of the button again.
Filed Under: Reviews
Questions related to this article?
👉Ask and discuss on Electro-Tech-Online.com and EDAboard.com forums.
Tell Us What You Think!!
You must be logged in to post a comment.