Stoplight: Green-Yellow-Red

Project Description 
Utilizing arduino code and LEDs to model a stoplight system.

Brainstorming & Planning
The first weeks arduino practice focused on controlling LEDs via the arduino. The kit that I purchased included yellow and red LEDs and as I began to play around with them I was reminded of a stoplight. Missing one color, I recalled that my kit included a multicolor LED. Upon further inspection I realized that one of its legs produced green. I hooked it up (using the green leg and common ground leg) in the same way that I had utilized the yellow and red LEDs.

Making Process & Pictures


Final Video


Video Description
The video shows my stoplight system at work. Green is lit for 5s, Yellow for 3s, Yellow flashes for 3s, and Red is lit for 5s. You will notice that the green LED is much brighter because it is a different type compared to the yellow and red LEDs.

Final Code
/*
 Name: Travis Ray
 Date: Nov 2, 2018
 Course: Makerspaces

 Task Description:
Models a stoplight


 Pseudocode:
Green on for 5
Yellow on for 3
Yellow flashes 3 times
Red on for 5

 */

int ledY = 13; //Yellow LED plugged into 13
int ledR = 12; //Red LED plugged into 12
int ledG = 11; //Green LED plugged into 11


void setup() {
  pinMode(ledY, OUTPUT); //Initialize digital pin out as an output
  pinMode(ledR, OUTPUT); //Initialize digital pin out as an output
  pinMode(ledG, OUTPUT); //Initialize digital pin out as an output

}



void loop() {
  //Green on for 5 seconds
digitalWrite(ledG, HIGH); //Turn on Green LED
delay(5000);              //5 seconds wait
digitalWrite(ledG, LOW);  //turn off green

//Yellow on for 3 seconds, solid
digitalWrite(ledY, HIGH); //Turn Yellow on
delay(3000);              //3 second wait
digitalWrite(ledY, LOW);  //Turn yellow off
delay(500);

//yellow flash on/off for 3 seconds (half second for each flash)
digitalWrite(ledY,HIGH);
delay(500);
digitalWrite(ledY, LOW);
delay(500);
digitalWrite(ledY,HIGH);
delay(500);
digitalWrite(ledY, LOW);
delay(500);
digitalWrite(ledY,HIGH);
delay(500);
digitalWrite(ledY, LOW);
delay(500);

//Red on for 5 seconds
digitalWrite(ledR,HIGH);
delay(5000);
digitalWrite(ledR, LOW);
 

}


Reflection
This project utilized the code and techniques we have used up to this point. Having taught robotics before, LEDs are the easiest starting location, but it can also prove tedious or boring for the students. I try to spice it up by expanding the activities to model a real-life example. In this case I wanted to model a stoplight. I didn't have any issues with the coding. The only problem I ran into was that I forgot to connect my ground wire to the left side of my board (it was connect to the right side for my earlier activities).

I could expand this project to include multiple sets of lights, modeling an intersection, or by adding a button control, modeling a crosswalk. I could also take a different approach and use the LEDs to signal morse code.

Comments

  1. How cool that you extended our project into an application like a stop light.
    -TLong

    ReplyDelete

Post a Comment

Popular posts from this blog

Week 3: Times Square and Multiple Inputs