Parallax LaserPING 2m Rangefinder
Jaguar
Posts: 3
Hello to everyone,
I need some help, I can't get my sensor to work properly.
I don't move anything but the values change all the time
the obstacle is 4 cm from the sensor.
thank you for your help
i use arduino mega and sensor is connected in pin A7 PWM
const int pingPin = 7; void setup() { // initialize serial communication Serial.begin(9600); } void loop() { // establish variables long duration, inches, mm; //Initialize sensor in Serial mode pinMode(pingPin, OUTPUT); digitalWrite(pingPin, LOW); delayMicroseconds(2); digitalWrite(pingPin, HIGH); delayMicroseconds(5); digitalWrite(pingPin, LOW); //Initialize the measurement of the echo pinMode(pingPin, INPUT); duration = pulseIn(pingPin, HIGH); //convert into a distance inches = microsecondsToInches(duration); mm = microsecondsToMillimeters(duration); Serial.print( "Duration: " ); Serial.println( duration ); Serial.print(inches); Serial.print("in, "); Serial.print(mm); Serial.print("mm"); Serial.println(); delay(1000); } long microsecondsToInches(long microseconds) { return microseconds * 6.752; } long microsecondsToMillimeters(long microseconds) { return microseconds * 171.5; }
Comments
Question: what are you using as a target? If the target is narrow, the sensor may have difficulty “seeing” it. Remember that the field of illumination is 23° degrees, and the field of view is 55° degrees. Stick a big one out there initially for debugging and put it midway between the allowable measuring extremes... ie range should be about 75 cm.
Perhaps you could also try putting the device into serial mode instead of using pulse mode. Then you can eliminate any possibility of your code being wonky and just read the distance value directly as serial data.
Thank you for your reply,
my target is a big box, I have tried many targets, but always the same thing.
I wrote a code for the serial mode but I have only 0 as values.
Don't have experience with this sensor or Arduino, but according to the documentation at https://www.parallax.com/package/laserping-2m-rangefinder-product-guide/, the LaserPing sends ASCII data in Serial mode.
Do you need to convert from ASCII to integer before printing to the terminal?
"...In Serial mode, LaserPING will constantly send new measurement data in ASCII format. The
value will be in millimeters, and followed by carriage return character (decimal 13). A new value
will be transmitted each time the sensor receives a valid reading, typically once every 45 ms...."
Since you didn't share your code to drive the Laser Pin sensor I assume that it's not setup correctly.
I don't have an UNO to try this with but I do have an Arduino Zero.
Here is the code I came up with for the pulse input:
Mike
I have tried both solutions but neither gives me correct values. Is this sensor really working or is there a problem?
I did a lot of research on google and tried several codes but my problem is still the same.
I have two Parallax sensors and both give me different values.
Do you have a serial to USB converter ? Something like the PropPlug ?
You could put LaserPing into serial mode (the user guide mentions which of the golden settings pads to short together, to make Serial mode the default).
Then attach the LaserPing serial output pin to the PropPlug RX pin.
And on the PC, open a serial terminal with baud rate set to whatever the LaserPing user guide says it uses.
Then (after power cycling the LaserPing) you can see the data coming direct from the LaserPing, and you should be able to determine if the issue is with the Arduino or the LaserPing.
(And if you have a fixed distance test object, you could compare your results to the same distance measured with your Arduino code...)