Pages: [1]   Go Down
Author Topic: Ping Sensor Frequency  (Read 705 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have a few ping sensors facing the same direction and was wondering if there is a way to change the frequency the sensors are chirping so they don't interfere with each other.
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 178
Posts: 8064
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It might be easier to just sample them in sequence.
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 168
Posts: 12428
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You could do neat things if the interfered....like

- setting up an ultrasound communication channel - beeping the bits over by ultrasound

- have the two pings at a known interval (e.g. 25 cm / 10 inch behind each other) and measure the dfference of arrival times.
   I think you can increase accuracy of the measurement.

- or one receiver to the left and one to the right of the source.

- making an interferometer, look for the border between interference and not. could possibly detect minimal movements.

just thinking out loud


 

Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Ontario, Ohio
Offline Offline
Full Member
***
Karma: 1
Posts: 205
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

just trigger one, then the other. Could someone advise whether bringing the pingpin back to low when the pingpin is in input mode is necessary? I figured it would be so that it still isn't reading while the next sensor is working. I added that into this code. This is untested, but it compiles. Let us know how it works.

Code:
const int pingPinLeft = 7;
const int pingPinRight = 8;

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

void loop()
{
  // establish variables for duration of the ping,
  // and the distance result in centimeters:
  long duration;
  int cmL, cmR;

  // 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(pingPinLeft, OUTPUT);
  digitalWrite(pingPinLeft, LOW);
  delayMicroseconds(2);
  digitalWrite(pingPinLeft, HIGH);
  delayMicroseconds(5);
  digitalWrite(pingPinLeft, 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(pingPinLeft, INPUT);
  duration = pulseIn(pingPinLeft, HIGH);

  // convert the time into a distance

  cmL = microsecondsToCentimeters(duration);
  Serial.print(cmL);
  Serial.print("cmLEFT");
  Serial.println();
  delay(100);
  digitalWrite (pingPinLeft, LOW);   // I don't know if this command is necessary, but it would make sense so it doesn't continue
                                                      // to read while the next sensor is working                                                             
  //////////////////////////////////////////////////////
  delay(1000);  //Time between sensor readings to "clear the airwaves"... so to speak. Could be much less or maybe is not needed.
  ///////////////////////////////////////////////////////
  // 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(pingPinRight, OUTPUT);
  digitalWrite(pingPinRight, LOW);
  delayMicroseconds(2);
  digitalWrite(pingPinRight, HIGH);
  delayMicroseconds(5);
  digitalWrite(pingPinRight, 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(pingPinRight, INPUT);
  duration = pulseIn(pingPinRight, HIGH);

  // convert the time into a distance

  cmR = microsecondsToCentimeters(duration);
  Serial.print(cmR);
  Serial.print("cmRIGHT");
  Serial.println();
  delay(100);
  digitalWrite (pingPinLeft, LOW);   // I don't know if this command is necessary, but it would make sense so it doesn't continue
                                                      // to read while the next sensor is working                           

}



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

« Last Edit: April 28, 2012, 09:51:34 pm by TeslaIaint » Logged

Offline Offline
God Member
*****
Karma: 3
Posts: 813
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If you are using shared ping and measure pins then you need to bring the pin low just to measure. Thus that seems necessary...
Or are you talking about the low period before the trigger pulse?
Logged

Ontario, Ohio
Offline Offline
Full Member
***
Karma: 1
Posts: 205
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I made comments in the code where I was wandering whether the command was needed or not . The commands/comments are just after the distance gets printed to the serial monitor for each sensor.
Logged

Offline Offline
God Member
*****
Karma: 3
Posts: 813
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

No, that write is not necessary. In fact, all it will do, is turn off the internal pull-up resistors, if they are on, because the pinMode hasn't changed since the pin was turned to input.

Also, because you already do a delay(100), there is no need to do a delay(1000) as well. Take out that second, longer, delay and you'll probably be fine.

Printing lots to the serial port may end up slowing you down. Make sure to use a high baud rate (57600, 115200) to minimize the impact of that, and make printed strings be sufficiently short.
Logged

Ontario, Ohio
Offline Offline
Full Member
***
Karma: 1
Posts: 205
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I would be concerned that the first sensor is still in input mode ready to receive while the second sensor is firing pulses.
Logged

Pages: [1]   Go Up
Jump to: