TheIdea
Until April 28, 2020 in Germany you have to keep at least 1.5 m (4.9 feet) side distance while overtaking a bicyle. If you violated the law you're going to receive a fine (30 EUR/34 USD).
But how does the police check the side distances between a car and a bicyle? During my research I found an article about the Salzburg's police department. I wondered how the device works so I tried to build one by myself.
Enhancing Cyclist Safety with Real-Time Proximity Monitoring
In many countries, traffic laws mandate a minimum side distance (often 1.5 meters) when a motorized vehicle overtakes a bicycle. This project reproduces a professional-grade monitoring tool using accessible Arduino components, allowing cyclists to objectively measure and record the proximity of overtaking vehicles.
Precision Ultrasonic Sensing in Traffic
The system relies on the HC-SR04 Ultrasonic Sensor, which operates by sending a 40kHz sonic burst and measuring the time it takes for the echo to return.
- Distance Calculation: Using the formula
Distance = (Time * Speed of Sound) / 2, the Arduino calculates the gap between the handlebar and the overtaking object. - Offset Calibration: A -20cm offset is included in the code to account for the sensor's mounting position relative to the edge of the bicycle.
Multi-Tiered Alert System
To provide immediate awareness to the cyclist without requiring them to look away from the road, the project uses a color-coded LED feedback system:
- Green LED (150cm+): Safe overtaking distance maintained.
- Yellow LED (100cm - 150cm): Warning - distance is below the recommended safety margin.
- Red LED (30cm - 100cm): Danger - critical proximity violation that could lead to an accident.
- Blue LED: System status or out-of-range indicator, ensuring the user knows the sensor is functioning even when no car is present.
User Interface and Data Readout
While the LEDs provide rapid feedback, a 16x2 LCD display shows the precise distance in centimeters. This is crucial for documentation or calibrating the device. The entire system is powered by a standard 9V battery and housed in a durable casing (in this case, a reinforced shoebox) mounted using standard GoPro-compatible hardware for maximum vibration resistance.
After The Idea
Due to german/european law I would have to censor every license plate and every person. Because of that I couldn't record a video in action. But it's working well.
I would like to have a 3d printed case but I don't have a 3d printer so I took a stable shoe box. For mounting it to my handlebars I used some GoPro stuff.
In the code I'm operating only with centimeters.
#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
}
Here some pictures:










I was even able to drive normally without getting affected by the device.
I'm open to all (positive/negative...) feedback.