Hi! I have a problem trying to read 2 HCSR04 at once. I've used the simple code and the Ultrasonic and NewPing Libraries, but the problem is the same.
Both sensors are facing in the same direction, but 45 cm apart. The problem is that when I put an object to one of them, and slowly putting away, around 25 cm the other sensor would start showing a reading, but around 95-99 cm. Are their getting interfences from one another? Because if dont put any object on them, both of them will show no reading (0cm), because the max distance is 100cm. Could be the wiring?
The two sensors have their echo and trigger pins each.
Hi @imanolbetanzos ;
Can you post a drawing showing the relative positions of sensors and objects to facilitate understanding?
A drawing speaks more than 1000 words.
Hi, here are two pics of the sensors.
We figured out that if we erase the sensor.ping_cm() function of the code of any of two sensors, the readings weren't affected, so, it isn't about of the wiring, but the code instead.
Make a test by placing a wide and long strip of cardboard between the 2 sensors in such a way that the reflection of the sound of one does not reach the other.
Unless the object in front of one of the sensor is a parabolic reflector, the echo will be reflected just like the original pulse is sent as a cone of sound, not a single point like a laser.
You need to change from triggering both sensors at the same time, to triggering them alternately with time for the other pulse and echo to dissipate.
Paul
Hi Paul, we don't trigger the sensors at the same time, at least that's what we think.
This is part of our code:
NewPing der(5, 4, MAX_DISTANCE);
NewPing izq(3, 2, MAX_DISTANCE);
int d=der.ping_cm();
int i=izq.ping_cm();
As you can see, we use different Echo and Trigger pins for each sensor
@ruilviana Thank so much! Such a simple thing and it's been causing us problems all week. It worked with the delay! We changed it to 100 ms, but it still works.