Implementing a XL-MaxSonar sensor to Atmega 1280.

Hello, all

I am currently trying to get data of range finder sensor (XL-MaxSonar) using ATmega 1280 board with the following code. The problem is that serial monitor keeps showing wrong outputs which does not respond actual distance measurement at all. I already tried to play around with pin number which ends up with fail.
Could anyone give me a advice?

Thank you very much in advance.

int configPin = 39;//Set the sonar Calibration Pin

void setup() { //begin of program
Serial.begin(9600); //serial baud rate 9600
pinMode(configPin,OUTPUT); //make Calibration pin output

void loop(){ //looping of program
digitalWrite(configPin,HIGH); //raise the reset pin high
delay(120); //start of calibration ring
float sensorvalue = analogRead(0); //get analog sensor value from pin 0
float inchvalue = (254.0/1024.0) 2.0 sensorvalue; //convert to inches
Serial.print(“Sensed a-d value:”); //print a-d text
Serial.println(sensorvalue); //print a-d value
Serial.print(“Inch value=”); //print inch text
Serial.println(inchvalue); //print inch value
delay(1000); //optional delay 1 second
digitalWrite(configPin,LOW); //turn off Calibration ring and sensor
delay(1000); //delay 1 second

Cross posting. See:,89440.0.html