Let's Make Robots!

Calibration problems with a Maxibotics XL-EZ4

Ok, here's the deal. Today, I got my fantastically awesome order from sparkfun. It included:

The Maxibotics XL-EZ4 Rangefinder

The JPEG Compression Camera

I managed to soder some wires to three pins of the EZ4 without burning the house down. I got GND, +V, and pin 2 (Digital signal)

I even managed to get some programming on my Arduino to work with it (Modded the PING))) library). However, the debug terminal does not go to 0 cm, although the sensor supposedly detects 0-range obstacles. I have tried using the number it came with, 29, and the number reccomended for conversion of time to distance by Maxibotics, 58. 58 let it get closer to 0, but I fear it messed up the actual length of a centimeter, as interpreted by the Arduino. Here is the code, with the number I need help with in bold and italic.

   This sketch reads a EZ4 ultrasonic rangefinder and returns the distance to the closest object in range. To do this, it sends a pulse to the sensor to initiate a reading, then listens for a pulse to return.  The length of the returning pulse is proportional to

   the distance of the object from the sensor.

  The circuit:

            * +V connection of the EZ4 attached to +5V

            * GND connection of the Ez4 attached to ground

            * SIG connection of the Ez4 attached to digital pin 10



const int sonarPin = 10;

void setup() {

  // initialize serial communication:



void loop()


  // establish variables for duration of the ping,

  // and the distance result in centimeters:

  long duration,cm;

  // Give a short LOW pulse beforehand to ensure a clean HIGH pulse:

  pinMode(sonarPin, OUTPUT);

  digitalWrite(sonarPin, LOW);


  digitalWrite(sonarPin, HIGH);


  digitalWrite(sonarPin, LOW);

  // The same pin is used to read the signal from the EZ4: a HIGH

  // pulse whose duration is the time (in microseconds) from the sending

  // of the ping to the reception of its echo off of an object.

  pinMode(sonarPin, INPUT);

  duration = pulseIn(sonarPin, HIGH);

  // convert the time into a distance

  cm = microsecondsToCentimeters(duration);






long microsecondsToCentimeters(long microseconds)


  // The speed of sound is 340 m/s or 29 microseconds per centimeter.

  // The ping travels out and back, so to find the distance of the

  // object we take half of the distance travelled.

  return microseconds / 29 / 2;


(29 gives me a minimum centimeter reading of 19, while 58 drops it to 9. which number do I use?)

Also, I can't seem to get the hang of serial stuff that I need for control of the camera. Any Arduino fans out there that can give me some pointers?

JComCamUserManual.pdf208.6 KB
XLSonarDatasheet.pdf406.42 KB

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

From the datasheet "Objects from 0-cm to 20-cm range as 20-cm.'

Yes it can see things at < 20cm, but it cannot range them. At 20cm or less it's more of an object detector than a ranger.

Some other sensors report higher (if not highest) readings when the object is less than a certain distance away. So it would seem Maxbotix considers it a feature that their's reports low instead.

Speedreading sucks. I really need to curl up by the fireplace with a good users manual and get real into it...