MB1013 HRLV-MaxSonar-EZ Ultrasonic Sensor Set-up Guide

Below we have a tutorial to help you get started with the MaxBotix MB1013 ultrasonic sensor! This will hopefully give you a basic understanding of how ultrasonic sensors work and will help you set up your ultrasonic sensor to read analog voltage.

Take a look at this sensor’s data sheet for more information on the sensor’s specs!

How Ultrasonics work

Using sound, the ultrasonic rangefinder measures distance for you. The diagram below shows how the sensor sends and receives the sound waves. It measures the distance using the time it takes for the sound wave to leave, reflect off of a surface or object, and travel back to the sensor.

Using Your Ultrasonic Sensor in your Project

1. HOOK UP CONTROLLER

We used an Arduino in this example, but you can use another controller and program of your choice.

2. INSTALL SOFTWARE

Install Arduino Sketch coding software onto your PC. This is where you type the code you want to compile and send to the Arduino board.

3. SET UP YOUR SENSOR WITH ARDUINO

Plug your Arduino into the USB cable and into your computer. Once you upload Arduino, you can then compile and activate the code.

4. COMPILE AND RUN CODE

The code below will allow you to read distance in centimeters. Compile and run this code to obtain real-time distance measurements to the closest object. (Please note: this code is not only for Arduino and will run on most controllers)

const int anPin = 0;

long anVolt, cm;


void setup() {

   Serial.begin(9600);

}


void read_sensor(){

   anVolt = analogRead(anPin);

   cm = anVolt/2;

}


void print_range(){

   Serial.print(“Range = ”);

   Serial.print(cm);

   Serial.print(” cm “);

   Serial.print('\n');

}

 
void loop() { 

   read_sensor();

   print_range();

   delay(100);

}


How This Helps You

How can you use this information? Glad you asked! There are quite a few applications in which this becomes very useful.

One, distance to objects data is extremely useful for the autonomous section of the contest. Your robot can actually use the distance when navigating to help avoid objects.

Another use is if you need to perform an action when your robot is a certain distance from an object. You can use the information to make the robot perform better and much more quickly even during the  remote-controlled section of the contest.

Also, as good as Lidar sensors are, only ultrasonic sensors can reliably detect certain surfaces such as glass. Transparency and color of objects have no effect on if an ultrasonic sensor can see an object. This is especially useful if you don’t know what kind of environment your robot will be operating in.

Need More Help?

If you find yourself in need of more information about the MaxSonar sensor and your project, we at MaxBotix are more than happy to help you. Please call us at (218)454-0766 or email our technical support team at [email protected].