Hello everyone.I am trying to make a distance measurement system using hc sr04 ultrasonic sensor and Arduino Diecimila board.But when I am connecting the sensor with arduino it is giving very erratic readings.Even for smaller distance it is showing value of around 150cm(snap is attached).As recommended am using new ping library v1.5 and arduino IDE v1.6.4.Earlier thought it may be due to faulty sensor but even new sensor showing same behaviour.I am totaly confused where the actual problem lies .Can anyone please help me to solve this puzzle.Following is the code that I am using
#include <NewPing.h>
#define TRIGGER_PIN 3
#define ECHO_PIN 2
#define MAX_DISTANCE 200
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);
void setup() {
Serial.begin(9600); .
}
void loop() {
delay(1000);
unsigned int uS = sonar.ping();.
Serial.print("Ping: ");
Serial.print(sonar.convert_cm(uS));
Serial.println("cm");
}