2 HC-SR04 (1 as trigger 1 as echo)

I want to expand the range of my US sensor so I've tried to connect 2 US to the Arduino - 1 as a trigger and 1 as an echo (I'm trying to discover objects in front of my car).

my code :

#include "NewPing.h"

const int trigPinL = 7;
const int trigPinR = 12;
const int echoPinL = 8;
const int echoPinR = 13;

long durationF;
int distanceF;

NewPing sonarL(trigPinL, echoPinR, 1000);

void setup() {
Serial.begin(9600); // set up Serial library at 9600 bps
pinMode(trigPinL, OUTPUT); // Sets the trigPin as an Output
pinMode(trigPinR, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPinL, INPUT); // Sets the echoPin as an Input
pinMode(echoPinR, INPUT);


void loop() {
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPinL, LOW);
digitalWrite(trigPinL, HIGH);
digitalWrite(trigPinL, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds
durationF = pulseIn(echoPinR, HIGH);

distanceF= durationF*0.034/2;

// Prints the distance on the Serial Monitor
Serial.print(" ");

I've tried to use the NewPing library too, but it won't solve the problem.

Does someone have an idea how I can use one sensor as trig and one as an echo?

thanks ahead.

Perhaps you missed this in the description of the operation of the sensor: "When triggered, the ultrasonic sensor generates eight acoustic (ultrasonic) wave bursts and initiates a time counter. As soon as the reflected (echo) signal is received, the timer stops. The output of the ultrasonic sensor is a high pulse with the same duration as the time difference between transmitted ultrasonic bursts and the received echo signal.".

Then how can I overcome this problem or start the timer without starting the trig on the sensor?

Likely will need a different sensor!

Hi, @liavtol
Welcome to the forum.

Please read the post at the start of any forum , entitled "How to use this Forum".

How do you think separating the Tx and RX units will increase your range?

The pulse is of fixed power, that dictates the range, the detection of the return reflection relies on a detectable signal.
The further away the target the weaker the return signal until the receiver can no longer detect it.

Spacing the Tx and the Rx will not make the return signal any stronger.

Tom... :grinning: :+1: :coffee: :australia:

Remove the sender from the receiver device and trigger them both with the same output pin. The one with the missing sender will start timing and will detect the echo from the other sender.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.