Gradient using ultrasonic sensor

Hi @edy_manz-zz-z ,

the ultrasonic sensors will give you a momentary distance only.

They do not tell you anything about changes over time. If you want to know whether the distance changes quickly or slowly, you have to compare distance measurements with previous data.

The speed of your car and the distance change can be related but most not be necessarily - if there are other moving objects around, e.g. a second car in front of yours.

If there are only static objects and you know the speed of your car (as you control it yourself) you can calculate when the car will crash

CrashTime = Distance [cm]/speed[cm/sec]

The speed with respect to the obstacle is

CollisionSpeed = (PreviousDistance - ActualDistance)[cm]/(Time between both Measurements)[sec]

Good luck!
ec2021