Hello all,
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.
Board: Arduino Ethernet Rev 3 - http://arduino.cc/en/Main/ArduinoBoardEthernet
Board | Sensor |
---|---|
Ground | Ground |
5V | 5V |
Pin ~6 | Trigger |
Pin ~5 | Echo |
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:
Ping: 264cm
Ping: 0cm
Ping: 0cm
Ping: 0cm
Ping: 263cm
Thank You!