Arduino Street Robot
Arduino Street Robot
Arduino Street Robot
Equipment
The equipment I have used in this Arduino traffic light
project is listed right below.
Recommended
Arduino Uno ( Amazon | SunFounder )
Red LED ( Amazon | SunFounder ), Yellow
LED ( Amazon | SunFounder ), and Green
LED ( Amazon | SunFounder )
3 x 100 Ohm resistor ( Amazon | SunFounder ) (Color =
Brown Black Brown)
Breadboard wire ( Amazon | SunFounder )
Breadboard ( Amazon | SunFounder )
Video
Below is a short video that goes through all the steps to
assembling and running the traffic lights using the Arduino.
A much more detailed written version of the tutorial is right
underneath the video.
Arduino Traffic Light Project
0 seconds of 3 minutes, 28 seconds
int GREEN = 2;
int YELLOW = 3;
int RED = 4;
// basic functions
void setup()
pinMode(GREEN, OUTPUT);
pinMode(YELLOW, OUTPUT);
pinMode(RED, OUTPUT);
The loop function creates a loop that the program will run
through, so every time we call a function, it will turn a light
on and then we can set a delay, so it doesn’t change until
that time is up.
void loop()
{
green_light();
delay(DELAY_GREEN);
yellow_light();
delay(DELAY_YELLOW);
red_light();
delay(DELAY_RED);
void green_light()
{
digitalWrite(GREEN, HIGH);
digitalWrite(YELLOW, LOW);
digitalWrite(RED, LOW);
void yellow_light()
digitalWrite(GREEN, LOW);
digitalWrite(YELLOW, HIGH);
digitalWrite(RED, LOW);
void red_light()
digitalWrite(GREEN, LOW);
digitalWrite(YELLOW, LOW);
digitalWrite(RED, HIGH);
Once you are done writing the code, you will need to
upload it to the Arduino using the USB cable that should
have come with your kit. The lights should start to blink in
the pattern that we have defined using the function calls
and the delays.
You should always test your code before uploading it to the
Arduino, you can do this by clicking the verify button (Tick).
This will let you know if there are any errors in your code
and allows you to make changes so that it is correct.
I hope you have enjoyed this Arduino traffic light project if
you have any questions, comments, then please don’t
hesitate to leave a comment below.