3D printed Arduino Traffic Lights
A little bit off topic for the 3D printer community , but then again maybe not , for those of you who design and create 3D models then this little blog will enable you to create Traffic lights simulator on a breadboard – insert some light emitting diodes , do some cabling and program the arduino.
If you are into modelling then you could design and print the traffic lights once you understand how it all goes together.
Traffic Light design and stl files
Instructions
Print out all the pieces and super glue them together. Place a battery in the base with one wire going from ground and three wires going from power. Connect each of the three powers to a different color 10″ LED, and connect the ground to a snap. Solder a ground wire to each of the LEDs and connect each of these ground wires to a snap. Bring all the LEDs and wires through the traffic pole and then super glue each of the lights into one of the three holes in the head. Have all the snaps coming out the of hole in the back of the head so they can be connected together and the LEDs will light up.
Click here to download the .STL Traffic lights <–
Brief history of Traffic Lights
Traffic lights, also known as traffic signals, traffic lamps, traffic semaphore, signal lights, stop lights, and (in technical parlance)traffic control signals, are signalling devices positioned at road intersections, pedestrian crossings, and other locations to control conflicting flows of traffic.
The world’s first, manually operated gas-lit traffic signal was short lived. Installed in London in December 1868, it exploded less than a month later, injuring or killing its policeman operator. The first safe, automatic electric traffic lights were installed in the United States in the late 1890s.
Traffic lights alternate the right of way accorded to road users by displaying lights of a standard colour (red, yellow, and green) following a universal colour code. In the typical sequence of colour phases:
- The green light allows traffic to proceed in the direction denoted, if it is safe to do so and there is room on the other side of the intersection.
- The yellow (or amber) light warns that the signal is about to change to red. In a number of countries – among them the United Kingdom – a phase during which red and amber are displayed together indicates that the signal is about to change to green. Actions required by drivers on an amber light vary, with some jurisdictions requiring drivers to stop if it is safe to do so, and others allowing drivers to go through the intersection if safe to do so.
- A flashing yellow indication is a warning signal. In the United Kingdom, a flashing amber light is used only at pelican crossings, in place of the combined red–amber signal, and indicates that drivers may pass if no pedestrians are on the crossing.
- The red signal prohibits any traffic from proceeding.
- A flashing red indication is treated as a stop sign.
- In some countries traffic signals will go into a flashing mode if the controller detects a problem, such as a program that tries to display green lights to conflicting traffic. The signal may display flashing yellow to the main road and flashing red to the side road, or flashing red in all directions. Flashing operation can also be used during times of day when traffic is light, such as late at night.ProcessWhat I will be going through is the coding first using the arduino ide , followed by breadboarding the circuit ,followed by connecting the arduino and the breadboard together and running the compiled code.plus a parts list.Parts List1 x Arduino1 x Small breadboard7 x Jumper cables3 x Led’s in Red , Yellow , and Green3 x 220 ohm resistors1 x cable to connect your arduino to your computerAnd the arduino ide from www.arduino.ccThe Arduino
I would guess that most of you use an arduino to control your 3D printer with a firmware sketch for Marlin or Repetier – There are others out there plus if you a programmer you could create your own.using C or C++ which the ide supports.
The arduino ide automatically checks for programming errors , if you have a problem it will give a brief error message and which line is effected.
Once you have a working program the sketch is compiled and uploaded to your arduino – overwriting whatever is on your arduino.
Please note – do not use the arduino that runs your printer because you cannot extract the contents .!!
A little bit about the arduino – basically it has loads of pins available for use which basically can be used as inputs and outputs.
As a default the arduino makes all pins “inputs” as a standard so when programming if you forget to state what you want the program will still compile but not work.
The Program
Create a new sketch and name it TrafficLightSimulator
This is what the sketch looks like with no code.
void setup() {
// put your setup code here, to run once:}
void loop() {
// put your main code here, to run repeatedly:}
You need to add all the variables next
int red = 13; // pin being used for output to red led
int amber = 12; // pin being used for output to amber led
int green = 11; // pin being used for output to green ledA quick note about pins – their state is either HIGH meaning a signal goes to them or LOW meaning no signal.
Setup pins
pinMode(red,OUTPUT);
pinMode(amber,OUTPUT);
pinMode(green,OUTPUT);Loop that makes it all work with timings for the light changes , in the delay setting 1000 = one minute.
ChangeLights();
delay(15000);The Full sketch
int red = 13;
int amber = 12;
int green = 11;void setup() {
// put your setup code here, to run once:
pinMode(red,OUTPUT);
pinMode(amber,OUTPUT);
pinMode(green,OUTPUT);
}oid loop() {
// put your main code here, to run repeatedly:
changeLights();
delay(15000);
}void changeLights(){
// green off, amber on for 3 seconds
digitalWrite(green,LOW);
digitalWrite(amber,HIGH);
delay(3000);//turn off amber ,then turn red on for 5 seconds
digitalWrite(amber,LOW);
digitalWrite(red,HIGH);
delay(5000);//red and amber on for 2 seconds (red is already on)
digitalWrite(amber,HIGH);
delay(2000);//Turn off red and amber , then turn on green
digitalWrite(amber,LOW);
digitalWrite(red,LOW);
digitalWrite(green,HIGH);
}I have put in as many comments as to what is going on.
So save the file and press the tick to verify all is well it will say DONE COMPILING and you will see in the terminal window.
Sketch uses 1,204 bytes (3%) of program storage space. Maximum is 30,720 bytes.
Global variables use 15 bytes (0%) of dynamic memory, leaving 2,033 bytes for local variables. Maximum is 2,048 bytes.Click upload and it gets sent to the arduino.
Building the circuit
If you are new to electronics just following the diagram below
Download the files by clicking the picture below!
Once my new video camera arrived I will update the post with a videoThanks for dropping by , If there is another arduino related project that you would like me to cover , let me know.
One thought on “Arduino based Traffic Light Simulator”
Sounds like a great little project! I haven’t tried out any of the boards yet (Arduino, pi) but it looks to be really fun and interesting. I imagine, knowing how to rig up some boards and having a 3D printer opens up a whole new world of projects to a person! You have your own little factory in your house! What we can do now alone took a huge factory decades ago! I remember as a kid, I would go into my grandfather’s workshop and try to make robots using his copper wire and junk laying around. I didn’t know what the heck I was doing. Being only 5 years old though it was still fun until I tried to plug in one of the wires to a robot into the wall outlet!!! Luckily the breaker switch flipped and I didn’t get electrocuted to death!! I wish we had all this new stuff when I was a kid! But it’s still fun for a grown up!! Plus we can make some awesome robots! haha