Skip Navigation

Arduino Traffic Lights

By Nabeela Merchant 60 minutes
Grades 9-12
Science and Technology,
  • Programming
  • Technology and Society
Tools & Languages

Key Coding Concepts

  • Functions
  • Loops
  • Variables



A board used to build electric circuit models.


A component that regulates the flow of an electric circuit.


A light-emitting diode (LED) emits visible light when an electric circuit passes through it.  

In this activity, students will create a working model of a traffic light using an Arduino Uno microcontroller and some electronics.

Materials (per pair):

  • Laptop with administrator permissions
  • Arduino Create account
  • Arduino Uno
  • A B USB cable (USB printer cable) to connect the the Arduino Uno to the laptop
  • Some basic electronics:
    • Breadboard
    • Wires
    • 1000 ohm resistors x3
    • A red, yellow, and green LED

Use the following slides for this lesson:


Traffic lights are used all over the world to control the flow of traffic. The first traffic light was installed in London in 1868, before cars were created, to control the movement of horse carriages in the area, so pedestrians could safely cross the road. These original traffic lights had only two colours, red for stop and green for go. The three coloured traffic lights we know today weren’t introduced till 1920.

Traffic lights are great examples of simple robotic systems that have had profound effects on society.

Using the Arduino Uno and a simple circuit, we will create a model of a three coloured traffic light. The circuit will consist of three lights - green, yellow, and red - that are each connected to the Arduino Uno. The traffic light will be green for 5 seconds, yellow for 1.5 seconds, and red for 3 seconds.

Code Along

Open up the example project and show learners the code and physical output (blinking LED on a circuit board).

Point out the main elements of the circuit: breadboard, LED, resistor, wires, digital pin 8 for power on the Arduino Uno, GND on the Arduino for the electrical ground.

Have the learners pair up. Assign each pair one of the elements of the circuit to research. The learners have 5 minutes to research their electrical component and explain it to the class.

Walk through each of the components with the class to ensure understanding.

Show the learners the code for the example project. Notice that the code is very similar to the Arduino Lesson 1 example project, Blink. The main differences are the variable “light” and the setup function. Instead of setting up the built-in LED on the Arduino Uno, we are setting up digital pin 8, which is called “light”, where the LED from our circuit is connected.

Check for understanding by asking learners what would happen if you change the value of ‘light’ from 8 to 9?

Demonstrate the effect of changing the value of the the variable ‘light’ in the code. This should result in no lights blinking in the circuit as we are now changing the value of digital pin 9, which is not connected to anything. Don’t forget to verify and upload the code each time you want to show learners the effect of the change.


In this activity, you’ll create a working model of a traffic light.

Use the Solution Sheet ( to guide learners through the following steps:

  1. Gather the materials for the project.
  2. Write out a detailed sequence of instructions of how each light should work.
  3. Build the circuit.
  4. Connect the Arduino Uno to the computer.
  5. Open up the Traffic Light project.
  6. Fill out the remaining commands to turn on and off the lights in the right order.
  7. Check the code.
  8. Verify and upload the code to the Arduino Uno.

After reviewing the example project, co-construct success criteria with the class to be used to evaluate their final projects.

Have learners research the following programming concepts and explain how they used them in their project: Variables, Functions, Loops

Program a 4 stage traffic light with the following pattern:

  1. Red for 3 seconds
  2. Red and yellow for 1.5 seconds
  3. Green for 5 seconds
  4. Yellow for 1.5 seconds
  5. These four stage traffic lights are used in Britain and use the same 3 colours while letting drivers know when the light will turn green.

Text-based coding, digital output devices, electronics, components of an electric circuit, electrical components, PCB (printed circuit boards), input/output devices, microcontrollers, communication, impacts of technology on societies

Teach lessons that are tied to your existing curriculum!


More Lesson Plans For Grades 9-12

    View All Lesson Plans

    Explore lessons based on components

    The K-12 Computer Science Framework

    Although learning how to build digital projects is a key part of Computer Science education, students should also learn a wider set of skills and competencies that will help them to harness the power of digital technologies as both creators and consumers. A comprehensive approach to K-12 Computer Science education includes learning about the following five focus areas:

    View Framework ➝


    By the end of high school, students should be able to create a simple computer program.

    Computing and Networks

    By the end of high school, students should understand and be able to use the tools and devices commonly used to build digital projects.


    By the end of high school, students should be able to explain how we use computers to create, store, organize, and analyze data.

    Technology and Society

    By the end of high school, students should be able to explore the ways in which technology and society have mutually shaped each other.


    By the end of high school, students should be able to apply design principles to the digital projects they create.