Is it possible to use 2 ultrasonic modules (HC-SR04) crossover?

Hi,

I tried to setup a circuit with an Arduino Nano and two ultrasonic modules (HC-SR04), such that the second module receives the signal of the first module. The modules are positioned 20 cm apart from each other "looking" at each other. However, that doesn't work as expected. Here's my simple sketch:

const int echoPin = 2; // The echo pin of the ultrasonic module 2 is connected to D2 of the Arduino Nano
const int trigPin = 3;   // the trigger pin of the ultrasonic module 1 is connected to D3 of the Arduino Nano
long duration;
void setup() {
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
Serial.begin(9600);
}
void loop() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
Serial.print("Duration: ");
Serial.println(duration);
delay(1000);
}

All I get are lines saying "Duration: 0", which means, something went wrong.

I wanted to use the sensors for measuring wind speed. Therefore, I cannot use them in the usual two-way manner, where one measures the time between signal emittance and receipt of the reflected signal. Wind related deviations of the travel time of an ultrasonic signal would cancel out when the signal is reflected. So I need one-way measurements of the duration it takes for an ultrasonic signal to travel over a given distance.

I assume, the function pulseIn() is somehow connected to the triggering process of a module, and therefore doesn't react to a signal triggered at a different module. Nevertheless, I am pretty sure that the second module is able to detect the ultrasonic signal of the first module. If so, there should be a way to measure the duration between send and receipt across two modules, but I don't know how. In the worst case, I would have to solder out the receiving sensor of the module and place it opposite to the sender, but I would prefer a software solution if possible.

Hopefully, someone out there is able to put me on the right track.

Thanks a lot in advance
fullcane

That has been done before, and if you google something like

arduino wind speed sensor

you will find some examples, including several links to Arduino forum posts on the topic.

For example, check out the paper and links in posts #10, #36, and #88 by @jremington (Ignore the OP’s posts…they’re bewildered and I doubt they ever got their system to work.)

I don't have two HC-SR04s to experiment with, but maybe this helps:
The HC-SR04 has a window built-in. In normal use, objects closer than 2cm or further than 400cm are rejected (be aware that the sound travels twice that distance).
To force unit2 to listen to unit1 you need to trigger them both at the same time, by connecting them to the same output. Now you need to measure the pulse lengths from both units (be aware that the sound travels only once now).

Use this algorithm:

  • Trigger both units.
  • Measure pulse of unit1.
  • Trigger both units.
  • Measure pulse of unit2.

The difference allows you to calculate wind speed and direction (hoping wind speed was constant).

(The function pulseIn() can measure only 1 unit at a time. If you're familiar with direct register access you can write a function yourself.)

As described in the short paper (PDF file which includes the Arduino code) linked in post #2 above.

Sorry, hadn't seen it yet.

Thanks a lot for your quick responses. Now I know, where my mistake was sitting: I need to trigger both modules simultaneously each time in order to get things going. In my original setting, I had only connected the trigger pin of module 1 to the trigger pin of the Arduino and that's why module 2 didn't react. Since the trigger pins of both modules are now connected to the trigger pin of the Arduino everything works as expected.