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:

IMG_20110730_131549

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);
delay(ledDelay);
digitalWrite(yellowPin, HIGH);
delay(2000);
digitalWrite(greenPin, HIGH);
digitalWrite(redPin, LOW);
digitalWrite(yellowPin, LOW);
delay(ledDelay);
digitalWrite(yellowPin, HIGH);
digitalWrite(greenPin, LOW);
delay(2000);
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:

Post a Comment

You must be bored for you to come all the way to comment on my boring posts.

You should be clear that there're some other things that are more worthy to waste your online time on rather than commenting on someone's blog ya noe... Like DL stuff, read news, play games, flirt around...

But for you to be willing enough to comment must mean a lot to you. Afterall you could've picked up a chick/dude with the time spent commenting here.

So wutcha doin reading these stuff here at this commenting section that I wrote out of boredom? Comment!

Wanna flame? Flame then! It's ok to flame online as long as it stays online...