2019WinterTeam4
Introduction
The goal of our project is to create a smart traffic light. We created structures for ultrasonic sensors to detect the car's presence and manage traffic. Utilizing the idea of smart infrastructure, smart cars are able to become more effective and optimizing traffic. We are able to turn off street lighting when it is unused and give priority to emergency vehicles. This simple model minimizes cost and complexity. This project surrounds the problem of directing traffic when 2-way streets merge into 1 on a mountain road.
Team Members
Justine Lee
Mihir Sathe
Kaj Kuchina
Mountain Road Model
Circuit Schematics
STL Models
Decreasing Ultrasonic Variability
The ultrasonic sensors will observe a sharp decrease in the distance as a car drives in front of the sensor. When the sensor is first configured, it establishes a baseline for an empty road. However, in the real world, the object it sees might not be flat or stationary, which could cause false detections. To ensure we had a consistent baseline for the ultrasonic sensors, we designed flat acrylic plates.
Arduino Code
Library that can read from multiple ultrasonic sensors at the same time and frequency.
#include <NewPing.h>
Define variables with set values
#define SONAR_NUM 2 // Number of sensors. #define MAX_DISTANCE 100 // Maximum distance (in cm) to ping. #define THRESH 40
Define green and red led pins on Arduino for traffic light.
#define led_g 7 #define led_r 8
Create a NewPing for each ultrasonic echo and trigger pairing.
NewPing sonar[SONAR_NUM] = { // Sensor object array. NewPing(10, 9, MAX_DISTANCE), // Each sensor's trigger pin, echo pin, and max distance to ping. NewPing(6, 5, MAX_DISTANCE), };
void setup() { Serial.begin(115200); // Open serial monitor at 115200 baud to see ping results. pinMode(led_r, OUTPUT); pinMode(led_g, OUTPUT); digitalWrite(led_g, LOW); digitalWrite(led_r, HIGH); }
void loop() { Serial.print(sonar[0].ping_cm()); Serial.print(","); delay(50); // Wait 50ms between pings (about 20 pings/sec). 29ms should be the shortest delay between pings. Serial.println(sonar[1].ping_cm());
First ultrasonic sensor detects an object then turn green for that side and red for the other side.
if (sonar[0].ping_cm() < THRESH) { digitalWrite(led_g, HIGH); digitalWrite(led_r, LOW); delay(1000); }
Second ultrasonic sensor detects an object then turn green for that side and red for the other side.
else if (sonar[1].ping_cm() < THRESH) { digitalWrite(led_g, LOW); digitalWrite(led_r, HIGH); delay(1000); }
No objects detected then turn red for both sides.
else { digitalWrite(led_g, LOW); digitalWrite(led_r, LOW); } }
Demo
Resources
Traffic Light STL:
https://www.thingiverse.com/thing:2826057
NewPing Arduino Library :
https://playground.arduino.cc/Code/NewPing