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

Smart Traffic System Group 10

Report on smart traffic system

Uploaded by

Shradha Swarup
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views

Smart Traffic System Group 10

Report on smart traffic system

Uploaded by

Shradha Swarup
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Smart Traffic System

AIM:

The aim of the experiment is to develop a smart traffic signal system that utilizes IR sensors to
detect vehicle presence, sound sensors to detect horn activity exceeding 70dB, and an OLED
display to raise awareness about the horn noise level. Additionally, the experiment aims to
control the traffic LED signals based on the data collected from these sensors, thus promoting
traffic discipline and reducing noise pollution.

OBJECTIVES:

1. Hardware Setup:
- Assemble the hardware components including NodeMCU, IR sensors, sound sensor, OLED
display, 3 LEDs, and jumper wires.
- Connect the IR sensors and sound sensor to the NodeMCU using jumper wires, ensuring
proper wiring connections.
- Mount the IR sensors and sound sensor at appropriate locations near the traffic signal
pole.

2. Software Development:
- Develop the firmware for the NodeMCU to read data from the IR sensors and sound
sensor.
- Program the NodeMCU to analyze sensor data and control the traffic LED signals
accordingly.
- Implement logic to detect vehicle presence using IR sensors and to detect horn activity
exceeding 70dB using the sound sensor.

3. Traffic LED Control:


- Define the LED signal patterns for different traffic directions (e.g., red for stop, green for
go, yellow for prepare to stop).
- Configure the NodeMCU to switch LED signals based on the detected traffic conditions
and sound levels.

4. Horn Awareness Display:


- Integrate the OLED display with the NodeMCU.
- Design a user interface on the OLED display to show the current horn noise level and a
warning message if it exceeds 70dB.
- Program the NodeMCU to update the OLED display in real-time based on the data
collected from the sound sensor.

5. Testing and Calibration:


- Test the system under various traffic conditions to ensure accurate detection of vehicle
presence and horn noise.
- Calibrate the sound sensor to accurately measure horn noise levels and adjust the
threshold if necessary.
- Validate the functionality of the traffic LED control and horn awareness display by
simulating different traffic scenarios.
6. Evaluation and Optimization:
- Evaluate the effectiveness of the system in promoting traffic discipline and reducing noise
pollution.
- Gather feedback from users and stakeholders for further optimization of the system.
- Fine-tune the software algorithms and sensor configurations to enhance the system's
performance and reliability.

7. Documentation and Presentation:


- Document the experiment setup, methodology, and findings including any challenges
encountered and their resolutions.
- Prepare a presentation to showcase the experiment outcomes, emphasizing the
significance of the developed smart traffic signal system in improving road safety and traffic
management.

By accomplishing these objectives, the experiment aims to demonstrate the feasibility and
effectiveness of using smart technologies to enhance traffic signal control and promote
awareness about noise pollution caused by excessive horn usage.

Components required

NODE MCU IR SENSOR LED

SOUND SENSOR OLED DISPLAY JUMPER WIRES


PROGRAM:

#include <ESP8266WiFi.h>
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <NTPClient.h>
#include <WiFiUdp.h>

#define SCREEN_WIDTH 128 // OLED display width, in pixels


#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

String apiKey = "15BJ7JOT78FE0RU7"; // Enter your Write API key from ThingSpeak
const char *ssid = "realme C25s"; // replace with your wifi ssid and wpa2 key
const char *pass = "pmishra12";
const char* server = "api.thingspeak.com";
const int ledPins[3] = {D5, D6, D7}; // D1, D2, D3
const int irPin = D8;
int redDuration = 3000; // Red LED duration in milliseconds (3 seconds)
int yellowDuration = 1000; // Yellow LED duration in milliseconds (1 second)
int greenDuration = 3000; // Green LED duration in milliseconds (3 seconds)

const int sampleWindow = 50; // Sample window width in mS (50 mS = 20Hz)


unsigned int sample;

WiFiClient client;
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP);

void setup()
{
Serial.begin(115200); //Serial comms for debugging
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); //OLED display start
display.display(); //show buffer
display.clearDisplay(); //clear buffer
display.setTextSize(1); //Set text size to 1 (1-6)
display.setTextColor(WHITE); //Set text color to WHITE (no choice lol)
display.setCursor(0,0); //cursor to upper left corner
display.println("Decibelmeter"); //write title
display.display(); //show title
delay(2000); //wait 2 seconds

WiFi.begin(ssid, pass);

while (WiFi.status() != WL_CONNECTED)


{
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");

display.clearDisplay();
display.setCursor(0,0);
display.setTextSize(1);
display.setTextColor(WHITE);
display.print("WiFi connected");
display.display();
delay(4000);
display.clearDisplay();

for (int i = 0; i < 3; i++) {


pinMode(ledPins[i], OUTPUT);
}
pinMode(irPin, INPUT);

// Initialize NTP client


timeClient.begin();
timeClient.setTimeOffset(19800); // Set time offset for IST (19800 seconds = 5.5 hours)
}

void loop()
{
int i; // Declare 'i' here

// Update current time


timeClient.update();
String formattedTime = timeClient.getFormattedTime();
Serial.print("Current Time: ");
Serial.println(formattedTime);

// Check if IR sensor output is LOW


if (digitalRead(irPin) == LOW) {
redDuration = 8000; // Change red light duration to 8 seconds when IR sensor detects input
} else {
redDuration = 3000; // Change red light duration to 3 seconds when IR sensor doesn't detect
input
}

// Turn on the red LED


digitalWrite(ledPins[0], HIGH);
delay(redDuration); // Wait for the red duration

// Turn off the red LED and turn on the yellow LED
digitalWrite(ledPins[0], LOW);
digitalWrite(ledPins[1], HIGH);
delay(yellowDuration); // Wait for the yellow duration

// Turn off the yellow LED and turn on the green LED
digitalWrite(ledPins[1], LOW);
digitalWrite(ledPins[2], HIGH);
delay(greenDuration); // Wait for the green duration

// Turn off all LEDs


for (i = 0; i < 3; i++) {
digitalWrite(ledPins[i], LOW);
}

unsigned long startMillis= millis(); // Start of sample window


float peakToPeak = 0; // peak-to-peak level
unsigned int signalMax = 0; //minimum value
unsigned int signalMin = 1024;
//maximum value

// collect data for 50 mS


while (millis() - startMillis < sampleWindow)
{
sample = analogRead(0); //get reading from microphone
if (sample < 1024) // toss out spurious readings
{
if (sample > signalMax)
{
signalMax = sample; // save just the max levels
}
else if (sample < signalMin)
{
signalMin = sample; // save just the min levels
}
}
}
peakToPeak = signalMax - signalMin; // max - min = peak-peak amplitude
float db = map(peakToPeak,20,900,49.5,90); //calibrate for deciBels

// Print decibel reading to serial monitor


Serial.print("Decibel Reading: ");
Serial.print(db);
Serial.println(" dB");

// Update OLED display immediately with decibel reading


display.clearDisplay();
display.setCursor(0,0);
display.setTextSize(2);
display.setTextColor(WHITE);
display.print(db);
display.print(" dB");

// Draw scale
for(int x =5;x<114;x=x+6){
display.drawLine(x, 32, x, 27, WHITE);
}
// Draw outline of bar graph
display.drawRoundRect(0, 32, 120, 20, 6, WHITE);
// Set bar graph width based on decibel reading
int r = map(db,0,120,1,120);
// Draw bar graph
display.fillRoundRect(1, 33, r, 18, 6, WHITE);

display.display();

// Check if sound level exceeds 70 decibels


if (db > 70) {
display.clearDisplay();
display.setCursor(0,0);
display.setTextSize(1);
display.setTextColor(WHITE);
display.println("Please lower your horn");
display.display();
Serial.println("Please lower your horn");
}
else {
if (client.connect(server, 80)) // "184.106.153.149" or api.thingspeak.com
{
String postStr = apiKey;
postStr += "&field1=";
postStr += String(db);
postStr += "r\n";
client.print("POST /update HTTP/1.1\n");
client.print("Host: api.thingspeak.com\n");
client.print("Connection: close\n");
client.print("X-THINGSPEAKAPIKEY: " + apiKey + "\n");
client.print("Content-Type: application/x-www-form-urlencoded\n");
client.print("Content-Length: ");
client.print(postStr.length());
client.print("\n\n");
client.print(postStr);
}
client.stop();
delay(150);
}
}

GROUP 10
ISHU KANT - 22052730
JAISH NAWED - 22052731
SHIVAM KUMAR - 22052760
ARPREET MAHALA - 22052804
AKSHAT KUTARIYAR - 22052791

You might also like