0% found this document useful (0 votes)
7 views

Document 7

The document outlines the creation of an IoT-Based Traffic Light System using an Arduino Uno microcontroller and Embedded C programming. It includes required apparatus, connection diagrams, and a detailed procedure for setting up the system, including code for traffic light timing and pedestrian override functionality. The project has been successfully tested and demonstrates the integration of IoT in traffic management.

Uploaded by

renugasoundharya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Document 7

The document outlines the creation of an IoT-Based Traffic Light System using an Arduino Uno microcontroller and Embedded C programming. It includes required apparatus, connection diagrams, and a detailed procedure for setting up the system, including code for traffic light timing and pedestrian override functionality. The project has been successfully tested and demonstrates the integration of IoT in traffic management.

Uploaded by

renugasoundharya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

IoT-Based Traffic Light System with Timing

Aim:
To Create IoT-Based Traffic Light System with Timing Using Embedded C
program.
Apparatus Required:
• Arduino Uno Microcontroller.
• Traffic Lights (LEDs).
• Pedestrian Button.
• Wiring Components.
• USB cable (for Arduino, ESP, or Raspberry Pi Pico).
Connection Diagram:
Procedure:
• Connect the LEDs (red, yellow, green) to the microcontroller's GPIO pins
through appropriate resistors, following the connection diagram.
• Install the necessary IDE (Arduino IDE, Platform IO, etc.) and libraries for your
chosen microcontroller.
• Observe the traffic lights: They should cycle through green, yellow, and red
according to the defined timings.
• Set up an IoT platform or MQTT broker to manage the data.
• Test the system thoroughly.
Program:

#include <stdio.h>

#include <stdint.h>

#include <stdbool.h>

#include <time.h>

// Define GPIO pins (replace with your actual pin assignments) #define
RED_LIGHT_1 2 // Example: GPIO pin 2 #define YELLOW_LIGHT_1 3 #define
GREEN_LIGHT_1 4 #define RED_LIGHT_2 5 #define YELLOW_LIGHT_2 6
#define GREEN_LIGHT_2 7 #define PEDESTRIAN_BUTTON 8 // Example:
GPIO pin for pedestrian button

// Define traffic light timings (in seconds) #define GREEN_DURATION 30


#define YELLOW_DURATION 5 #define RED_DURATION 35

// Function prototypes void initialize_gpio(); void set_light(int pin, bool state);


void delay_seconds(int seconds); bool read_button(int pin); void
pedestrian_override();

// Global variables bool pedestrian_request = false;

int main() { initialize_gpio();


while (1) { // Traffic light 1: Green, Traffic light 2: Red
set_light(GREEN_LIGHT_1, true); set_light(RED_LIGHT_2, true);
delay_seconds(GREEN_DURATION); set_light(GREEN_LIGHT_1, false);

// Traffic light 1: Yellow, Traffic light 2: Red


set_light(YELLOW_LIGHT_1, true);
delay_seconds(YELLOW_DURATION);
set_light(YELLOW_LIGHT_1, false);

// Traffic light 1: Red, Traffic light 2: Green


set_light(RED_LIGHT_1, true);
set_light(GREEN_LIGHT_2, true);
delay_seconds(GREEN_DURATION);
set_light(GREEN_LIGHT_2, false);

// Traffic light 1: Red, Traffic light 2: Yellow


set_light(YELLOW_LIGHT_2, true);
delay_seconds(YELLOW_DURATION);
set_light(YELLOW_LIGHT_2, false);
set_light(RED_LIGHT_1, false); //both red, then restart
cycle.

//Pedestrian check. This is done between cycles.


if(read_button(PEDESTRIAN_BUTTON)){
pedestrian_override();
}

return 0; }

void initialize_gpio() { // Initialize GPIO pins as output (for lights) and input (for
button) // Replace with your microcontroller's GPIO initialization code // Example
(using pseudo-code): // set_pin_mode(RED_LIGHT_1, OUTPUT); //
set_pin_mode(YELLOW_LIGHT_1, OUTPUT); //
set_pin_mode(GREEN_LIGHT_1, OUTPUT); // set_pin_mode(RED_LIGHT_2,
OUTPUT); // set_pin_mode(YELLOW_LIGHT_2, OUTPUT); //
set_pin_mode(GREEN_LIGHT_2, OUTPUT); //
set_pin_mode(PEDESTRIAN_BUTTON, INPUT); }

void set_light(int pin, bool state) { // Set the specified GPIO pin to the given state
(true = on, false = off) // Replace with your microcontroller's GPIO output code //
Example (using pseudo-code): // write_pin(pin, state); if(state){ printf("Pin %d
HIGH\n", pin); } else { printf("Pin %d LOW\n", pin); } }

void delay_seconds(int seconds) { // Delay for the specified number of seconds //


Replace with your microcontroller's delay function // Example (using standard C
library): time_t start_time = time(NULL); while (time(NULL) - start_time <
seconds); }

bool read_button(int pin) { // Read the state of the specified GPIO pin (for the
button) // Replace with your microcontroller's GPIO input code // Example (using
pseudo-code): // return read_pin(pin); // This example simulates a button press
every 10 cycles. static int cycleCount = 0; cycleCount++; if(cycleCount % 10 ==
0){ return true; } return false; }

void pedestrian_override() {

// Immediately set both traffic lights to red. set_light(RED_LIGHT_1, true);


set_light(RED_LIGHT_2, true); printf("Pedestrian Override Activated\n");
delay_seconds(10); // Pedestrian crossing time.

// Restore the normal traffic light cycle. printf("Pedestrian Override


Deactivated\n"); }
Output:
Result:

Thus the IoT-Based Traffic Light System with Timing project has been done
and tested Successfully.

You might also like