ARDUINO
TRAFFIC LIGHTS TUTORIAL
INTRODUCTION
Arduino is a
microcontroller which can be programmed to do certain operations like lighting
led, controlling servo, etc. This is a DIY Arduino project intended to simulate
traffic lights on the streets. A Traffic light usually consists of three lights
red, yellow and green. They switch on and off within a certain time interval. The
usual cycle of traffic light starts with red light for some time, followed by a
momentary yellow light as a warning and finally green light for the remaining
time before switching back to red.
COMPONENTS
REQUIRED
1. Breadboard
2. Arduino
UNO and USB cable
3. One
5mm LED each of three colors (Red, Yellow and Green)
4. Three
20 Ohm resistors
5. Jumpers
6. A 5V DC Power supply
CIRCUIT SCHEMATICS
Traffic Light wiring schematic |
Make
the appropriate connections as shown in the schematic above
CODE
This
is the code for simulating Arduino Traffic lights. Note that this code is valid
only for the particular schematic represented in figure1. The values and choice
of ports can always be changed.
Copy and paste the code in Arduino IDE sketch
area.
void setup() {
pinMode(2, OUTPUT); //red led
pinMode(4, OUTPUT); //yellow led
pinMode(7, OUTPUT); //green led
}
// the loop function
runs over and over again forever
void loop() {
digitalWrite(2, HIGH); // turn the red led on
delay(5000); // wait for some time
digitalWrite(2, LOW); // turn the red led off
delay(100); // wait for some time
digitalWrite(4, HIGH); // turn the yellow led on
delay(1000); // wait for some time
digitalWrite(4, LOW); // turn the yellow led off
delay(100); // wait for some time
digitalWrite(7, HIGH); // turn the green led on
delay(5000); // wait for some time
digitalWrite(7, LOW); // turn the green led off
delay(200); // wait for some time
}
No comments:
Post a Comment