Go Down

Topic: how to let 2 receivers receive a signal from the same transmitter? (Read 1 time) previous topic - next topic

MoleforBrain

Hi all,

I tried to use 1 transmitter (connected separately from the receiver using different arduino uno boards) transmit a pulse and using 2 identical sensors (already removed the transmitter cans) to receive it, but only 1 receiver managed to receive the signal while the other receiver just displays 0cm.

Any idea what could have caused this and what should i do in order for both of the receivers to receive the same transmitted signal?

Below is my code for the receivers side:


Code: [Select]
const int pingPin1 = 2;
const int pingPin2 = 3;
const int trigpin = 4;
int trigstate = 0;

void setup() {
  // initialize serial communication:
  Serial.begin(9600);
  pinMode (trigpin, INPUT);
}

void loop() {
  // establish variables for duration of the ping,
  // and the distance result in inches and centimeters:
  long duration2, duration1, cm1, cm;
  trigstate = digitalRead(trigpin);
  
  if(trigstate == LOW)
  {

  // The PING))) is triggered by a HIGH pulse of 2 or more microseconds.
  // Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
  pinMode(pingPin1, OUTPUT);
  pinMode(pingPin2, OUTPUT);
  digitalWrite(pingPin1, LOW);
  digitalWrite(pingPin2, LOW);
  delayMicroseconds(2);
  digitalWrite(pingPin1, HIGH);
  digitalWrite(pingPin2, HIGH);
  delayMicroseconds(5);
  digitalWrite(pingPin1, LOW);
  digitalWrite(pingPin2, LOW);

  // The same pin is used to read the signal from the PING))): a HIGH
  // pulse whose duration is the time (in microseconds) from the sending
  // of the ping to the reception of its echo off of an object.
  pinMode(pingPin1, INPUT);
  pinMode(pingPin2, INPUT);
  duration1 = pulseIn(pingPin1, HIGH);
  duration2 = pulseIn(pingPin2, HIGH);

  // convert the time into a distance
  cm = microsecondsToCentimeters(duration1);
  cm1 = microsecondsToCentimeters(duration2);

  Serial.print(cm);
  Serial.print("cm");
  Serial.println();
  Serial.print(cm1);
  Serial.print("cm1");
  Serial.println();
  Serial.println();

  delay(200);
  }}
  

long microsecondsToInches(long microseconds) {
  // According to Parallax's datasheet for the PING))), there are
  // 73.746 microseconds per inch (i.e. sound travels at 1130 feet per
  // second).  This gives the distance travelled by the ping, outbound
  // and return, so we divide by 2 to get the distance of the obstacle.
  // See: http://www.parallax.com/dl/docs/prod/acc/28015-PING-v1.3.pdf
  return microseconds / 74 / 2;
}

long microsecondsToCentimeters(long microseconds) {
  // The speed of sound is 340 m/s or 29 microseconds per centimeter.
  // The ping travels out and back, so to find the distance of the
  // object we take half of the distance travelled.
  return microseconds / 29 / 2;
}

weedpharma


Paul_KD7HB

Try switching the receiver/pin connections and see if the other receiver now gets the signal. If so, does that help debug your program?

Paul

DaveEvans

Could be because the first pulseIn blocks the second pulseIn.

MoleforBrain

Please identify the Tx and Rx you are using.

@weedpharma
Oh I did not use any Tx or Rx pin in the Arduino.

Try switching the receiver/pin connections and see if the other receiver now gets the signal. If so, does that help debug your program?
@Paul_KD7HB
yeah it does, but the previous receiver did not.


Paul_KD7HB

@weedpharma
Oh I did not use any Tx or Rx pin in the Arduino.

@Paul_KD7HB
yeah it does, but the previous receiver did not.


Does that help you determine one receiver works and the other does not?

Paul

MoleforBrain

Does that help you determine one receiver works and the other does not?

Oh it's like at first receiver A receives and receiver B does not. If i swap the pins, it'll end up with receiver B receives and receiver A does not. something like this

weedpharma

@weedpharma
Oh I did not use any Tx or Rx pin in the Arduino.

What PARTS did you use for the Tx and Rx?

Weedpharma

MoleforBrain

What PARTS did you use for the Tx and Rx?
Currently I'm not using any parts except for the 2 sensors and a transmitter on the other Arduino board, i left the Tx and Rx unused.

DaveEvans

Weed: it appears that he's using the Parallax Ping))) for the Tx and Rx.  It's buried in the code - see the microsecondsToInches function.


It seems that there are three Ping)))s...two receiving and one transmitting.

It's not clear whether the receiving Ping))) is actually giving him the correct distance.  It "receives the signal" (post #1), but is it the correct distance?  And if the pins are swapped, is it still the correct distance?




MoleforBrain

Weed: it appears that he's using the Parallax Ping))) for the Tx and Rx.  It's buried in the code - see the microsecondsToInches function.


There are three Ping)))s...two receiving and one transmitting.

It's not clear whether the receiving Ping))) is actually giving him the correct distance.  It "receives the signal" (post #1), but is it the correct distance?  And if the pins are swapped, is it still the correct distance?

Ah! I didn't know! And yes, the distance is off but that is most probably my calculation part as the pulse did not "bounce back". The value is the same even when the pins are swapped so i'm guessing it should be correct

DaveEvans

Regarding this code:

Code: [Select]
  pinMode(pingPin1, INPUT);
  pinMode(pingPin2, INPUT);
  duration1 = pulseIn(pingPin1, HIGH);
  duration2 = pulseIn(pingPin2, HIGH);


If Rx2 (on pin2) is closer to the Tx than Rx1 (on pin1), then what happens to the second pulseIn?

If Rx2 is farther from the Tx than Rx1, then what happens to the second pulseIn?

I suppose you could delete the pulseIns and do your own timing with interrupts (or a "while true" loop, polling the pins, if fast enough), keeping track of low/high and high/low transition times, and having a timeout to prevent hangs in case nothing is received.

PS: also, I don't see where you are triggering the Tx (presumably attached to the "trigpin") in the code in your first post.  Is that really the sketch you are using?  How about posting a schematic and some photos, so we don't have to rely on your written descriptions of what you are doing.


Go Up