Introduction
Traffic lights or traffic signals is used to control the traffic and to supervised motorist and pedestrians. The lights alternate accorded to users by displaying “green” for go, “yellow” signal that the light will change to red and “red” for stop. Without traffic lights there will be a lot of road accidents and traffic congestion. This experiment shows how traffic lights work using Arduino.
Materials with Description
Used as an output in the circuit and to know if the code is working.
An electronic device used to control the current in the circuit.
Used as the connector to different pins in the prototyping board.
Used as the connector from computer to DFRArduino Uno R3.
A programmable circuit board. This hardware reads the code uploaded in the computer.
Used to write, compile and upload the code to the circuit.
Procedure (self-explained)
2.Traffic lights for motorist, green(2) positive pin at pin J8 and negative pin to pin J7, yellow positive pin at pin J5 and negative pin to pin J4. red(2) positive pin at pin J2 and negative pin to pin J1.
3. Plot the push button switcher at pin E10,E12, F10 and F12.
6. Connect the USB cable to the computer and the circuit, compile the code then upload.
Circuit Diagram
Code
Code Analysis
“”int carRed = 12;, int carYellow = 11;, int carGreen = 10;” this is the initialization of pins for motorists traffic lights.
“int button = 9;” the initialization of the pushbutton connected to the Arduino.
“int pedRed = 8;, int pedGreen = 7;” the initialization of pins for pedestrian lights.
“int crossTime = 5000;” sets 5 seconds for the pedestrian LED to lit.
“pinMode(pinType,OUTPUT);” pinType sets what pin to use, LEDs in this circuit serves as output.
“pinMode(button, INPUT);” the input in the circuit came from the push button switcher.
“int state = digitalRead(button);” reads if the push button switcher is pushed/pressed or not.
“if (state == HIGH) && (millis() – changeTime) > 5000){…}” a condition that checks if the push button switchern was pressed 5 seconds and then call the method changeLights().
“void changeLights(){…}” in this method, it indicates the sequence lights when it will lit and shows how car/motorist and pedestrian traffic lights work.
“delay(2000);” delays for 2 seconds before it the green light changes to yellow light and “delay(1000);” delay for a second before it goes red.
“changeTime = millis();” this stores the current time in milliseconds to changeTime by calling millis().
Comparison of Code vs. Hardware Output
The code manipulate, manages and provides the output for the hardware. In this experiment if you push or press the push button switcher it changes its lights in a of set time and this shows how traffic lights works.
Recommendation/Enhancement
We can use this traffic light experiment to create mini traffic lights inside the car or motor. In that case the motorist farther on the traffic light will also know the signal.
You have to be 100% sure of the quality of your product to give a money-back guarantee. This describes us perfectly. Make sure that this guarantee is totally transparent.
Read moreEach paper is composed from scratch, according to your instructions. It is then checked by our plagiarism-detection software. There is no gap where plagiarism could squeeze in.
Read moreThanks to our free revisions, there is no way for you to be unsatisfied. We will work on your paper until you are completely happy with the result.
Read moreYour email is safe, as we store it according to international data protection rules. Your bank details are secure, as we use only reliable payment systems.
Read moreBy sending us your money, you buy the service we provide. Check out our terms and conditions if you prefer business talks to be laid out in official language.
Read more