ARDUINO and MaxSonar EZ1Jul 8, 2009 Edit
Update: 13 July 2009, Resolved with the help of Bob Gross. User error see notes below.
I found a MAX Sonar EZ1 sensor at my local electronics store and decided to try it out. The selling features of this sensor for me was
- Cheap (< $20), and immediately available, (impulse buy)
- Analog and serial pins, with documentation, oh how I love documentation on electronic parts.
- Operated on 5v, the arduino has a 5V Pin making it as easy as can be to hook it up to the board.
- Mounting holes.
I mounted the sensor on an €˜L" bracket and pointed it at a wall about 36 inches away. I connected the GRD, 5V, Analog pin to my Arduino chip and started reading data. After playing around with it for a while, I found it hard to get reliable data from this sensor.
Took in 100 readings getting results anywhere from 50-255, unreliable data. I searched Google and found a few other people using this sensor with the Arduino. http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1226321702
Apparently these range finders (less then $100) are notorious for giving spiked reading every once in a while. So all data read from these sensors should be averaged over ~10 or more readings for better accuracy. Also grounding the unused pins can sometimes help.
So I grounded all my unused analog pin (this is where I made my miss take, see below) and changed my code to find the average over 100 readings as the result. Then tested the results for 10k times and found the results to be wildly different between each session.
After a few more hours of playing around with it I gave up. I considered connected to the serial pins but decide it was more work then it was worth. It could be that this particular sensor was damaged or it could be the brand, either way it didn"t work out for me.
I have included my source code for your reference.
Update (12 July 2009): After getting contacted by Bob Gross of MaxBotix Inc. I decided to give this sensor anther chance. Using the code above I connected analog pin 1 (NOT Pin 0) to the “AN” ping on the chip. GND to GND, +5 to 5V. Picture Uploaded the code and connected Hyper terminal capturing the output to a text file and let it run for about an ~hour poiting at the roof. The results where variable as shown in the output.
Update (13 July 2009)
User error. Boy do I feel like an idiot today. When I grounded the analog pins (as noted above) I also connected the pin that I was using for the sensor to all the other analog pins.
I removed the grounding wire, and the connection between all the pins and got reliable results. The sensor works fine this was entirely human error. I decided to keep using the averaging code above with ~10 reads instead of 100 for speed.
My aploagies to Bob Gross and MaxBotix Inc for my error and false claims that the sensor didn’t work. Thank you for your help.