int greenRight = 2; // Declaring greenRight as an int, and set it to 2
int yellowRight = 3; // Declaring yellowRight as an int, and set it to 3
int redRight = 4; // Declaring redRight as an int, and set it to 4
int greenBottom = 5; // Declaring greenBottom as an int, and set it to 5
int yellowBottom = 6; // Declaring yellowBottom as an int, and set it to 6
int redBottom = 7; // Declaring redBottom as an int, and set it to 7
int greenLeft = 8; // Declaring greenLeft as an int, and set it to 8
int redLeft = 9; // Declaring redLeft as an int, and set it to 9
int yellowLeft = 10; // Declaring yellowLeft as an int, and set it to 10
int redTop = 11; // Declaring redTop as an int, and set it to 11
int yellowTop = 12; // Declaring yellowTop as an int, and set it to 12
int greenTop = 13; // Declaring greenTop as an int, and set it to 13
void setup() {
pinMode(greenRight, OUTPUT);
pinMode(yellowRight, OUTPUT);
pinMode(redRight, OUTPUT);
pinMode(greenBottom, OUTPUT);
pinMode(yellowBottom, OUTPUT);
pinMode(redBottom, OUTPUT);
pinMode(greenLeft, OUTPUT);
pinMode(redLeft, OUTPUT);
pinMode(yellowLeft, OUTPUT);
pinMode(redTop, OUTPUT);
pinMode(yellowTop, OUTPUT);
pinMode(greenTop, OUTPUT);
digitalWrite(redLeft, HIGH); // Turns left red LED on
digitalWrite(redRight, HIGH); // Turns right red LED on
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(redTop, LOW); // Turns top red LED off
digitalWrite(redBottom, LOW); // Turns bottom red LED off
digitalWrite(greenTop, HIGH); // Turns top green LED on
digitalWrite(greenBottom, HIGH); // Turns bottom green LED on
delay(20000); // 20s delay - green light top and bottom
digitalWrite(greenTop, LOW); // Turns top green LED off
digitalWrite(greenBottom, LOW); // Turns bottom green LED off
digitalWrite(yellowTop, HIGH); // Turns top yellow LED on
digitalWrite(yellowBottom, HIGH); // Turns bottom LED on
delay(5000); // 5s delay - yellow light top and bottom
digitalWrite(yellowTop, LOW); // Turns top yellow LED off
digitalWrite(yellowBottom, LOW); // Turns bottom yellow LED off
digitalWrite(redTop, HIGH); // Turns top red LED on
digitalWrite(redBottom, HIGH); // Turns bottom red LED on
delay(2000); // 2s delay - all red
digitalWrite(redLeft, LOW); // Turns left red LED off
digitalWrite(redRight, LOW); // Turns right red LED off
digitalWrite(greenLeft, HIGH); // Turns left green LED on
digitalWrite(greenRight, HIGH); // Turns right green LED on
delay(20000); // 20s delay - green light left and right
digitalWrite(greenLeft, LOW); // Turns left green LED off
digitalWrite(greenRight, LOW); // Turns right green LED off
digitalWrite(yellowLeft, HIGH); // Turns left yellow LED on
digitalWrite(yellowRight, HIGH); // Turns right yellow LED on
delay(5000); // 5s delay - yellow light left and right
digitalWrite(yellowLeft, LOW); // Turns left yellow LED off
digitalWrite(yellowRight, LOW); // Turns right yellow LED off
digitalWrite(redLeft, HIGH); // Turns left red LED on
digitalWrite(redRight, HIGH); // Turns right red LED on
delay(2000); // 2s delay - all red
}
Welcome to the community.
You seem to have posted before you had a chance to type your question.
That's OK, you can go back and modify it to add the question.
Thank you both for letting me know. I thought this is where to post cool projects or see other projects for inspiration. My only question is what is a good project using Arduino Uno to start out on for beginners?
Would you not want to carry on with your traffic light project
You could accommodate your sketch to support buttons.
For example, one that pressed at any time, directly switches the lights to yellow,
blinking in all directions, until that button is pressed again,
or one that allows pedestrians to stop the traffic to cross the street.
That's fine; just make it clear that it's your completed project. You can also move it to Exhibition / Gallery - Arduino Forum; you might get some comments about the use of delay and I think that @Whandall is pointing at that.
I will attempt to add buttons, sensors, and timers to advance this project
I would suggest that you don't hop on the library-train
before you are able to handle the timing by using millis() yourself.
I think you are eager to learn some concepts,
not how to use some libraries.
This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.