Pages: [1]   Go Down
Author Topic: 1 TRX to 2 RX on HC-SR04  (Read 1071 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 14
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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);
}
Logged

Brunsbüttel, SH, F.Rep.GERM
Offline Offline
God Member
*****
Karma: 4
Posts: 596
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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...
Logged

-Arne

Offline Offline
Newbie
*
Karma: 0
Posts: 14
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Pages: [1]   Go Up
Jump to: