Carmen makes an Arduino Stoplight

December 12, 2011 | Arduino, electronics, LED | By: Mark VandeWettering

Today, Carmen decided that she wanted to give Arduino programming a try. She’s an experienced programmer, but had never tried any of this small embedded stuff, and knows relatively little about electronics, but with a little direction from me, she got the Arduino development environment installed, and we did a bit of playing around. I showed how we could blink an LED, and then showed her how to read switches and even drive a servo motor. She then walked through some of Lady Ada’s tutorials and ended up scavenging a red, green, and yellow LED from some old throwies we had, and coding up a little stop light application:

Here’s the code:

// Stoplight 
// Introductory Arduino program - Carmen & Mark VandeWettering 12/11/11
// with thanks to : http://www.ladyada.net/learn/arduino/lesson3.html
//
int redPin = 12;                  // Red LED connected to digital pin 12
int greenPin = 11;                // Green LED connected to digital pin 11
int yellowPin = 13;               // Yellow LED connected to digital pin 13
int delayTime = 1000;             // initiate a delaytime amount here

void setup()                      // run once, when the sketch starts
{
  pinMode(redPin, OUTPUT);        // sets the digital pin as output
  pinMode(greenPin, OUTPUT);      // sets the digital pin as output
  pinMode(yellowPin, OUTPUT);     // sets the digital pin as output
}

void loop()                       // run over and over again
{
  digitalWrite(redPin, HIGH);     // sets the Red LED on
  delay(delayTime);               // waits the delayTime 
  digitalWrite(redPin, LOW);      // sets the Red LED off
  digitalWrite(greenPin, HIGH);   // sets the Green LED on
  delay(delayTime*5);             // waits the delayTime * 5
  digitalWrite(yellowPin, HIGH);  // sets the Yellow LED on
  digitalWrite(greenPin, LOW);    // sets the Green LED off
  delay(delayTime);               // waits the delayTime
  digitalWrite(yellowPin, LOW);   // sets the Yellow LED off (and continue the loop)
}

If you have any experience with programming at all, the Arduino should be pretty easy. If you don’t, it will take a bit more work, but it’s still doable. Give it a try!

Share Button
Be Sociable, Share!

Comments

Comment from M4rc3lv
Time 12/12/2011 at 1:50 am

The code is very well commented :-)

Comment from Dave
Time 12/14/2011 at 6:22 pm

Now add crosswalk buttons.

Write a comment






three + 6 =