Follow MaxBotix:
Ask A Question
|     Written By: Tom Bonar     |     Date Posted: 04-30-2014    |
The Arduino micro-controller is one of the most popular development boards for electronics enthusiasts. With the ability to control components such as buzzers, LED’s, servos, motors, and LCD’s, Arduinos have become the go-to selection for users that are looking to start into electronics, firmware coding, or automation. So with all these item types at your finger tips, what good is it to have control over so many components, if there are no sensors to trigger different functions in the Arduinos firmware?

The MaxBotix Inc., MaxSonar sensor line has become a very popular sensor for operation with the Arduino micro-controller. With three simple interfaces, it is easy to connect a MaxSonar to an Arduino.

In this article, I will be providing: links to components needed, wiring diagrams for all outputs, and Arduino sketch files for all compatible MaxSonar sensors. With that being said, let’s get coding!
 

Table of Contents

 

List of Materials Needed

Setting Up the Arduino

Wiring Pictures

 

Arduino Coding Part 1

    Useful Information
    Arduino Comments
    Code the Input & Variables
 

Arduino Coding Part 2

    Code Setup
    Code Section to Read Sensor
 

Arduino Coding Part 3

    Code Debug Section
    Code Void Loop
    Review the Code
 

Code Downloads

    LV-MaxSonar Code Downloads
    XL-MaxSonar Code Downloads
    HR-MaxSonar Code Downloads

Arduino Coding Part 2

Code the Setup

This section covers how to write the code section that tells the Arduino how to communicate the computer, and the IO pin characteristic.
Note - Any time a section is being written besides the input pins and viables, a "void" section will be created.
Note - When code is being written, care should be taken to ensure the correct case is being used. All characters are case sensitive. i.e. "Serial" always starts with a capital S. All code in this tutorial will have the proper cases.

Reading Analog Voltage

void setup (){
  Serial.begin(9600);
}

Reading Pulse Width

void setup (){
  Serial.begin(9600);
  pinMode(pwPin1, INPUT);
}

Take notice of the 9600 that is used in the "void setup" section. This is the BAUD rate that is used to read the Arduino for use in software such as: HyperTerminal, Termite, MatLab, or any software that can read a COM Port.

Top of the Page

Code the Section to Read the Sensor's Output

This section covers how to write the code section that tells the Arduino how to read and scale the sensor's output.

Reading Analog Voltage

The Arduino has a 10-bit ADC to read the MB1013. The MB1013 outputs a scale of 5mm per bit when reading Pin 3. This means every bit read by the Arduino has to be multiplied by 5 for the range in mm. To code this use the example below. For the sensor scaling of a different sensor line please consult the datasheet or the article entitled "Finding Distance Using Analog Voltage"

void read_sensor (){
  anVolt = analogRead(anPin);
  mm = anVolt*5;      //Takes bit count and converts it to mm
  inches = mm/25.4;   //Takes mm and converts it to inches
}

Reading Pulse Width

The MB1013 outputs a Time Of Flight signal when reading Pin 2. The scaling factor on this is 1mm per 1uS. This means if the Arduino reads 800, the target distance is 800mm away. For the sensor scaling of a different sensor line please consult the datasheet or the article entitled "Finding Distance Using Pulse Width"

void read_sensor (){
  sensor = pulseIn(pwPin1, HIGH);
  mm = sensor;      //Takes the pulse width and tells Arduino it is equal to millimeters
  inches = mm/25.4;   //Takes mm and converts it to inches
}

Top of the Page

 
Author: Kathy Kostal  Date: 08-31-2016
Inc 5000 Maxbotix Logo Inc. Magazine Unveils 35th Annual List of America's Fastest Growing Private Companies–the Inc. 5000. MaxBotix Inc., Ranks No. 1752 on the 2016 Inc. 5000 with Three–Year Sales Growth of 213%.
Click here for full article.
Author: Cody Carlson  Date: 08-02-2016
Raspberry Pi 2 board MaxSonar sensors offer a variety of outputs including TTL serial data. This tutorial guides you through the process of setting up your Raspberry Pi 3 with a MaxBotix sensor. Click here for full article.
Author: Scott Wielenberg  Date: 07-26-2016
Full Horn Housing MaxBotix offers an expanded range of packaging options for many of our sensors. Each option provides unique benefits to certain mounting integrations. This article provides a brief overview of each option.
Click here for full article.
Author: Scott Wielenberg  Date: 07-18-2016
Sensor is Tested When providing support, our technical support team may determine that further testing at our facility is the best way to help resolve the issue that you are facing. At this point, they will start the Return Merchandise Authorization (RMA) process. This article will explain what you can expect as your ultrasonic sensor travels through our RMA process.
Click here for full article.
Author: Scott Wielenberg  Date: 07-11-2016
Typical Wall Pipe Many customers have requested the option to mount an ultrasonic sensor in a pipe. During the testing and development cycle, we discovered a number of considerations and requirements that must be met for the application to be successful. When all of these are met, a user may be able to achieve the desired level of success for measuring the liquid level inside of a pipe.
Click here for full article.
Author: Jenney Grover  Date: 06-28-2016
one of the options for outputs On April 19th, we welcomed our supporters to join us for the Grand Opening of the Build Out. Bob and Nita Gross gave a tour of the build out and their vision for the space. We continue to be in awe of the support from our community, our employees, our distributors, and our customers. Thank you for the many years of support, and we look forward to serving you in the years to come.
Click here for full article.
 
 
 
 
 
Signup for notification of our exciting new products and periodic new letters. We are excited to provide the latest information from MaxBotix Inc.