Arduino SA
  • Learn @ Arduino SA
  • Arduino Introduction
  • Support
    • Setup your Computer
    • Adding Libraries
    • Setting up a ESP32
  • Arduino Robot Car
    • Arduino Bluetooth Car
      • What you will need
      • Circuit Diagram
      • Assembly the Car
      • Upload the Code
      • Bluetooth setup and Test
    • 4WD Obstacle Avoidance
      • Introduction
      • Component List
      • Assembly
      • Component Description
      • Circuit Diagram
      • Computer Setup
      • Line Tracking Mode
      • Obstacle Avoidance Mode
  • Arduino Kits
    • Smart Plant Watering Kit
      • What you will need
      • Wiring Diagram
      • The Code
      • Pics
    • Basic Starter Kit
      • Component View
      • Installing the IDE
      • Add Libraries
      • Blink
      • Button Control LED Delay Switch
      • Active Buzzer
      • Passive Buzzer
      • Servo
      • IR Remote and Receiver
      • Stepper Motor
      • Eight LED with 74HC595
      • LCD
      • Digital tube with Traffic Light Experiment
      • Four digit tube display
      • LM35D Temperature Sensor
      • LDR 5516 experiment
      • Flame Sensor
      • 8 * 8 LED Module
      • Controlling Stepper Motor With Remote
    • Super Starter Kit
      • Tutorials
    • Best Beginner Kit for Arduino
      • Tutorials
    • Uno R3 RFID Kit
    • WIFI ESP32 IOT Kit
    • Arduino School STEM Kit
    • Arduino Ultimate Starter Kit
  • Blocking Coding Lessons
    • Beginner Lessons
      • Setting up mBlock
      • Blinking an LED
      • LED Switching
      • LED Chasing
      • Traffic Signal
      • Buzzer
      • Buzzer + Push Button
      • LED + Push Button
  • Sensor Kits
    • 37-in-1 Sensor Kit
      • Joystick
      • Relay
      • Big Sound
      • Small Sound
      • Tracking
      • Avoid
      • Flame
      • Linear Hall Sensor
      • Touch
      • Digital Temperature
      • Buzzer
      • Passive Buzzer
      • RGB LED
      • SMD RGB
      • Two-Color 5mm
      • Two Color 3mm
      • Reed Switch
      • Mini Reed
      • Heartbeat
      • 7 color flash
      • Laser emitter
      • PCB mounted push Button
      • Shock switch
      • Rotary encoder
      • Light Cup
      • Tilt Switch
      • Rolling ball tilt switch
      • Photoresistor
      • Temp and Humidity
      • Analog Hall
      • Hall Magnetic
      • Temp
      • Analog Temp
      • IR Emission
      • IR Receiver
      • Tap Module
      • Light blocking
Powered by GitBook
On this page
  • What will we do
  • Parts List
  • Wiring it up
  • How does it work
  • Block Coding

Was this helpful?

  1. Blocking Coding Lessons
  2. Beginner Lessons

Traffic Signal

What will we do

This example uses three LEDs to make a model traffic light signal. You can use all red LEDs if you like, but its more realistic if you use red, yellow and green.

The LEDs cycle around in the sequence red, green, yellow and then back to red again

Parts List

You will need the following parts:

  • 1x arduino uno

  • 1x arduino uno USB Cable

  • 1x Breadboard

  • 4x Jumper Wire

  • 1x Red LED

  • 1x Yellow LED

  • 1x Green LED

  • 3x Resistors

Wiring it up

To add the extra LEDs and resistors, wire them up as shown in the breadboard layout below.

Ensure that the LEDs are the right way around, with the longer positive leads (anodes) to the left.

How does it work

Think of how a traffic light works.

  • it starts from RED

  • then turns to GREEN

  • then turns YELLOW

  • and back to RED

Think about the how long the light stays on before it changes to the next colour

This time that it takes before the light changes is called a WAIT in coding. So the program will WAIT for a specific number of seconds before the next light changes to the next colour

In order to turn the light ON or OFF in code, we say that if we want the light on then we need to set it to HIGH and if we want the light OFF we setup it to LOW.

So to change the traffic lights we say

  • to make the light ON, we set it to HIGH

  • to make the light OFF, we set it to LOW

If you look at the wiring diagram above, you will see that we connected it as follows

  • we connected DIGITAL PIN 7 (D7) to the RED light

  • we connect DIGITAL PIN 6 (D6) to the YELLOW light

  • we connect DIGITAL PIN 5 (D5) to the GREEN light

So In order for the program to work we will do the following

  • set D7 to HIGH (red light)

  • set D6 to LOW (yellow light)

  • set D5 to LOW (green light)

  • WAIT for 10 seconds

  • set D7 to LOW (red light)

  • set D6 to LOW (yellow light)

  • set D5 to HIGH (green light)

  • WAIT for 10 seconds

  • set D7 to LOW (red light)

  • set D6 to HIGH (yellow light)

  • set D5 to LOW (green light)

  • WAIT for 1 seconds

Block Coding

PreviousLED ChasingNextBuzzer

Last updated 3 years ago

Was this helpful?

mBlock Block-Based IDE- Coding for Beginners
Logo