{"id":25,"date":"2007-12-02T18:32:41","date_gmt":"2007-12-02T23:32:41","guid":{"rendered":"https:\/\/flatline.net\/journal\/2007\/12\/02\/arduino-reading-the-maxbotix-ultrasonic-rangefinder\/"},"modified":"2008-03-01T12:55:05","modified_gmt":"2008-03-01T17:55:05","slug":"arduino-reading-the-maxbotix-ultrasonic-rangefinder","status":"publish","type":"post","link":"https:\/\/flatline.net\/journal\/?p=25","title":{"rendered":"Arduino: Reading the Maxbotix Ultrasonic Rangefinder"},"content":{"rendered":"<p>This was so easy it wasn&#8217;t even funny.  I think I spent more time discovering that I was trying to read the wrong pin than I did actually getting this to work.  The main reason I&#8217;m posting it is so that people considering this rangefinder can see just how easy it is to use compared to some of the other rangefinders out there.<\/p>\n<p>This reads the voltage from the AN (analog) pin on the Maxbotix LV-EZ1 Ultrasonic Range Finder (I got mine at <a href=\"http:\/\/www.sparkfun.com\">SparkFun<\/a>).  Connect power and ground on the Maxbotix to a reference ground and power, then connect the AN pin to the analog input of your choice. <\/p>\n<p>Here&#8217;s a simple program to read the sensor and report the range in inches on serial:<\/p>\n<p><code><br \/>\n\/\/-*-C-*-<br \/>\n\/\/ read values from a LV-MaxSonar-EZ1 sensor<br \/>\n\/\/ this is for the Arduino MINI -- change the pin values to suit your board.<br \/>\n\/\/ jet@flatline.net<br \/>\n\/\/ 1 Dec 2007<\/p>\n<p>\/\/Output<br \/>\nint statusLed = 13;<\/p>\n<p>\/\/intput<br \/>\nint ez1Analog = 0;<\/p>\n<p>void setup() {<br \/>\n    pinMode(statusLed,OUTPUT);<br \/>\n    pinMode(ez1Analog,INPUT);<\/p>\n<p>    beginSerial(9600);<br \/>\n}<\/p>\n<p>void loop() {<br \/>\n    int val = analogRead(ez1Analog);<br \/>\n    if (val > 0) {<br \/>\n\t\/\/ The Maxbotix reports 512 steps of information on AN<br \/>\n\t\/\/ but we read that as 1024.  Each step is 1\", so we need<br \/>\n\t\/\/ to divide by 2 to get the correct rough range in inches.<br \/>\n\t\/\/<br \/>\n\t\/\/ this value should also be calibrated for your particular<br \/>\n\t\/\/ sensor and enclosure<br \/>\n\tval = val \/ 2;<br \/>\n\tSerial.println(val); \/\/ inches<br \/>\n    }<br \/>\n    blinkLed(statusLed,100);<br \/>\n}<\/p>\n<p>void blinkLed(int pin, int ms) {<br \/>\n    digitalWrite(pin,LOW); \/\/ turn it off it was on<br \/>\n    digitalWrite(pin,HIGH);<br \/>\n    delay(ms);<br \/>\n    digitalWrite(pin,LOW);<br \/>\n    delay(ms);<br \/>\n}<\/p>\n<p><\/code><\/p>\n<p>[tags]arduino,maxbotix[\/tags]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This was so easy it wasn&#8217;t even funny. I think I spent more time discovering that I was trying to read the wrong pin than I did actually getting this to work. The main reason I&#8217;m posting it is so that people considering this rangefinder can see just how easy it is to use compared [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17,11],"tags":[],"class_list":["post-25","post","type-post","status-publish","format-standard","hentry","category-arduino","category-hacking"],"_links":{"self":[{"href":"https:\/\/flatline.net\/journal\/index.php?rest_route=\/wp\/v2\/posts\/25","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/flatline.net\/journal\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/flatline.net\/journal\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/flatline.net\/journal\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/flatline.net\/journal\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=25"}],"version-history":[{"count":0,"href":"https:\/\/flatline.net\/journal\/index.php?rest_route=\/wp\/v2\/posts\/25\/revisions"}],"wp:attachment":[{"href":"https:\/\/flatline.net\/journal\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=25"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/flatline.net\/journal\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=25"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/flatline.net\/journal\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=25"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}