Introduction: Getting Started With Arduino - Switched Traffic Light

Picture of Getting Started With Arduino - Switched Traffic Light

In this tutorial we are going to build a set of traffic lights (with Green, Amber and Red LEDs)

We'll use a 3 way switch to control which light is lit.

For reference, the switch we will be using is a 3 pin ON-OFF-ON switch

Step 1: Wire Up Your Arduino

Picture of Wire Up Your Arduino

Connect an orange wire to pin 8 and a blue wire to pin 7 (these will be the switch wires)

Connect red, yellow and green wires to pins 1, 2 and 3 (these will be the LED wires)

Step 2: Connect Your Switch

Picture of Connect Your Switch

Connect the blue wire from pin 7 on the arduino to the left hand contact on the 3-way switch

Connect the orange wire from pin 8 on the arduino to the right hand contact on the 3-way switch

Connect the centre pin on the 3-way switch back to one of the ground (GND) pins on the arduino

Step 3: Connect Your LEDs

Picture of Connect Your LEDs

The next step is to connect your LEDs. Depending on the type of LED you are using, you might need to add some resistors as described in step 1 of this instructable. Once your LEDs are ready...

Connect the red wire from pin 1 on the arduino to the positive (long) leg of the red LED.

Connect the yellow wire from pin 2 on the arduino to the positive (long) leg of the yellow/amber LED.

Connect the green wire from pin 3 on the arduino to the positive (long) leg of the green LED.

Connect the all negative (short) legs on the LEDs to one of the ground (GND) pins on the arduino.

See the schematic diagram for a configuration of LEDs that uses the minimum number of wires

(paying close attention to the + and - signs on each LED)

Step 4: Write Your Code

The next step is to write some code to control the LEDs.

Download the TrafficLights.ino file and open it up in the Arduino application.

You can tinker with it if you like, or just use it as it is.

For an explanation of INPUT_PULLUP see step 2 of this instructable.

Step 5: Enjoy

Picture of Enjoy

If everything worked, you should be able to upload your code onto the arduino and control the LEDs with the switch (switching between green, amber and red)

If you enjoyed this instructable, check out our other tutorials

If you love this kind of stuff, check out our degree


candyrabbit (author)2015-07-13

What kit did you buy

TCSC47 (author)2015-07-08

I don't think it is good enough to simply say that a resistor "may" be needed in series with each LED. People seem to be able get away with this for the Arduino presumably because of the 40mA sink/source limit (?) or because they have programmed a PWM. However, it is not a good idea. A lot of your audience, for a simple project like this, will be new to electronics, so you are doing them no favours in allowing them to go away thinking that LEDs may not need some form of current limit. I have followed your link to another instructable using an LED current limiting resistor and I am not impressed with it either.

It all depends on the specification of your the LED - some will need a resistor when connected to an arduino, others will be fine without. There are plenty of web pages out there that will help calculate the correct value for the resistor (for example But it's often quicker just to try it without and see what happens (especially if you don't know the spec of your LED). If it pops (or seem very bright) then it's time to try a resistor.

shyamrajan26 (author)2015-07-08

Thanks for let me start with my favourite choice. You have done a great job.

MotherOfMine1 (author)2015-07-07


About This Instructable




Bio: Tutorials provided by BA/BSc (Hons) Digital Art and Technology at Plymouth University
More by Digital Art and Technology:Green space activity monitorPython Micro:bit Light ShowJumpstarting a Hot-glued Arduino
Add instructable to: