2  pings on a Duemilanove

Im using the Ping Source code provided in the examples but cannot get the left one to read. Is it as easy as duplicating the entire code cause it seem to run slower.

const int pingPinr = 7; const int pingPinl = 6;

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 durationr, inchesr; long durationl, inchesl;

// 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(pingPinr, OUTPUT); digitalWrite(pingPinr, LOW); delayMicroseconds(2); digitalWrite(pingPinr, HIGH); delayMicroseconds(5); digitalWrite(pingPinr, LOW);

pinMode(pingPinl, OUTPUT); digitalWrite(pingPinl, LOW); delayMicroseconds(2); digitalWrite(pingPinl, HIGH); delayMicroseconds(5); digitalWrite(pingPinl, 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(pingPinr, INPUT); durationr = pulseIn(pingPinr, HIGH);

pinMode(pingPinl, INPUT); durationl = pulseIn(pingPinl, HIGH);

// convert the time into a distance inchesr = microsecondsToInches(durationr); inchesl = microsecondsToInches(durationl);

Serial.print(inchesr); Serial.print(" right, "); Serial.print(inchesl); Serial.print(" Left, "); Serial.println();

delay(10); }

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

You’re firing the right one, then the left one, then waiting for the echo on the right Ping, then the left.
How do you know that the two Pings won’t pick up each other’s echo?

Right now I have one facing foward and one facing backwards.

Im sure the signals are overlaping

As I get my programming better i will fire one at a time and wait for the return. left, right,left,right you get the idea.

But for now i cant get the seperate code working together

So, fire one, wait for the echo from that sensor, then fire the other one and wait for the echo from that. I don't see what the problem is.

What you said first made sense

"you're firing the right one, then the left one, then waiting for the echo on the right Ping, then the left."

I writing the code now

thanks

This works

I put a delay between the two reads to give better seperation from left to right.

Both sensors are facing foward now.

const int pingPinr = 7; const int pingPinl = 6;

void setup() {

Serial.begin(9600); }

void loop() {

long durationr, inchesr; long durationl, inchesl;

pinMode(pingPinr, OUTPUT); digitalWrite(pingPinr, LOW); delayMicroseconds(2); digitalWrite(pingPinr, HIGH); delayMicroseconds(5); digitalWrite(pingPinr, LOW);

pinMode(pingPinr, INPUT); durationr = pulseIn(pingPinr, HIGH);

inchesr = microsecondsToInches(durationr);

delay (250);

pinMode(pingPinl, OUTPUT); digitalWrite(pingPinl, LOW); delayMicroseconds(2); digitalWrite(pingPinl, HIGH); delayMicroseconds(5); digitalWrite(pingPinl, LOW);

pinMode(pingPinl, INPUT); durationl = pulseIn(pingPinl, HIGH);

inchesl = microsecondsToInches(durationl);

Serial.print(inchesr); Serial.print(" Right, "); Serial.print(inchesl); Serial.print(" Left, "); Serial.println();

delay(200); }

long microsecondsToInches(long microseconds) { return microseconds / 74 / 2; }