Go Down

Topic: 1 TRX to 2 RX on HC-SR04 (Read 1 time) previous topic - next topic

anura92

Hi guys

Recently I bought couple HC-SR04 Ultrasonic sensor from ebay. So Yesterday I tested each one of them and they worked fine. Now I would like to test transmitting on one HC-SR04 sensor and receive the ping on another 2 HC-SR04 sensors. However I wired up the circuit below and used the code but all I get on the serial monitor was 0cm. Anyone know where i went wrong?




Code: [Select]

int TrigPin = 12;
int EchoPin1 = 11;
int EchoPin2 = 10;

void setup()
{
  Serial.begin(9600);
  pinMode(TrigPin,OUTPUT);
  pinMode(EchoPin1,INPUT);
  pinMode(EchoPin2,INPUT);
}
void loop()
{
  int distance1,duration1,distance2,duration2;
 
  digitalWrite(TrigPin1,HIGH);
  delayMicroseconds(11);
  digitalWrite(TrigPin1,LOW);

  duration1 = pulseIn(EchoPin1, HIGH);//EchoPin received high start counting until the receiver to the low,return to the count valu
  distance1 = duration1/29/2;//Calculating the distance  cm
 
  duration2 = pulseIn(EchoPin2, HIGH);//EchoPin received high start counting until the receiver to the low,return to the count valu
  distance2 = duration2/29/2;//Calculating the distance  cm
                           
 
  Serial.print("Echo 1:" + distance1 + "cm" );
  Serial.print(" ");
  Serial.print("Echo 2:" + distance2 + "cm" );
  Serial.println();
  delay(1000);
}

RIDDICK

Hi!

what if u use the same sketch as yesterday?
then u could find out, if  it is the wiring or the sketch...

Have fun...
-Arne

anura92

Yesterday i ran the example sketch for 1 ultrasonic. Its was just to test each one of them. The problem occurs when i try to use transmitter of one ultrasonic and receiver on another.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy