# Gradient using ultrasonic sensor

**URL:** <https://forum.arduino.cc/t/gradient-using-ultrasonic-sensor/1099820>\
**Category:** Programming\
**Created:** [March 9, 2023, 2:49pm UTC](https://forum.arduino.cc/t/gradient-using-ultrasonic-sensor/1099820 "2023-03-09T14:49:45Z")\
**Posts on this page:** 1\
**Showing post:** 8

<div class="post-metadata">

**Author:** ![ec2021](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ec2021/32/997272_2.png) [@ec2021](https://forum.arduino.cc/u/ec2021)\
**Post date:** [March 11, 2023, 3:15pm UTC](https://forum.arduino.cc/t/gradient-using-ultrasonic-sensor/1099820/8 "2023-03-11T15:15:37Z")

</div>

> [@edy\_manz-zz-z](#):
>
> the sensor detects it is getting closer really fast

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

---

_[View the full topic](https://forum.arduino.cc/t/gradient-using-ultrasonic-sensor/1099820)._
