Shop OBEX P1 Docs P2 Docs Learn Events
Ping sensors — Parallax Forums

Ping sensors

I had these ping sensor laying around for quiet some time and decided it's time to take a look at them. And since I have both sensors I thought maybe I should compare the two and see if they both work the same.

The nice thing about the laser ping sensor is that it has an ascii mode that will just give you the answer in millimeters rather than measuring the PWM value. I also notice there was not a driver for the laser ping sensor only the ultrasonic version.

So I quickly wrote up a laser ping driver and made it so that it would run in a cog so I could just set it and read the answers. I also had it average the answer over 10 reading so it would be a little more stable.

Here is the test code:
#include "simpletools.h"
#include "laserping.h"


#define LASER 16
#define PING 0

int i;

int main()
{

  laserping_start('S', LASER);
  
  while(1)
  {
    i = laserping_distance();
    printi("Distance: %d\n", i);
    pause(500);
  }  
}
My setup was a box positioned 150 mm in front of the sensors.

So first the code puts the laser ping into serial mode and displays the answer. The answer was about 147 but jumped around 145 to 150. Never came back as a constant distance.

Next I put the unit into PWM mode and had to multiple by 174 and divide by 1000 to get the same readings. The manual states you should use 171.5 but that did not seem to be enough to come up with the same readings. Maybe my unit is not calibrated the same.

Next I tested the ultrasonic ping sensor using the same setup. For this unit I used the 171.5 value since it produced about the correct distance with a reading of 151. The value did not move around like the laser sensor and was a constant 151. Now I don't know if the distance is from the center of the speakers or measured from the printed circuit board. That would make about a 10mm difference in the measurement.

Anyway the to sensors are very close in distance but the ultrasonic unit produce more stable measurements.

I did find out that adding a moving a light source around caused the reading of the laser ping sensor to jump around a bit.

Being they are pin compatible is a nice touch and thinking that a light sensor should be better than a sound one may not be the case.

Mike

Comments

  • Mike:
    A very helpful post. I have been working with the Ping Ultrasonic detectors and not found the LaserPing to be "code compatible" using the Arduino Ping library.

    How can I access the simpletools.h and laserping.h libraries that you reference? I don't find them in the Arduino IDE library manager.

    Thanks.
  • Sorry, I wrote my own library to drive both sensors.

    I uploaded it to the Object exchange and you can find it there: Laser Ping Library

    Mike
  • Mike: Thanks.
Sign In or Register to comment.