Traffic Light Sensor
Hello, my name is Dev. On this Instructable i will be showing you how to make a Traffic light in where a distance sensor is placed to help the drivers make better judgement.This project is designed to help drives decide if they would like to cross a yellow light or not.Now that the purpose of this project has been identified lets get to making it.
Materials
1.Arduino Uno x1
2. Breadboard x1
3.Assorted LEDs x3(red, yellow and green)
4.Varying Resistors x4(3x 330ohm, 1x 250 ohm)
5.LCD 16x2 x1
6. Ultrasonic Distance Sensor x1
7. Simple Wires
Wiring
Here is an image of the model in Tinker CAD(I Have Poor Cable management ). Unfortunately due to certain circumstances were not able to make the model in person but the idea should be the same and the same steps would be applied.
Steps
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 place the LEDs and connect the cathode to the ground. the anodes will be connected to digital pins 2,3,4 corresponding from red, yellow and green. Make sure to add your 330ohm resistor before each led is connected to there digital pins
3.Next we'll add our Ultrasonic Distance Sensor. For this we will start by connecting our VCC to power and we will connect the GND to the ground.Now we will connect TRIG to digital pin 12 and ECHO to digital pin 6.
4. Lastly we'll set up our most complicated component, the LCD. To began we will Connect the GND to the ground and the VCC to the power line on the circuit.Next we'll connect the VO to the ground. Now we will connect the RS to digital pin 1. Furthermore we will connect RW to the ground on the circuit. Now we will continue by connecting the E to digital pin 7. Now we will skip DB0,DB1,DB2 and DB3. Starting at DB4 and ending at DB7 we will connect them to digital pins 8,9,10, and 11. Now we will connect the LED Anode to the power make sure to add your final resistor(250ohms) here. Lastly well connect the LED Cathode to the ground.
Code
This code is fairly simple once you understand it. At first we have to add the Library that lets us use the LCD. Then from there the code is pretty straight forward. We specify all our variables then in the void setup we start the LCD and mention all the devices that are either inputs or outputs. In our void loop section we setup the leds to go mimic the design of a Traffic light by adding delays and loops. we also Set our Trig and Echo in that section. We create more Void loops with different names to set the Led Delays and mention when there on and off.
Code File in Txt
This is the code i used.