CODE | LED Traffic Light - Arduino Project 003

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

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

C01 | The Past and Present of the C Language

C01 | The Past and Present of the C Language

C语言教程01:C语言的前世今生程序设计语言的发展经历了从机器语言->汇编语言->高级语言的过程机器语言:是计算机最原始的语言,由 0 和 1 的代码构成,CPU 在工作的时候只认识机 器…

Electric Maker Beginner Tools Kit

Electric Maker Beginner Tools Kit

This assortment of tools has everything you need to get started tinkering with Sparkfun products and…

CODE | Digital Pressure Sensor - Arduino Project 031

CODE | Digital Pressure Sensor - Arduino Project 031

Arduino Programming Basic -- Pressure SensorsPressure sensors are integral components in a multitude…

CODE | L293D Motor Driver IC - Arduino Project 016

CODE | L293D Motor Driver IC - Arduino Project 016

In the previous project, you used a transistor to control the motor. In this project, you are going…

CODE | Light Sensor - Arduino Project 014

CODE | Light Sensor - Arduino Project 014

This project introduces a new component known as a Light Dependent Resistor, or LDR. As the name imp…

CODE | Dot Matrix Display Beat Heart - Valentine's Day Gift

CODE | Dot Matrix Display Beat Heart - Valentine's Day Gift

You’re going to use the Project 19 circuit, but with a slight variation in the code to create a mult…

Post a Comment

Anonymous

Feel free to share your thoughts and opinions here.