Getting Started With Arduino - Switched Traffic Light

About: Tutorials provided by BA/BSc (Hons) Digital Art and Technology at Plymouth University

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

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: 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

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

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

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

Be the First to Share


    • Made with Math Contest

      Made with Math Contest
    • Multi-Discipline Contest

      Multi-Discipline Contest
    • Robotics Contest

      Robotics Contest

    5 Discussions


    4 years ago on Introduction

    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.

    1 reply

    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.


    4 years ago on Introduction

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