Simple Arduino Traffic Lights

77,707

82

18

Introduction: Simple Arduino Traffic Lights

Have you ever made a city out of Legos? I know i have built many of them but they all missed something... Traffic lights!
So i decided to make my very own traffic light setup from my arduino board.

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: You Will Need:

You will need:

An arduino board
Red, Green and amber LED's
Three 220 Ohm Resistors

Optional:

Wire
and an Protoshield

Step 2: Get the Components

I assume you already have an adruino board, and maybe also a Protoshield.

You'll need the LED's and resistors

the 220 Ohm resistors are color coded so: Red, Red, Brown

Step 3: Hook Up to the Board

Since this is a really simple project we only need 3 digital pins and ground.

Put the LED's in the breadboard/protoboard and use the resistors to connect them to the digital pins,

Green to pin 8
Yellow to pin 9
and Red to pin 10

then connect all the negative pins of the LED's together and to ground.

Step 4: Upload the Code!

Again, since this is a really simple project the code is also simple,
just copy it from below and upload it to your board via USB.

int greenled = 8; //Led's and pins
int yellowled = 9;
int redled = 10;

void setup()
{
pinMode(greenled, OUTPUT); //Pinmodes of the leds
pinMode(yellowled, OUTPUT);
pinMode(redled, OUTPUT);
}

void loop()
{
digitalWrite(greenled, HIGH); //Green on for 5 seconds
delay(5000);
digitalWrite(greenled, LOW); //Green off, yellow on for 2 seconds
digitalWrite(yellowled, HIGH);
delay(2000);
digitalWrite(yellowled, LOW); //yellow off, red on for 5 seconds
digitalWrite(redled, HIGH);
delay(5000);
digitalWrite(yellowled, HIGH); //Yellow and red on for 2 seconds
delay(2000);
digitalWrite(redled, LOW); //Red and Yellow off
digitalWrite(yellowled, LOW);
}

Step 5: Watch Your Traffic Being Controlled :)

Now you can see your very own traffic lights, control traffic.
the lights change according to European standards.

2 People Made This Project!

Recommendations

  • Backyard Contest

    Backyard Contest
  • Silly Hats Speed Challenge

    Silly Hats Speed Challenge
  • Finish It Already Speed Challenge

    Finish It Already Speed Challenge

18 Discussions

0
SakthiV44
SakthiV44

Question 1 year ago on Introduction

Can you make a traffic light with switch as first time first light should glow and so on i need it please please try to make one

0
JanM193
JanM193

2 years ago

Hi,

Now that's a cool breadboard you have!

Can you tell me where you bought it?

I definately want to buy one :)

Thanks and greets from Holland.

Jan

0
Muhd ShahrizanC
Muhd ShahrizanC

3 years ago

i would like to make traffic light using red and green light only.

so, shoud i just delete the amber color ?? need help here. thank you

0
lmangione
lmangione

4 years ago

this is the screenshot

Immagine.png
0
ochâtelain
ochâtelain

4 years ago on Introduction

Nice build, wrote nearly the same too ;-). Only modification: Make the delay variable for impatient kids or realistic crowded cities.

void loop() {

// WAIT

digitalWrite(RED, HIGH);

digitalWrite(YELLOW, LOW );

digitalWrite(GREEN, LOW );

delay(DELAY*3);

// START

digitalWrite(RED, HIGH);

digitalWrite(YELLOW, HIGH );

digitalWrite(GREEN, LOW );

delay(DELAY);

// GO

digitalWrite(RED, LOW );

digitalWrite(YELLOW, LOW );

digitalWrite(GREEN, HIGH);

delay(DELAY*2);

// STOP

digitalWrite(RED, LOW );

digitalWrite(YELLOW, HIGH );

digitalWrite(GREEN, LOW);

delay(DELAY);

}

0
OWH
OWH

5 years ago on Introduction

Had fun building the double traffic lights. I changed the code to work like actual traffic lights. Here is the change.

int g1 = 8;
int y1 = 9;
int r1 = 10;
int r2 = 13;
int y2 = 12;
int g2 = 11;
void setup()
{
pinMode(g1, OUTPUT);
pinMode(y1, OUTPUT);
pinMode(r1, OUTPUT);
pinMode(r2, OUTPUT);
pinMode(y2, OUTPUT);
pinMode(g2, OUTPUT);
}
void loop()
{
digitalWrite(r1, HIGH);
digitalWrite(g2, HIGH);
delay(8000);
digitalWrite(g2, LOW);
digitalWrite(y2, HIGH);
delay(6000);
digitalWrite(y2, LOW);
digitalWrite(r2, HIGH);
delay(50);
digitalWrite(r1,LOW);
digitalWrite(g1, HIGH);
delay(8000);
digitalWrite(g1, LOW);
digitalWrite(y1, HIGH);
delay(6000);
digitalWrite(y1, LOW);
digitalWrite(r1, HIGH);
delay(50);
digitalWrite(r2,LOW);
}

0
spike1998
spike1998

5 years ago on Introduction

its a lot of fun this project if made it i also made a double traffic light here is the code for it

#define DELAYg 2000

#define DELAYy 1000

#define DELAYr 2500

int g1 = 8;

int y1 = 9;

int r1 = 10;

int r2 = 13;

int y2 = 12;

int g2 = 11;

void setup()

{

pinMode(g1, OUTPUT);

pinMode(y1, OUTPUT);

pinMode(r1, OUTPUT);

pinMode(r2, OUTPUT);

pinMode(y2, OUTPUT);

pinMode(g2, OUTPUT);

}

void loop()

{

digitalWrite(r1, HIGH);

digitalWrite(g2, HIGH);

delay(DELAYg);

digitalWrite(g2, LOW);

digitalWrite(y2, HIGH);

delay(DELAYy);

digitalWrite(y2, LOW);

digitalWrite(r2, HIGH);

delay(DELAYr);

digitalWrite(r1,LOW);

digitalWrite(g1, HIGH);

delay(DELAYg);

digitalWrite(g1, LOW);

digitalWrite(y1, HIGH);

delay(DELAYy);

digitalWrite(y1, LOW);

digitalWrite(r1, HIGH);

delay(DELAYr);

digitalWrite(r2,LOW);

}

0
billbillt
billbillt

6 years ago on Introduction

great... for me, I found an amber LED looks a more natural color for this..

0
biomech75
biomech75

8 years ago on Step 3

Nice job ...but here is the fix for the red,yellow, green. It is incorrect The traffic lights goes as follows green, yellow,red... then red,green (not red,yellow.green).
Enjoy;)
CODE:

int greenled = 8; //Led's and pins
int yellowled = 9;
int redled = 10;

void setup()
{
pinMode(greenled, OUTPUT); //Pinmodes of the leds
pinMode(yellowled, OUTPUT);
pinMode(redled, OUTPUT);
}

void loop()
{
digitalWrite(greenled, HIGH); //Green on for 5 seconds
delay(5000);
digitalWrite(greenled, LOW); //Green off, yellow on for 2 seconds
digitalWrite(yellowled, HIGH);
delay(2000);
digitalWrite(yellowled, LOW); //yellow off, red on for 5 seconds
digitalWrite(redled, HIGH);
delay(5000);
digitalWrite(redled, LOW); //Red and Yellow off
digitalWrite(yellowled, LOW);
}

0
bjarni1995
bjarni1995

Reply 8 years ago on Step 3

As I said, this is according to icelandic (european?) standards, not American

0
B2BSurvivor
B2BSurvivor

8 years ago on Introduction

Thanks again for responding. Yes, I am quite familiar with Google, and sorry if this isn't the "right place" to ask. BUT when I went to Google and found the Arduino home page, the Arduino was described as an "open source electronics prototype platform" etc. All I wanted was a simple answer, because I had no clue after reading the home page. So thanks, again. Obviously I am not an electronics hobbyist. Just trying to catch up a little on the technology. By the way, "lingo is an old slang term for "language" and "loop" is another old, outdated slang term for "information loop" or in other words, "lingo loop" would mean "techno speak", referring to the language of the "informed electronics technical people" like you.

0
B2BSurvivor
B2BSurvivor

8 years ago on Introduction

Thanks for your reply to my comment. All I meant was that I am new to some of the terminology and behind in the technology, What is an Arduino?
Thanks,
B2Bsurvivor

0
bjarni1995
bjarni1995

Reply 8 years ago on Introduction

Well, i don't think this is the right place to ask that but i'll give you the short answer. Arduino is a very popular Microcontroller among hobbyists, like me.

Hope that answers your question ad remember, "Google is your best friend"

0
B2BSurvivor
B2BSurvivor

8 years ago on Introduction

Looks like a great project. So please help me out here, I'm out of the lingo loop. What is the Arduino reference all about?

0
bjarni1995
bjarni1995

Reply 8 years ago on Introduction

Hmmm, I don't really know what you mean? "Lingo Loop" never heard of that? Help me out here so i can help you ;)

0
Robot Lover
Robot Lover

8 years ago on Introduction

Good instructable! This is great for beginner arduino users! Brotip: only one resistor is required, put it between the LED's ground and arduino ground. this helps save resistors for other projects!