Project 001: Street Traffic Light

TrafficeLights GYR

Level: Stars 10

Objectives

  1. Understand the fundamentals of microcontroller programming and circuit design.
  2. Develop a traffic light control system with specified timings.
  3. Practice programming I/O interfaces.
  4. Learn debugging and testing of embedded systems.

Required Components List

Component/DeviceDescriptionQuantity
R330ohm 220 Ω (red red brn gld / red red blk blk brn) × 6
LED Green 64 Red LED × 2
LED Green 64 Green LED × 2
LED Green 64 Blue LED × 2

Background

Traffic light systems manage the flow of traffic at intersections. Students can learn about sequential logic, timing control, and embedded system programming basics by creating a model traffic light system. This project involves creating a simplified cross-road traffic management system using LEDs for North-South and East-West directions.

Schematic Diagram

Use diagrams to set up the LEDs with the microcontroller.

Sch LEDRYG LED Symbol Polarity
Figure 1: Schematic Diagram for Traffic Light

Sch TrafficeLight 01
Figure 2: Connect the LEDs on the Breadboard

Pin Configuration Table

DevicePort.PinSignal TypeModuleDirectionDrive Mode

TrafficeLights 2GYR

Crossroad Traffic Light System

For a complete simulation, construct two traffic lights:

  • North-South Direction
  • East-West Direction

Each light will follow the sequence:

  • Green for 10 seconds
  • Solid Yellow for 3 seconds
  • Blinking Yellow for 2 seconds (500ms interval)
  • Both directions turn red for a brief 1-second pause. Then, the cycle switches to another direction.

Lab Procedure

  1. Circuit Setup
    • The green and yellow LED's anode (longer leg) connects to the digital output, and the cathode (shorter leg) goes to the ground (GND) through a resistor.
    • The red LED's anode (longer leg) connects to the power source through a resistor, and the cathode (shorter leg) connects to the digital output pin.
    • Arrange the LEDs in two sets (North-South and East-West), each comprising a Red, Yellow, and Green LED.
  2. Programming
    • Initialize the pins connected to the LEDs as OUTPUT in your code's Setup_GPIO() function.
    • Follow the lab experiments session to implement the control code in the main() function
    • Implement the timing sequence using DelayMs() for the specified durations.
  3. Testing and Debugging
    • Upload the code to the microcontroller and observe the operation of the traffic light system.
    • Verify lights change according to the sequence and timings.
    • If necessary, adjust the code or connections to correct any issues.

Did You Know? Relating to their first installation in London in 1868, traffic lights represent one of the foundational robotic systems impacting society. The three-colored pattern we recognize today was first seen in 1920.

Lab Experiments

In the code, the first step involves configuring the GPIO ports and setting the direction for each pin. Next, initialize all lights to be off by default. Note that some LEDs use negative logic output, meaning a logic 1 output will turn those LEDs off.

© 2024 Air Supply Information Center (Air Supply BBS)