Video thumbnail Play Video

Smart Traffic light System

IT STEM STEM Day 8 3 hrs Computational Thinking Block Coding

This course introduces key STEM concepts by offering a dynamic, team-based learning environment. Participants will engage in hands-on activities, utilizing tools such as IR distance interrupters and LEDs, to create an intelligent traffic light system. Dive into the practical applications of STEM and gain valuable collaborative skills in the process.

Course Enquiry

Learning objectives

  • Understand the workings of real-time traffic light systems.
  • Create a smart traffic light with micro:bit, IR sensors, and LEDs.
  • Learn to synchronize two traffic lights, both wired and wirelessly.

Lesson plan

How traffic lights work | Asks how real traffic lights decide when each colour comes on, observes that fixed-timer lights keep waiting even with no traffic, and introduces the infrared distance sensor (2-10 cm range) as the hardware that lets the light change when a vehicle actually approaches.
Hardware introduction and loading program | Introduces micro:bit as the controller, the micro:Driver expansion board (battery holder, switch, sensor and light connections) and the red/yellow/green LEDs, then walks through pairing the micro:bit and loading the prepared MakeCode program on either a tablet or a computer.
Making the traffic light core (hardware wiring) | Hands-on wiring: open the micro:Driver screw terminals, fit the battery holder red lead to + and black lead to -, check the power LED, plug the red/yellow/green LEDs into pins P12/P13/P14 and connect the infrared distance sensor to the G/V/C/D port.
Code explanation | Breaks down the MakeCode blocks behind the traffic light: pin initialisation, the pause block (1 second = 1000 ms), the if-condition, reading the infrared sensor signal, and the full cycle — red plus yellow when a car is detected, then green for 5 s, yellow for 2 s, back to red with a 5 s hold so the sensor does not retrigger immediately.
Decorating, assembling and testing the traffic light | Craft build: glue five craft sticks into the light pole, decorate and cut the A4 traffic-light housing template, fold and tape the casing, mount the three LEDs with Blu Tack in the right orientation, slide the casing over the pole and test that the sensor triggers the correct colour sequence.
HuskyLens AI camera | Introduces the HuskyLens AI machine-vision sensor and its seven built-in functions (face recognition, object tracking, object recognition, line following, colour recognition, tag recognition, object classification), how the function and learning buttons work, how to power it, then trains it in object-classification mode to recognise hand gestures and the three traffic-light colours.
Maqueen Plus V2 smart car assembly | Introduces the Maqueen Plus V2 robot car, then mounts the HuskyLens on it using the angle bracket, mini mount and four screws, routes the 4-pin cable, adjusts the camera angle and downloads the car's MakeCode program.
Car line following and traffic light interaction | Reads the car's code: initialisation, using HuskyLens object classification so the car stops when Color ID is 1 or 2 (red or yellow) and drives on green, and line following using the M/L1/L2/R1/R2 sensors to steer along a black line; students then tune the drive speed and test the car on the printed road map.

Prerequisites

  • None

Software

  • Una Virtual Classroom - Intermediate / Microsoft MakeCode

Other requirements

    Hardware

    • Tablet/Notebook/Desktop
    • Micro:bit V2 x 2
    • DFRobot micro:Driver - Driver Expansion Board for micro:bit x2
    • 3xAA Battery Holder x 2
    • IR distance interrupter x 2
    • LED
    • Supporting materials