SR-04 ultrasonic module

I am using the SR-04 , so I used it this way

give it a 10 uS pulse

Use the pulse in

dist=pulsein / 58

can I use this once or I should cylce it several times ?

Don't understand the question.

Post your code, post your problem.

int distance_measurment() {

int distance=0;

digitalWrite(trigger,LOW); delayMicroseconds(2);

digitalWrite(trigger,HIGH); delayMicroseconds(10);

digitalWrite(trigger,LOW); delayMicroseconds(2);

distance=pulseIn(echo,HIGH); distance=distance/58;

return distance;


That's (a part of) the code, so where's the problem? (Apart from using the wrong data type for the return value from pulseIn)

If you want to reduce noise in your signal you can use the .ping_median() method of the NewPing library. It will return the median value (the one closest to the middle) of however many samples you choose.

I think OP is asking about single or continuous pulsing.

For every pulse (output) u initiate, u should get an echo (input) if there is an obstacle within range i.e. your specified range.

You can send repetitive pulses which are controlled by how long u put the MCU to sleep/delay between pulses.

So in theory u can do a single pulse and put the MCU to sleep, or you can pulse as often as u like with delays between pulses. I believe the min suggested delay (after time-out) is 60 to 100 ms.

Bottom line is u have full control over how often you pulse which I imagine depends on how often u want to know what the sensor is sensing.