16/10/2019
Experiment 1: Traffic Lights
We are now going to create a set of traffic lights
that will change from green to red, via amber, and
Description of the Project
back again, after a set length of time using the 4-
state system..
The components needed
10/16/2019 1
The Light Emitting Diode (LED)
LED is a semiconductor device that emits visible
light when an electric current passes through it.
What is LED
Some LEDs emit infrared (IR) energy; such a
device is known as an infrared-emitting
diode (IRED). An consists of two elements of
processed material called P-type semiconductors
and N-type semiconductors. These two elements
are placed in direct contact, forming a region
called the P-N junction. In this respect, the LED
or IRED resembles most other diode types, but
there are important differences.
Symbol of LED
10/16/2019 2
1
16/10/2019
The Circuit Connection for the Traffic Light
10/16/2019 3
The Circuit Connection for the Traffic Light
10/16/2019 4
2
16/10/2019
void loop() {
digitalWrite(redPin, HIGH); // turn the red light on
int ledDelay = 10000; // delay in between
delay(ledDelay); // wait 5 seconds
changes
digitalWrite(yellowPin, HIGH); // turn on yellow
int redPin = 10;
delay(2000); // wait 2 seconds
int yellowPin = 9;
digitalWrite(greenPin, HIGH); // turn green on
int greenPin = 8;
digitalWrite(redPin, LOW); // turn red off
void setup() {
digitalWrite(yellowPin, LOW); // turn yellow off
pinMode(redPin, OUTPUT);
delay(ledDelay); // wait ledDelay milliseconds
pinMode(yellowPin, OUTPUT);
digitalWrite(yellowPin, HIGH); // turn yellow on
pinMode(greenPin, OUTPUT);
digitalWrite(greenPin, LOW); // turn green off
}
delay(2000); // wait 2 seconds
digitalWrite(yellowPin, LOW); // turn yellow off
// now our loop repeats
}}
10/16/2019 5
10/16/2019 6