TRAFFIGO

by bcsedlon in Circuits > Arduino

2942 Views, 5 Favorites, 0 Comments

TRAFFIGO

traffigo.jpg
IMG_20190713_070752.jpg
VID 20190713 071408

Are you bored in traffic jams? Build your own traffic jam assistant for few dollars. TRAFFIGO (TRAFFIc GO) makes sound indication if you are approaching to a car in front of you (like parking sensor) and in additional makes different sound if the car in front of you is moving away.

With TRAFFIGO you will never miss time to go again and traffic will go more smoothly without unnecessary spaces and delays.

What Do You Need?

JSN-SR04T-ultrasonische-sensor-waterdicht.jpg
dupont.jpg
nano.jpg

How Does It Work?

Distance sensor is mounted in front bumper of your car and connected by wire to box with Arduino and buzzer in cabin. Arduino continuously measure distance, if distance is bellow limit (1m) sound indication is started with pause between beep corresponding to distance (higher distance = longer pause). As you are approaching car in front of you beeps are faster until you stop car.

If you’re your car and car in front of you are stopped and distance is not changing, TRAFFIGO stops indication and is quiet.

When car in front of starts moving away TRAFFIGO starts beeping again with different sound and you are announced to continue drive. When front car is away sounds stops again and nothing disturb you.

TRAFFIGO is powered from 12VDC car board voltage, e.g. from cigarette lighter socket.

Connect Together

traffigo_bb.png
traffigo_schem.png

Arduino Code

//traffigo.ino

#include "Arduino.h"
int diffDistance = 1;

int diffDistanceTimeout = 500;
int toneDuration = 100;

int maxDistance = 100;


unsigned long lastDiffDistanceMillis;
unsigned long lastMillis;
const int buzzerPin = 8;
const int trigPin = 9;
const int echoPin = 10; int distance; int lastDistance; #include "filter.h"
ExponentialFilter distanceFiltered(16, 0);

const int c = 261; const int aH = 880;
void setup() {
pinMode(buzzerPin, OUTPUT);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
Serial.begin(9600);
Serial.println("TRAFFIGO");
}

void loop() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10); digitalWrite(trigPin, LOW);
long duration;
duration = pulseIn(echoPin, HIGH);
distance = duration * 0.034 / 2;
distanceFiltered.Filter(distance);
distance = distanceFiltered.Current();
// Prints the distance on the Serial Monitor
Serial.print("Distance: ");
Serial.println(distance);

bool bBeep = true;
if(abs(lastDistance - distance) < diffDistance + (distance / 20)) {
if(millis() - lastDiffDistanceMillis > diffDistanceTimeout) {
bBeep = false;
}
}
else {
lastDiffDistanceMillis = millis();
}
if(distance > maxDistance) {
bBeep = false;
}
if(bBeep) {
if(millis() - lastMillis > distance * 4) {
lastMillis = millis();
if(distance > lastDistance)
tone(buzzerPin, c, toneDuration);
else
tone(buzzerPin, aH, toneDuration);
lastDistance = distance; } else { noTone(buzzerPin); } } else { noTone(buzzerPin); } }
//filter.h

#pragma once
/* Implements a simple linear recursive exponential filter. See: <a href="http://www.statistics.com/glossary&term_id=756" rel="nofollow"> <a href="http://www.statistics.com/glossary&term_id=756"> <a href="http://www.statistics.com/glossary&term_id=756"> http://www.statistics.com/glossary&term_id=756 </a> </a> </a> */

template class ExponentialFilter {
// Weight for new values, as a percentage ([0..100])
T m_WeightNew;
// Current filtered value.
T m_Current;

public:
ExponentialFilter(T WeightNew, T Initial): m_WeightNew(WeightNew), m_Current(Initial) {
}

void Filter(T New) {
m_Current = (m_WeightNew * New + (100 - m_WeightNew) * m_Current) / 100;
}

void SetWeight(T NewWeight) {
m_WeightNew = NewWeight;
}

T GetWeight() const {
return m_WeightNew;
}

T Current() const {
return m_Current;
}

void SetCurrent(T NewValue) {
m_Current = NewValue;
}
};

// Specialization for floating point math.
template<> class ExponentialFilter {
float m_fWeightNew;
float m_fCurrent;

public:
ExponentialFilter(float fWeightNew, float fInitial) : m_fWeightNew(fWeightNew/100.0), m_fCurrent(fInitial) {
}

void Filter(float fNew) {
m_fCurrent = m_fWeightNew * fNew + (1.0 - m_fWeightNew) * m_fCurrent;
}

void SetWeight(float NewWeight) {
m_fWeightNew = NewWeight/100.0;
}

float GetWeight() const {
return m_fWeightNew*100.0;
}

float Current() const {
return m_fCurrent;
}

void SetCurrent(float fNewValue) {
m_fCurrent = fNewValue;
} };

Source code is available on Github https://github.com/bcsedlon/traffigo

Downloads

Photos

IMG_20190713_070442.jpg
IMG_20190713_070435.jpg
IMG_20190713_070429.jpg