i am using arduino nano and hc-sr04 ultrasonic sensor to measure speed of a car. i plan to take the difference of distances taken at different time, hence by making a delay in turning on the pins.
(distance1 - distance2)/delay = speed
it gives me distances and the delta almost accurately, but the speed remained 0.
Since you are using a delay of 1000ms between distance measurements, the distance traveled is already giving the speed in cm/second. Using cm/ms as the units of speed doesn't seem very useful, since that will give a maximum speed of 0.40cm/ms if you travel the entire 400cm range of the ultrasonic sensor during the one second interval. It would also be helpful if you printed out more decimal places, since anything less than 5cm/second will show as 0.00