Introduction: Break Lights

My project is kind of a traffic light, it can be useful in schools, like in the little kids's classrooms. For example, they have a break that starts 09:00 and they need to be in the classroom by 09:20, but they can't look at the clock and see the time remaining because they don't know how to tell the time.

The traffic light goes green when the break starts and then when the break is over, the green light goes off and the yellow light goes on.

In this Instructables I'm going to teach you how to make one of these.

Just follow the steps and I hope you like it!

Step 1: Materials

Here is a list of all the things you need to begin (there are pictures of the materials above):

- Two (2) LEDs (a yellow and a green)

- Nine (9) jumper wires

- One (1) breadboard

- One (1) arduino

- Three (3) resistors (the 6 X 220 kind)

- One (1) pushbutton switch

- One (1) cable to connect the arduino into the computer

You need to connect the long leg of each LED to digital pins eight, nine, and ten on the arduino.And connect the short leg of the LEDs to Arduino ground.

You also need to connect the wires corresponding to the pushbutton in the digital pin 12

There is a picture of what your arduino should look like above

Step 2: The Code

I know how difficult is to create a code but I created a code for this type of of project. Here it is:

int yellow = 9;
int green = 8;

int button = 12; // switch is on pin 12

void setup(){

pinMode(yellow, OUTPUT);

pinMode(green, OUTPUT);

pinMode(button, INPUT);

digitalWrite(green, HIGH);

pinMode(yellow, OUTPUT);

pinMode(green, OUTPUT); }

void loop(){

if (digitalRead(button) == HIGH){

delay(15); // software debounce

if (digitalRead(button) == HIGH) {

// if the switch is HIGH, ie. pushed down - change the lights!

changeLights();

//delay(15000); // wait for 15 seconds

}

}

}

void changeLights(){

// green off, yellow on for 3 seconds

digitalWrite(green, LOW);

digitalWrite(yellow, HIGH);

delay(3000);

// turn off green, then turn yellow on for 5 seconds

digitalWrite(yellow, HIGH);

digitalWrite(green, LOW);

delay(500);

// green and yellow on for 2 seconds (yellow is already on though)

digitalWrite(green, HIGH);

delay(200);

// turn off yellow, then turn on green

digitalWrite(yellow, LOW);

digitalWrite(green, HIGH);

delay(300); }

Step 3: Other Information:

My code was inspired by another code form a website called "Make use of".

But instead of two lights, it uses three (red, yellow and green).

This the link, if you want to check it out, it's really cool!

https://www.makeuseof.com/tag/arduino-traffic-ligh...

Also if you need/want the lights to change slower or faster, you just have to change the numbers in the parenthesis right after “delay”, so if you want the lights to change at every 15 seconds, you need to write “delay (15000)” or if you want for 5 seconds, you have to write “delay (500)”. There has to be zeros after the number of seconds.

On the website, there is a video of what the project should look like

That's it,

Hope you enjoyed, thanks for reading

Bye