Saturday, July 30, 2011

Traffic Light using Arduino UNO

This is the first proper things I did with the Arduino UNO. The blinking LEDs one don’t really count, do they?

Anyway, this is Project 3 from the tutorial at this link.

The circuit is as follows:


Proper schematic can be found at the manual linked earlier.

And the code is as follows:

int ledDelay = 10000;
int redPin = 10;
int yellowPin = 8;
int greenPin = 9;

void setup(){
pinMode(redPin, OUTPUT);
pinMode(yellowPin, OUTPUT);
pinMode(greenPin, OUTPUT);

void loop(){
digitalWrite(redPin, HIGH);
digitalWrite(yellowPin, HIGH);
digitalWrite(greenPin, HIGH);
digitalWrite(redPin, LOW);
digitalWrite(yellowPin, LOW);
digitalWrite(yellowPin, HIGH);
digitalWrite(greenPin, LOW);
digitalWrite(yellowPin, LOW);

What it was doing is described below:

1. The red light will be on for 10 secs, then remains on while the yellow light turn on for 2 seconds.

2. After that both lights will turn off and the green light turns on for 10 second.

3. After that the green light remains on while the yellow light turns on for 2 seconds.

4. Loop repeats.

No comments: