theodorbenad
Published © GPL3+

Is The Overtaking Car Keeping Enough Side Distance To You?

Simple and effective method (some police is using too) how to measure the side distance to an overtaking car.

BeginnerShowcase (no instructions)2,958
Is The Overtaking Car Keeping Enough Side Distance To You?

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
Alphanumeric LCD, 16 x 2
Alphanumeric LCD, 16 x 2
×1
9V battery (generic)
9V battery (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1
5 mm LED: Red
5 mm LED: Red
×1
5 mm LED: Yellow
5 mm LED: Yellow
×1
5 mm LED: Green
5 mm LED: Green
×1
5 mm LED: Blue
×1
Rocker Switch, SPST
Rocker Switch, SPST
×1
Rotary potentiometer (generic)
Rotary potentiometer (generic)
×1
Breadboard (generic)
Breadboard (generic)
×1
Resistor 100 ohm
Resistor 100 ohm
×2
Through Hole Resistor, 150 ohm
Through Hole Resistor, 150 ohm
×2
Standard Terminal Block, Lever-Nuts
Standard Terminal Block, Lever-Nuts
×2
Snap-on Connector, For 1 9-V Battery
Snap-on Connector, For 1 9-V Battery
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
(+ solder)
Crimp Tool (generic)
(+ a few ferrules)
Side cutter (generic)
Tape, Electrical
Tape, Electrical
For isolating
Cutter knife (generic)

Story

Read more

Schematics

Schematic

The most non 5V and non ground cables are colored as in the pictures.

Code

Ultrasonic_Seitenabstand.ino

C/C++
#include <LiquidCrystal.h>
int trigger=7;
int echo=6; 
int blue=8;
int green=9;
int yellow=10;
int red=13;
long distance,duration;
LiquidCrystal lcd(12,11,5,4,3,2);
void setup() {
  pinMode(trigger,OUTPUT);
  pinMode(echo,INPUT);
  lcd.begin(16,2);
  pinMode(blue,OUTPUT);
  pinMode(green,OUTPUT);
  pinMode(yellow,OUTPUT);
  pinMode(red,OUTPUT);
}

void loop() {
  lcd.clear();
  digitalWrite(trigger, LOW); 
  delay(5); 
  digitalWrite(trigger, HIGH); 
  delay(10);
  digitalWrite(trigger, LOW);
  duration = pulseIn(echo, HIGH); 
  distance = ((duration/2) * 0.03432) - 20; 
  lcd.print(distance);
  if(distance>400 || distance<30){ //failure or not making sense to measure
    digitalWrite(blue,HIGH);
    digitalWrite(green,LOW);
    digitalWrite(yellow,LOW);
    digitalWrite(red,LOW);
  }else if(distance<400 && distance>150){ //enough distance
    digitalWrite(blue,LOW);
    digitalWrite(green,HIGH);
    digitalWrite(yellow,LOW);
    digitalWrite(red,LOW);    
  }else if(distance<150 && distance>100){ //too little distance
    digitalWrite(blue,LOW);
    digitalWrite(green,LOW);
    digitalWrite(yellow,HIGH);
    digitalWrite(red,LOW);
  }else if(distance<100 && distance>30){ //far too little distance
    digitalWrite(blue,LOW);
    digitalWrite(green,LOW);
    digitalWrite(yellow,LOW);
    digitalWrite(red,HIGH);
  }
  delay(100); //repeating fast enough to have a current value but slow enough having enough time to read the value
}

Credits

theodorbenad
0 projects • 0 followers

Comments