I'm using Ultrasonic-HC-SR04 , which has the many examples to calculate the distance, I want to calculate the velocity which is = ( distance [2] - distance [1] ) / ( time[2] - time[1] )
the distance is changing depand on my delay (..);
1- How can I take these values of distance and time frequently ??
2- if there is an array with variable (i) how can I make it ?
1- How can I take these values of distance and time frequently ??
Take two distance readings, separated by a known time interval (the delay() function is fine for this simple experiment), and compute the velocity as you described.
The velocity won't be correct unless the object is moving directly toward or directly away from the sensor.