I have connected PING sensor to arduino mega 2560 adk
I have connected the SIG pin to analog pin A0
I am getting readings.
but the readings are in a specific range 300-500..
when i try bringing objects in front of the sensor,the values do not change much.
The values are not exact.
This is my code:
const int analogInPin = A0; // Analog input pin that the potentiometer is attached to
const int analogOutPin = 9; // Analog output pin that the LED is attached to
int sensorValue = 0; // value read from the pot
int outputValue = 0; // value output to the PWM (analog out)
void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
}
void loop() {
// read the analog in value:
sensorValue = analogRead(analogInPin);
// map it to the range of the analog out:
outputValue = map(sensorValue, 0, 1023, 0, 255);
// change the analog out value:
analogWrite(analogOutPin, outputValue);
// print the results to the serial monitor:
Serial.print("sensor = " );
Serial.print(sensorValue);
Serial.print("\t output = ");
Serial.println(outputValue);
//convert to cm
long dist=sensorValue*(0.03434);
Serial.print(dist);
// wait 10 milliseconds before the next loop
// for the analog-to-digital converter to settle
// after the last reading:
delay(10);
}
The ultrasonic waves of the sensor do not detect objects in front of it or maybe the waves get past through the objects,,Plz help.. Thanks in advance

How can i get exact readings in cms../?
The ouput in the serial monitor is like this
15sensor = 510 output = 127
17sensor = 464 output = 115
15sensor = 501 output = 124
17sensor = 477 output = 118
16sensor = 486 output = 121
16sensor = 493 output = 122
16sensor = 470 output = 117
16sensor = 506 output = 126
17sensor = 460 output = 114
15sensor = 513 output = 127
17sensor = 459 output = 114
15sensor = 506 output = 126
17sensor = 469 output = 116
16sensor = 493 output = 122
16sensor = 485 output = 120
16sensor = 477 output = 118
16sensor = 500 output = 124
17sensor = 464 output = 115
15sensor = 509 output = 126
17sensor = 458 output = 114
15sensor = 510 output = 127
17sensor = 464 output = 115
15sensor = 500 output = 124
17sensor = 477 output = 118
16sensor = 485 output = 120
16sensor = 492 output = 122
16sensor = 469 output = 116
16sensor = 506 output = 126
17sensor = 460 output = 114
15sensor = 512 output = 127
17sensor = 460 output = 114
15sensor = 505 output = 125
17sensor = 469 output = 116
16sensor = 493 output = 122
16sensor = 485 output = 120
16sensor = 477 output = 118
16sensor = 501 output = 124
17sensor = 464 output = 115
15sensor = 510 output = 127
17sensor = 458 output = 114
15sensor = 510 output = 127
17sensor = 464 output = 115
15sensor = 500 output = 124
17sensor = 477 output = 118
16sensor = 485 output = 120
16sensor = 493 output = 122
16sensor = 469 output = 116
16sensor = 506 output = 126
17sensor = 460 output = 114
Mostly the values are same evn if i move objects in frnt of the sensor