I am doing a uni project. I am trying to design a system which would alert the driver of a car if he is not keeping safe distance (distance of three seconds) with the next car. For this,
PART 1: I would need to measure current speed of the vehicle and with some mathematical calculations in code, the optimum distance required to be kept. To read vehicle's current speed, I am using an UNO with Freematics OBD-II I2C adapter.
PART 2:The second part is to detect current distance for which I am using a HC-SR04 ultrasonic sensor with arduino.
The code will then compare the required distance (from part1) with current distance (from part 2) and give the driver a warning (an LED turns on).
It is my first time with Arduino and JAVA. Can anyone please help me with the code I need to do this project? Any help would be much appreciated.
If you are just using the ultrasonic sensor as a demonstration of a concept that's OK, but if you plan to put it on a real car then prepare to be disappointed.
Ultrasonic sensors have a wide beam spread and will reflect back from the road surface giving false returns.
The HC-SR04 is also severely limited in detection range. OK for 2m, no good for 100m.
A Google search for "arduino hc-sr04 tutorial", returns 40,000 web pages and videos.
We are taught in the US driver's ed program that 2 seconds is the distance.
Then we see on the roads that you will basically never see anyone 2 seconds behind the car in front.
Look at the car in front, pick a spot on the road that it passes, start counting 'one one thousand two one thousand' or Mississippi, if you're inclined that way.
It's an unrealistic distance. At 60mph, a 2 second gap is 176 feet, about 59 yards, about 54 meters.
Do you really expect cars on the highway, doing the typical 60mph, to space out over half an American football field worth of space? 11 or so car lengths away?
And mind you, that's a 2 second rule. You and your 3 second rule are dead in the water before you even begin. The driver behind you won't even be close enough to see your most-likely-illegal-anyway light contraption telling him he's too close.
So. With your pipedream of 3 seconds, you would need a distance sensor that can ping a car-sized cross section at 94 meters, and an insanely obnoxious and noticeable warning light that would be visible to that driver 94 meters away while probably trying not to distract everyone within a soccer field's size behind you.
I'll say universities just aren't what they used to be if kids are this far behind in an understanding of the real world. And I'll also say, you should be looking at lidar type distance sensors and not ultrasonic, just so I at least contribute some kind of help to this terribad idea.
INTP, you must live in L.A. Everywhere else I have driven in many countries, the 2 second rule works. In snow, 4 seconds is good and I can still do 65mph.
But leave a gap that big on the 405 freeway? There will be 2 cars in that space.
Speed guns use radar and laser. I cannot see ultrasonics working and if as @spycatcher2k says your sensor has a maximum range of 4m then the other driver will almost be in the back seat. Road noise and weather would probably affect ultrasonics badly.
At 50mph your stopping distance will be around 60m
Yes and no, pure stopping distance is useful if you're worried about static obstacles appearing like a frozen deer or a fallen tree.
Those scare stats don't apply to the everyday in the sense that it's as if you're expecting the car in front or you in this case you yourself, come to a complete stop instantly. Realistically, the car ahead of you will also take time and distance to slow down to a stop, extending your buffer at the same time.
INTP:
Yes and no, pure stopping distance is useful if you're worried about static obstacles appearing like a frozen deer or a fallen tree.
Those scare stats don't apply to the everyday in the sense that it's as if you're expecting the car in front or you in this case you yourself, come to a complete stop instantly. Realistically, the car ahead of you will also take time and distance to slow down to a stop, extending your buffer at the same time.
Yes and no
I get what you are saying and the OP does say 'optimum distance' not stopping distance. However you do get pileups so the car in front stops pretty damn quick ( though I suppose in that situation an LED is not much use anyway).
The stopping distance is the driver's reaction time plus the braking distance. When the car in the front of a line has a problem the next car can probably stop. However the reaction time of the drivers means that each following driver has to react faster and faster to the car in front braking. Enough cars too close together and they all end up getting shunted into one another even if initially they managed to stop in time.
You also get funny standing wave effects on roads. Have you ever had to slow down because the traffic in front slows down for no apparent reason and then you all speed up again. These waves seem to relate to driver reaction time and can persist for ages after the original event that caused the braking has gone.
ardly:
Speed guns use radar and laser. I cannot see ultrasonics working and if as @spycatcher2k says your sensor has a maximum range of 4m then the other driver will almost be in the back seat. Road noise and weather would probably affect ultrasonics badly.
At 50mph your stopping distance will be around 60m
There is a band of frequencies in the 70Ghz range assigned for automobile radar use. My general manager's few-years old Ford has exactly what you are planning. It uses the radar transponder. It not only warns of obsticles in front of the car, it adjusts the cruse control to maintain the safe distance.
So, you are trying to recreate OLD technology using ancient sensors.