Ultrasonic Sensing Project

Hello,

I would like to use two ultrasonic sensing packages (2 triggers, 2 echos) to measure the distance between two ultrasonic sensors.

My initial idea is to use the trigger from Sensor A to send a ping to the echo of Sensor B, but I can't seem to get this setup to register any distance, let alone an incorrect one.

I'm using the NewPing library, and my code is basically as follows:

#include <NewPing.h>

#define triggerA 10
#define echoA 11
#define triggerB 12
#define echoB 13

NewPing sonar(triggerA, echoB, 50)

void setup(
Serial.begin(9600);
)

void loop(

delay(50);
Serial.print("Distance: ");
Serial.println(sonar.ping_cm());
Serial.println("cm");

delay(500);

)

It compiles correctly, but the output is always 0. Does anyone have any ideas?

Please use code tags when posting.

The setup won't work as it stands. The second sensor needs to be triggered at the same time as the first, otherwise it won't be listening for an echo.

Since the ultrasonic transmission from the second sensor will interfere with the measurement, you have to remove the transmit transducer.

Thank you for the response, I'll be sure to use code tags in the future. By remove the transmit transducer, are you implying that I'll need to physically remove it?

Either remove it or disable it by cutting a trace on the PCB.

Depends on the environment between the sensors. If there is nothing between the units to reflect the ping from sensor B back to itself (or closer than half the distance between the units), then the ping from sensor A will always be the first thing that sensor B hears, as desired. If so, then there's no need to remove or disable sensor B's transmit transducer, except to be on the safe side.

Will that concept work in the code then? Just setting the trigger and echo ports to pull from different sensors in the same function?

Or do I need to set it up as two separately functioning sensors and then either neuter the second one so that it will only ever receive the first's ping or ensure that the environment is such that the same is true?

The sensor does not listen for an echo unless triggered. So you must trigger BOTH sensors and do so at the same time. Connecting the TRIG pins to the same Arduino output should do the job.

Setting two sensors up facing each other and having them trigger from the same port has provided the expected result. Each sensor is reading half the actual distance between them, which, based on my code, means they are receiving the ping from the opposite sensor.