Ping Sensor

I've used the ping sensor to measure distance to a wall and it works great. How ever I would like to use 2 sensors to read direction(left and right). My thought was to remove the transmit senor on each ping module leaving only the receiver. Then use the transmitter that was removed from one the ping modules to send a ping to both modules positioned to the left and the right at a set distance, moving the transmitter from left to right would change the angle to each receiver hence changing the distance from the transmitter to each ping receiver. I've got the transmitter to (ping)communicate with one of the receivers resulting in a distance output, how ever I haven't been able to successfully communicate to both receivers simultaneously. Can anyone shed some light on this or has anyone ever tried this with success? I'll be sure to post my current code this afternoon as well.

Thank you in advance for any help you can provide.

Dave

Single process microcontroller can't read 2 incoming signals at the same time.

If you had the signals coming in to the same port and read the port multiple times until you determined that either both were received, or had timed out, you could get there. Example - you send a ping out in two directions at the same, then you read PORTD over and over looking for the 2 bits to change, note the time that each changed as part of the distance calculation.

Thank you so much for shedding light on this, I didn't realize you couldn't read more than 2 incoming signals at the same time.

I have each output one from each ping sensor that have been set to input digital pins 10 and 11(pingPin 1 & pingPin2). And only 1 will give an output at a time, I've tried swapping the pins and this confirms they function, but only on the "const int" pin that's first on the list. Is there a way manipulate my code to accomplish this or am I chasing the impossible.

Thank you again

Dave

Please find the current code I'm using below

// this constant won't change.  It's the pin number
// of the sensor's output:
const int pingPin1 = 10;
const int pingPin2 = 11;

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

void loop()
{
  // establish variables for duration of the ping, 
  // and the distance result in inches and centimeters:
  long duration1, inches1, cm1;
  long duration2, inches2, cm2;

  // 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);
  duration1 = pulseIn(pingPin1, HIGH);
  pinMode(pingPin2, INPUT);
  duration2 = pulseIn(pingPin2, HIGH);

  // convert the time into a distance
  inches1 = microsecondsToInches(duration1);
  cm1 = microsecondsToCentimeters(duration1);
  
  // convert the time into a distance
  inches2 = microsecondsToInches(duration2);
  cm2 = microsecondsToCentimeters(duration2);
  
  Serial.print(inches1);
  Serial.print("in1, ");
  Serial.print(cm1);
  Serial.print("cm1");
  Serial.println();
  
  Serial.print(inches2);
  Serial.print("in2, ");
  Serial.print(cm2);
  Serial.print("cm2");
  Serial.println();
  
  delay(100);
}

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;
}