I'm trying to work with an ultra sonic sensor #DYP-ME007Y (Amazon.com). I have tried to use the NewPing Library (https://code.google.com/p/arduino-new-ping/) but the results are plain wrong and very sporadic. Any help would be great, not sure what the issue could be.
My Code is below based on the example the library provides:
#include <NewPing.h>
#define TRIGGER_PIN 6 // Arduino pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN 5 // Arduino pin tied to echo pin on the ultrasonic sensor.
#define MAX_DISTANCE 400 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
void setup() {
Serial.begin(115200); // Open serial monitor at 115200 baud to see ping results.
}
void loop() {
delay(1000);
Serial.print("Ping: ");
Serial.print(sonar.ping_cm());
Serial.println("cm");
}
The Output is below, the 0 is when I put something about 1 foot from the sensor, the code is very straight forward, not sure what the issue could be:
To update this, I switched the ports around in hopes that that would help as I noticed with the newPing library it used 1 PWN pin and one regular digital pin. But to no avail, readings still make no sense and jump around a lot.
Here is the picture I am referring to from the NewPing Library google page:
Finally got this working with the original code. Ends up the external sensor plug on my sensor wasn't the 'straightest' so it wasn't making good contact, i had to play with that connection a bit.
With Extension, that is what was fouling me up, the sensor plug though plugged in wasn't making good contact. It was 'effective' from my short testing period in the 30 - 120 cm range. It did seem to be a little sporadic as far as having a few reading jumps, that I didn't get with the ping))) sensor, but that might have been the connector as well. I ended up scrapping as the lower threshold didn't meet our needs. I'm currently trying to swap the sensors to waterproof versions on the ping sensor with no luck yet but my fingers are crossed.