Lab Exercise:2 Traffic Light Signal System in IoT
Objective: To design and implement a Traffic Light Signal System using Internet of Things
(IoT) concepts, allowing real-time monitoring and control of traffic lights over the internet.
The system will use sensors to detect traffic density and adjust the signal timing accordingly,
ensuring efficient traffic management.
Required Components:
1. Microcontroller/Development Board:
o ESP8266/ESP32 or Raspberry Pi (for internet connectivity and control)
2. Traffic Light Module:
o Red, Yellow, Green LEDs (for each lane)
o Resistors (appropriate values for LEDs)
3. Sensors:
o IR Sensors or Ultrasonic Sensors (for detecting traffic density on each lane)
4. Relay Module:
o For controlling the traffic lights (if necessary)
5. Breadboard and Jumper wires
6. Power Supply:
o Appropriate supply for the microcontroller and LEDs (e.g., 5V)
7. Wi-Fi Connectivity (for ESP8266/ESP32)
8. IoT Platform (optional):
o Blynk, ThingSpeak, or Adafruit IO (for monitoring the traffic light system
remotely)
Preliminary Setup:
1. Wiring the Traffic Lights:
o Connect each red, yellow, and green LED for each lane to the microcontroller.
Use appropriate resistors to prevent excessive current draw.
o Wire the LEDs to GPIO pins of the ESP32/ESP8266 or Raspberry Pi.
2. Wiring Sensors:
o Connect the IR or Ultrasonic sensors to the microcontroller to detect the
presence of vehicles.
o Ensure the sensor readings are accurate for the desired range.
3. Testing Hardware:
o Test individual LEDs to ensure they light up correctly when triggered.
o Test the sensor readings on the microcontroller to verify they detect the
presence of vehicles.
Steps to Follow:
Step 1: Write the Basic Code for Traffic Light Control
1. Set up your development environment:
o For ESP8266/ESP32, use Arduino IDE or PlatformIO.
o For Raspberry Pi, use Python (GPIO library).
2. Traffic Light Control Logic:
o Define a simple state machine for traffic light management: Red, Yellow, and
Green.
o Implement a delay for each state (e.g., Green for 30 seconds, Yellow for 5
seconds, Red for 30 seconds).
// Example for ESP8266/ESP32 with Arduino IDE
int redPin = 5; // GPIO Pin for Red light
int yellowPin = 4; // GPIO Pin for Yellow light
int greenPin = 3; // GPIO Pin for Green light
void setup() {
pinMode(redPin, OUTPUT);
pinMode(yellowPin, OUTPUT);
pinMode(greenPin, OUTPUT);
void loop() {
// Green Light: 30 seconds
digitalWrite(greenPin, HIGH);
delay(30000); // Wait for 30 seconds
// Yellow Light: 5 seconds
digitalWrite(greenPin, LOW);
digitalWrite(yellowPin, HIGH);
delay(5000); // Wait for 5 seconds
// Red Light: 30 seconds
digitalWrite(yellowPin, LOW);
digitalWrite(redPin, HIGH);
delay(30000); // Wait for 30 seconds
The ThingSpeak platform or Blynk app will display the status of the traffic light and sensor
readings in real-time.
Step 2: Test the System
Monitor the Traffic Light: Observe how the traffic lights change according to the
programmed timings and sensor inputs.
Sensor Detection: Ensure that when vehicles are detected, the system adjusts the
traffic light timing.
Control Remotely: If using IoT, use the mobile app or web platform to control and
monitor the traffic light system.
Step 3: Analysis and Reporting
Performance Analysis: Measure the time taken for the traffic light to adjust
according to sensor input.
IoT Integration: Evaluate the responsiveness of the IoT platform (e.g., Blynk or
ThingSpeak) in real-time monitoring and control.
Conclusion:
This lab will help you understand how IoT can be applied to control and monitor real-world
systems like traffic lights. You will learn how to interface sensors with microcontrollers,
write code to control hardware, and integrate IoT for real-time monitoring and
management.