CODE | LED Traffic Light - Arduino Project 003

RonWang3 years ago (2023-05-22)电子编程 COD15

You are now going to create a set of traffic lights that will change from green to red, via amber, and back again, after a set length of time using the four-state UK system. This project could be used to make a set of working traffic lights for a model railway or for a child’s toy town. If you’re not from the UK, you can modify the code and colors to make them work like the traffic lights in your own country. First, though, make the project as it is and change it once you know how it works.

Project 3 -LED Traffic Lights

03 Traffic Light Circuit

03 Traffic Light Schematic



/* Coding Ron Wang
   June 4th 2024
   Autaba support for coding hardware
 */
// Project 3 - LED Traffic Lights

int ledDelay = 10000; // delay in between changes
int redPin = 10;
int yellowPin = 9;
int greenPin = 8;
void setup() {
 pinMode(redPin, OUTPUT);
 pinMode(yellowPin, OUTPUT);
 pinMode(greenPin, OUTPUT);
}
void loop() {
 digitalWrite(redPin, HIGH); // turn the red light on
 delay(ledDelay); // wait 5 seconds
 digitalWrite(yellowPin, HIGH); // turn on yellow
 delay(2000); // wait 2 seconds
 digitalWrite(greenPin, HIGH); // turn green on
 digitalWrite(redPin, LOW); // turn red off
 digitalWrite(yellowPin, LOW); // turn yellow off
 delay(ledDelay); // wait ledDelay milliseconds
 digitalWrite(yellowPin, HIGH); // turn yellow on
 digitalWrite(greenPin, LOW); // turn green off
 delay(2000); // wait 2 seconds
 digitalWrite(yellowPin, LOW); // turn yellow off
 // now our loop repeats
}
Share with Friends:

Related Articles

CODE | Piezo Sounder Melody Player - Arduino Project 012

CODE | Piezo Sounder Melody Player - Arduino Project 012

Rather than using the piezo to make annoying alarm sounds, why not use it to play a melody? You are…

CODE | 4 Digital 7 Segment Display - Arduino Project 033

CODE | 4 Digital 7 Segment Display - Arduino Project 033

Showing Heep and number 0-9 on a Common Anode 7-segment LED display. Displays the numbers 0-9 on the…

CODE | DTH Temperature & Humid Sensor - Arduino Project 036

CODE | DTH Temperature & Humid Sensor - Arduino Project 036

The DHT11 Temperature and Humidity Sensor senses, measures and regularly reports the relative humidi…

Series and parallel circuits

Series and parallel circuits

Two-terminal components and electrical networks can be connected in series or parallel. The resultin…

Resitor Ohm's Law

Resitor Ohm's Law

Ohm's law states that the current through a conductor between two points is directly&n…

CODE | RGB LED Mood Lamp - Arduino Project 008

CODE | RGB LED Mood Lamp - Arduino Project 008

In the last project, you learned how to adjust the brightness of an LED using the PWM capabilities o…

Post a Comment

Anonymous

Feel free to share your thoughts and opinions here.