CODE | LED Traffic Light - Arduino Project 003

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

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 | LED Dot Matrix Display Basic Animation - Arduino Project 019

CODE | LED Dot Matrix Display Basic Animation - Arduino Project 019

So far you have dealt with individual 5mm LEDs. LEDs can also be obtained in a package known as a do…

How to use the Soldering Electric Maker Basic Technology

How to use the Soldering Electric Maker Basic Technology

如何使用电络铁?初级电子制作与维修之焊接知识Gather Tools: You will need a soldering iron, solder, a soldering iron stand,…

CODE | Input and Output- Arduino Programming Basic

CODE | Input and Output- Arduino Programming Basic

The pins on the Arduino can be configured as either inputs or outputs. This document explains the fu…

CODE | Basic Stepper Control (Bipolar) - Serial to Display - Arduino Project 028A

CODE | Basic Stepper Control (Bipolar) - Serial to Display - Arduino Project 028A

In this very simple project, you will connect up a stepper motor and then get the Arduino to control…

CODE | Funcation - Arduino Programming Basic

CODE | Funcation - Arduino Programming Basic

Arduino 程序基础,介绍Arduino程序的基本组成,第一部分编写了10个例子,关于变量及变量名称,串口监视器,if循环,for循环,while循环等。第二部分介绍了函数,全局变量,局部变量和静…

CODE | LED Interactive Traffic Lights - Arduino Project 004

CODE | LED Interactive Traffic Lights - Arduino Project 004

This time you are going to extend the previous project to include a set of pedestrian lights and a p…

Post a Comment

Anonymous

Feel free to share your thoughts and opinions here.