obligatory obscure reference

self-deprecating yet still self-promotional witty comment


Arduino: Reading the Maxbotix Ultrasonic Rangefinder

Filed under: Arduino,Hacking — jet @ 18:32

This was so easy it wasn’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’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.

This reads the voltage from the AN (analog) pin on the Maxbotix LV-EZ1 Ultrasonic Range Finder (I got mine at SparkFun). 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.

Here’s a simple program to read the sensor and report the range in inches on serial:

// read values from a LV-MaxSonar-EZ1 sensor
// this is for the Arduino MINI -- change the pin values to suit your board.
// jet@flatline.net
// 1 Dec 2007

int statusLed = 13;

int ez1Analog = 0;

void setup() {


void loop() {
int val = analogRead(ez1Analog);
if (val > 0) {
// The Maxbotix reports 512 steps of information on AN
// but we read that as 1024. Each step is 1", so we need
// to divide by 2 to get the correct rough range in inches.
// this value should also be calibrated for your particular
// sensor and enclosure
val = val / 2;
Serial.println(val); // inches

void blinkLed(int pin, int ms) {
digitalWrite(pin,LOW); // turn it off it was on


Powered by WordPress