Go Down

Topic: 4x Ultrasonic Sensors problem (Read 356 times) previous topic - next topic

adwsystems

Do you realise that this means the sensors will be retriggering themselves all the time? No wonder you get unexpected readings!

It's not just because that trig and echo are separate pins.

You CAN get away with connecting all trig pins together, and reading all echoes at the same time. As long as the sensors don't hear each other's signal. Then you need five pins for four sensors.
I don't have sensors to test with. I don't know the sensors the OP is using is the same as those used by the library author. Based on the library used, NewPing library - https://playground.arduino.cc/Code/NewPing/, the write up says the echo and trig pins can be the same pin. I don't know how it works, I didn't write the library and cannot test it; but that is what the library says.

wvmarle

OP says they have the HC-SR04 sensor.

The sensor triggers on a falling edge on the trig pin, regardless of how long trig has been high as long as it is at least 10 us. So that's exactly what happens when the echo is finished: instant re-trigger of the sensor.

That is, unless the firmware of the sensor ignores the trig pin for a short time in this situation.

It also requires the Arduino's I/O pin to be set as output to trigger, and as input to read the echo. The echo pin is normally held low, and goes high when a trig comes in. So unless that pin is set to input when the sensor is idle, you create a short the moment you try to trigger it by setting the Arduino pin high.
Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

adwsystems

This thread is now redundant with the NewPing Library thread to which the library author is commenting.

Aylee

Doesn't matter anymore, thank you guys, finally i sort it out, i`ve read againd the data sheet for L293D shield and i saw that it uses all digital pins from 3 to 12 so...  Now i`ve managed to get a constant reading at all the time as you can see:


Code: [Select]

sonar0: 19
sonar1: 4
sonar2: 23
sonar3: 7
sonar0: 19
sonar1: 4
sonar2: 23
sonar3: 7
sonar0: 19
sonar1: 4
sonar2: 23
sonar3: 8
sonar0: 19
sonar1: 4
sonar2: 23
sonar3: 7


it barely gives errors. i`ve connected them on a0, a1, a2, and a3. This thread can be closed. Thank you!

Go Up