0% found this document useful (0 votes)
7 views3 pages

Arduino Lesson 5-Trafic Light

This document outlines an Arduino lesson for creating a traffic light system, building on a previous lesson. It lists required components, including LEDs and resistors, and provides a sample program to control the traffic light using digital interfaces and delay functions. The program demonstrates the sequence of turning on and off the red, yellow, and green LEDs.

Uploaded by

maisecinos
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views3 pages

Arduino Lesson 5-Trafic Light

This document outlines an Arduino lesson for creating a traffic light system, building on a previous lesson. It lists required components, including LEDs and resistors, and provides a sample program to control the traffic light using digital interfaces and delay functions. The program demonstrates the sequence of turning on and off the red, yellow, and green LEDs.

Uploaded by

maisecinos
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd

Arduino Lesson 5

Traffic Light
 Intro
1. This experiment actually is an extend version of lesson 2.
2. We can use lesson 2 for reference, use digital interface # 10、#7、#4.

3. Use Arduino delay()function to control the delay time.

 Parts required
Besides Arduino main board and USB cable, we also need
Red 5mm LED x 1
Yellow 5mm LED x 1
Green 5mm LED x 1
220ΩResistor x 3
Breadboad x 1
Jumper wires x 1 Bundle
 Program for reference

int redled =10; // Define digital interface #10.

int yellowled =7; // Define digital interface #7.

int greenled =4; // Define digital interface #4.


void setup()
{

pinMode(redled, OUTPUT);// Define red LED interface as

output.

pinMode(yellowled, OUTPUT); // Define yellow LED interface as

[Link](greenled, OUTPUT); // Define green LED

interface as output.
}
void loop()
{
digitalWrite(redled, HIGH);// Turn on red led.
delay(1000);//Delay 1 sec

digitalWrite(redled, LOW); // Turn off red led.

digitalWrite(yellowled, HIGH);// Turn on yellow led.


delay(200);//Delay 0.2 sec
digitalWrite(yellowled, LOW);//Turn off yellow led.

digitalWrite(greenled, HIGH);// Turn on the green led.


delay(1000);//Dealy 1 sec.
digitalWrite(greenled, LOW);//Turn off green led.
}

Download the program you will see the traffic light is working.

You might also like