drhm
Published © GPL3+

Mini Traffic Light

It's like a traffic light, right? But tiny. Complete with the long waits and everything.

BeginnerShowcase (no instructions)971
Mini Traffic Light

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
5 mm LED: Red
5 mm LED: Red
×2
5 mm LED: Green
5 mm LED: Green
×2
5 mm LED: Yellow
5 mm LED: Yellow
×1
Breadboard (generic)
Breadboard (generic)
×1
Resistor 10k ohm
Resistor 10k ohm
Only necessary if you use a small breadboard, like me.
×1
Resistor 2.21k ohm
Resistor 2.21k ohm
×5
Push Button
I will be honest, mine didn't work
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Circuit

A picture of my circuit, and the link to it

Code

Schoolwork.ino

C/C++
This is... just the whole thing. This is all the code.
int ledPin = 14;              //set the LED pin to 14 (used for the loop)
int loopTimes = 6;              //set the first loop to go 6 times
int butState = 0;             //Button State Variable
                      //
void setup(){               //
  while (loopTimes > 0){          //Repeat until loopTimes is 0, in this case 6 times
    ledPin -= 1;            //go to the next LED pin (why I started at 14)
    pinMode(ledPin, OUTPUT);      //set the LED pin to an output
        digitalWrite(ledPin, LOW);      //make sure it's off (can never be too safe)
        loopTimes -= 1;}          //go to the next iteration of the loop
    loopTimes = 2;              //set the next loop to go twice
  pinMode(7, INPUT);            //set the Button as an input
}                     //
                      //
void loop(){                //
  ledPin = 9;               //select the pedestrian red light
  digitalWrite(ledPin, HIGH);       //turn the LED on
  ledPin = 13;              //select the car green light
  digitalWrite(ledPin, HIGH);       //turn the LED on
    butState = digitalRead(7);        //get the state of the button
    if (butState==1){           //if the button is pressed, begin the sequence
    delay (6000);           //wait 6 seconds
        while (loopTimes > 0){        //Repeat until loopTimes is 0, in this case twice
      delay(2000);          //wait 2 seconds
      digitalWrite(ledPin, LOW);    //turn the LED (starting w/ car green light) off
      ledPin -= 1;          //move to the next LED
      digitalWrite(ledPin, HIGH);   //turn the LED on
            loopTimes -= 1;}        //go to the next iteration of the loop
        loopTimes = 5;            //set the next loop to go 5 times
    ledPin = 9;             //select the Pedestrian Red Light
    digitalWrite(ledPin, LOW);      //turn the LED off
    ledPin = 8;             //select the Pedestrian Green Light
    digitalWrite(ledPin, HIGH);     //turn the LED on
    delay(4000);            //wait 4 second
    digitalWrite(ledPin, LOW);      //turn the LED off
    ledPin = 9;             //select the Pedestrian Red Light
    digitalWrite(ledPin, HIGH);     //turn the LED on
        while (loopTimes > 0){        //Repeat until loopTimes is 0, in this case 5 times
      delay(200);           //wait 0.2 seconds
      digitalWrite(ledPin, LOW);    //turn the LED off
      delay(200);           //wait 0.2 seconds
            digitalWrite(ledPin, HIGH);   //turn the LED on
            loopTimes -= 1;}        //go to the next iteration of the loop
      loopTimes = 2;            //set the next loop to go twice
    ledPin = 11;            //select the Car Red Light
    digitalWrite(ledPin, LOW);}     //set the LED to off
}                     //

Credits

drhm

drhm

0 projects • 0 followers

Comments