HC-SR 04 Ultrasonic sensor is most commonly used to measure distance, but this time I will show you how to measure the speed of movement of an object using this sensor.
Device is very simple and consist only a few components:
- Arduino Nano microcontroller
- LCD display
- Ultrasonic sensor
- and LED diode
For that purpose we need to take two distance measurements in a short time apart and we have:
distance2 - distance1 = distance speed at a given time
If we make the measurements in a time period of 1 second, then we get the speed of movement of the object in cm/s. The basic code is taken from the arduino cc forum and I just added an LCD display for a visual representation of the results.
The first row shows the distance, and the second row shows the speed if the object is moving.
There is also an LED that signals the distance at which the object is placed. If the distance is less than 5 cm, the LED lights up continuously. As the distance increases the LED starts flashing at a speed that depends on the distance of the object. If the object moves away, the blinking is slower, and vice versa.
When the object is moving in the opposite direction, the speed represented on the display has a negative sign.
Comments