I am struggling to use the MaxSonar-WR1 ultrasonic rangefinder with the Arduino Duemilanove (328 chip) and wonder if anyone can provide some tips to the uninitiated
Following the datasheet www.maxbotix.com/uploads/LV-MaxSonar-WR1-Datasheet.pdf,
I decided to use pulse width output, pin 2, output....since I was familiar with PW output on the Parallax Ping))) ultrasonic rangefinder. Power was provided for the WR1 from a benchtop power supply at 5.0V and the ground of the WR1 was connected to the Arduino ground.
I borrowed code from the code I had used with the Ping))) sensor, removing the pulse generating code which the WR1 doesnt need and adjusting the pulse width:distance setting to 147uS/inch:
int pingPin = 7;
void setup()
{
Serial.begin(9600);
}
void loop()
{
long duration, inches, cm;
pinMode(pingPin, INPUT);
duration = pulseIn(pingPin, HIGH);
// convert the time into a distance
inches = microsecondsToInches(duration);
Serial.print(inches);
Serial.print("in, ");
Serial.println();
delay(100);
}
long microsecondsToInches(long microseconds)
{
return microseconds / 147/ 2; // MaxSonar says use 147uS/inch in calculating
distance.
}
When I read the values output on the Arduino serial monitor, its showing 5” regardless of where I point the sensor. When I put my hand close to the face of the sensor (this is an unreadable distance for this sensor) it reads 20+”.
I also tried using serial communication mode, connecting sensor pin 5 to arduino pin 0/RX, but I wasn't sure how to clear the code (listed above) from the Arduino memory ()so that I could hopefully just use the serial monitor.
Any advice in correcting the problem(s) with this gameplan would be greatly appreciated.