Sonar Range Finder DataSheet Summary

Initial Summary by Rebecca Bray, February 2006. See original report with photos and diagrams.

Modified by Mark Breneman and Melissa dela Merced January 2012

MaxSonar-EZ1 High Performance Sonar Range Finder from Maxbotix

See Datasheet

On this page: Intro | Applications | Electrical | Output Pins | Analog Output | Circuit | Code Example

This is a brand new product released in January 2006 that Bob Gross designed when his daughter's robot lost a race because it misjudged distance to a wall. According to current discussions about it on various robotics forums, it's a comparatively good product.

Sonar rangers work by sending out ultrasonic beams and receiving the waves that it receives, like bats. In this way it can detect both the presence and distance of objects. This particular sensor operates at 42KHz. The signal from the transducer in the sensor is amplified and goes through an analog to digital converter integrated into a microcontroller within the sensor. The microcontroller is continuously processing the signal.

This sensor gives short to long range detection and ranging. It detects objects from 0 inches to 254 inches and ranges from 6 inches to 254 with a one-inch resolution.The ability to give meaningful output at such close range is rare, as is this sensors' small size and relatively low price. It is comparable in price to the Devantech Ranger, but has a greater range and more types of output.

Where to Buy new

NYU Computer Store 27.00
SparkFun 25.95-27.95
Adafruit 25.00
Solarbotics 23.95-24.95
MaxBotix 21.95-29.95
Applications

This sensor was designed for use in robotics, but could be used in a range of applications, including deep sea fishing, industrial production (finding flaws in factory parts), simple object detection, etc.

New Assistive Parking - Toyota
Water Measurement
Projects which have Used it
Melissa’s Project
Hannah Kang Brown
Robbie Tilton
Manuela Donoso & Dong Ik Shin

http://www.instructables.com/id/Getting-started-with-the-Maxbotix-sonar-sensor-q/step4/Wire-it-up/ -QUick Start 2

http://www.maxbotix.com/tutorials.htm - Quick Start Guide

Using Multiple Sensors new When using multiple utrasonic sensors there is the possibility of crosstalk or interference where one sensor may be receiving the information sent by another sensor. Maxbotix has posted solutions to avoid this problem.

http://www.maxbotix.com/uploads/Chaining_Application_Notes__AN_Output_Commanded_Loop_.pdf
http://www.maxbotix.com/uploads/Chaining_Application_Notes__AN_Output_Constantly_Looping_.pdf
http://www.maxbotix.com/uploads/Chaining_Application_Notes__AN_Output_Simultaneous_Operation_.pdf
Simultaneous Operation

You can also run them all at the same time (and for some uses this is preferred as the measurement speed is maximum, but it is only for selected applications). Just tie all of the RX pins together and command them with a pin from your microcontroller. Hold the RX pin high for more than 20uS and up to 400uS. Do not continuously leave this pin high, as then all of the sensors will free run. Command the sensors every 50mS or whenever a new range reading is desired.

Daisy Chaning with Constant Looping

If you want them to keep running and constantly loop and always provide the latest range reading you will have to do two things.

First, add a resistor between the last sensor's TX back to the Rx of the first unit through a 1K resistor.

Second, then you will have to "kick start" them, (at least 250mS or more after power is applied to the sensors to give the sensors this time to boot-up). To do this, pull the RX pin high on the first sensor for at least 20uS. Then the micro controller will have to return it's pin to a high impedance state so that the next time around the TX output from the last sensor will make it's way to the RX of the first sensor. Then all of the sensors in the chain will run in sequence. This "ring of sensors" will cycle around and around, constantly maintaining the validity of their analog values.

You can then read the latest range reading (i.e. the analog value) at any time. This is the easiest way to use them. After pulling the RX pin low, you can read the analog pin about 50mS (100mS if this is the first time reading the sensor as it calibrates upon the first commanded range cycle after power up, i.e. the sensor must complete a range cycle). In addition, the most recent range reading is always ready to be read on the analog voltage pin, so once you start the chain, and if you are using it in continuous mode, you can read the values at any time.

Daisy Chaining with a Commanded Loop

To chain the sensors, and have them to operate in sequential daisy-chained fashion, you do so by linking the TX of unit 1 to RX of unit 2 and so on. The BW pin is tied high on all of the parts. Then just strobe the first sensor's RX pin and all of the sensors will read the range in sequence. The analog values can then be read. The example above would use one pin to command the chain, and three analog to digital inputs.

Electrical Characteristics

This sensor requires 5VDC +/- 0.5VDC. Current capability of 3mA capacity is recommended. It outputs 0 to 2.55 volts with a scaling factor of 10mV per inch.

Output Pins

The sensor gives output as pulse width, analog, and serial digital, and can give all 3 simultaneously. It can give readings every 50mS.

The serial output characteristics on the TX pin are a little atypical with RS232 format with 0-5 V. This caused some consternation on some of the robotics forums.

The RX pin is pulled high, and the sensor will measure data if it's kept there. To do triggered readings instead of continuous, bring this pin low until you want a reading and then bring high for 20uS.

The analog output is scaled. It outputs 0 to 2.55 volts and scales to 10mV per inch. To reduce the noise on the output, a 0.1uF capacitor can be placed between the analog pin on the microcontroller and then a 10K ohm resistor in series with the analog voltage output from the sensor to that capacitor. The analog output needs to be buffered by the op amp in the circuit.

The FAQ on the product web site says that pulse width and serial output give the most accurate numbers.

Pulse width output gives range and the numbers can be used to calculate distance using the scale factor of 147uS per inch. Pulse width is set high internally after the sonar waves are sent, and if something is detected, the PW pin is pulled low.

New Filtering the data
Maxbotix recommends not to average the readings from the sensor or else it will provide incorrect data. Users should instead use the following filtering methods:

Median Filter The median filter would take the last group of readings and first sort them and then pull out the center reading. Here one might take three or more readings (up to say about 11 for people sensing) and after sorting the readings in order of range, pull out and use only the middle (median) reading. Fairly good filtering.

Mode Filtering The mode filter would take the largest group of the same readings out of a set of even larger readings. Very robust filtering. Filtering for most applications, the Very Simple Mode Filter

The simplest mode filter, is simple as this question, "Do the last two readings agree?" (with in a certain distance, and the certain distance depends upon how much variation one expects in the actual use. Even so most use the logic of "are these readings exactly the same")? If so, use the readings, otherwise throw away to oldest reading, and compare the next reading with the most current reading and do this again. Obviously with very noisy data, one might have to sample a larger group of readings, and pull out the most common reading, but for most applications, this simple two reading filter works very well.

The circuit

Parts: PIC16F676 LM324 Operational Amplifier (14 pin) BAV99DA diode array 8 100K resistors, 2 10K, 1 each - 1K, 33K, 75K, 2.7K 1 u, 5 0.1u,3 600pcapacitors

The data sheet shows that the circuit for the analog readings requires a LM324 Low Power Quad Operational Amplifier and a BAV99DA diode array. On Tom's site there's an example of an op amplier and diode array, used there with a piezo as sensor.

Operational amplifiers serve to amplify the voltage. If there are very small changes in the readings, you need to amplify them to get good data. There are various resisters in this circuit, and I believe that by adjusting them you can adjust the scale of the readings. The LM324 has 14 pins.

The switching diode array helps to ensure that voltage does not flow in the wrong direction and that the readings are always positive.

Code Sample: (from product FAQ)

'BX24 'MaxSonar-EZ1 Code Example 'By Chris Harriman '01/09/2006 'The program below continues to read the MaxSonarEZ1 'It uses the AD to read, and debug to output the data.

Const RX As Byte = 10 Const AN As Byte = 13 Dim AnalogOutPut As Byte Dim SerialOutPut As Byte Dim PWOutPut As Byte ''********************************************************************************************** Sub Main() Do AnalogOutPut = RangeA ' Get the Range Debug.Print "Analog " & CStr(AnalogOutPut) ' Print the Range Call SLeep(512) Loop End Sub

'********************************************************************************************** Function RangeA() As Byte ' Reads the Analog output of the MAXSonar EZ1 (AN Pin) and returns the target range as a Byte Dim AValue As Integer

Call PutPin (RX, 0) ' Turn off the EZ1 just in case we started with it on Call PutPin (RX, 1) ' Turn on the EZ1 Call Sleep(40) ' Wait about 50 ms

AValue = GetADC(AN) ' Read the ADC RangeA = Cbyte(AValue \ 2) ' Convert value to Byte and return End Function '**********************************************************************************************


Code Sample for Arduino C: (by Bruce Allen http://www.arduino.cc/playground/Main/MaxSonar)

//Feel free to use this code.
//Please be respectful by acknowledging the author in the code if you use or modify it.
//Author: Bruce Allen
//Date: 23/07/09

//Analog pin 1 for reading in the analog voltage from the MaxSonar device.
//This variable is a constant because the pin will not change throughout execution of this code.
const int anPin = 1;

//variables needed to store values
long anVolt, inches, cm;
int sum=0;//Create sum variable so it can be averaged
int avgrange=60;//Quantity of values to average (sample size)

void setup() {
//This opens up a serial connection to shoot the results back to the PC console
 Serial.begin(9600);

}
void loop() {
pinMode(anPin, INPUT);

//MaxSonar Analog reads are known to be very sensitive. See the Arduino forum for more information.
//A simple fix is to average out a sample of n readings to get a more consistant reading.\\
 //Even with averaging I still find it to be less accurate than the pw method.\\
 //This loop gets 60 reads and averages them

for(int i = 0; i < avgrange ; i++)
 {

  //Used to read in the analog voltage output that is being sent by the MaxSonar device.
   //Scale factor is (Vcc/512) per inch. A 5V supply yields ~9.8mV/in
   anVolt = analogRead(anPin);
   sum += anVolt;
   delay(10);

}  

inches = sum/avgrange;
 cm = inches * 2.54;
 Serial.print(inches);
 Serial.print("in, ");
 Serial.print(cm);
 Serial.print("cm");
 Serial.println();

//reset sample total
 sum = 0;

delay(500);

}

PW


//Feel free to use this code.
//Please be respectful by acknowledging the author in the code if you use or modify it.
//Author: Bruce Allen
//Date: 23/07/09

//Digital pin 7 for reading in the pulse width from the MaxSonar device.
//This variable is a constant because the pin will not change throughout execution of this code.
const int pwPin = 7;
//variables needed to store values
long pulse, inches, cm;
void setup() {
//This opens up a serial connection to shoot the results back to the PC console
 Serial.begin(9600);

}
void loop() {
pinMode(pwPin, INPUT);

  //Used to read in the pulse that is being sent by the MaxSonar device.
//Pulse Width representation with a scale factor of 147 uS per Inch.

pulse = pulseIn(pwPin, HIGH);
 //147uS per inch
 inches = pulse/147;
 //change inches to centimetres
 cm = inches * 2.54;

Serial.print(inches);
 Serial.print("in, ");
 Serial.print(cm);
 Serial.print("cm");
 Serial.println();

delay(500);

}
 

Go to the Maxbotix site for more information on the FAQ