FIRST FRC Ultrasonic Sensor for 2024

Welcome Robotics Teams!

FIRST FRC Cresendo

MaxBotix has been a proud sponsor of FIRST team since 2012 and once again we are supporting your work in the field of robotics by giving each team a voucher for a free MB1122 MaxSonar Sensor from our HRLV-MaxSonar-EZ line. This small and lightweight sensor is designed for easy integration into your project and is a great option for autonomous robot navigation.

This page should contain everything you need to get your sensor up and running with your robot.  Should you have any questions, you can email us at or call us at 218.454.7363

Take a look at our data sheet for more information on your sensor’s specs! The MB1122 is the same as the MB1043 and uses this datasheet.



How Ultrasonic Sensors Work

All of our ultrasonic rangefinders will measure distance by tracking the time-of-flight of a sound wave. The diagram below shows how the sensor sends and receives the sound waves. Once the sensor emits a sound wave, it tracks how long it takes for the sound to reflect off of a surface and travel back to the sensor. The sensor then uses the known speed-of-sound to turn the time-of-flight into a range reading. how ultrasonic sensors work

Using Your Ultrasonic Sensor with your NI roboRIO

Using the MaxBotix sensor is a simple process which we define for you in this article.  The steps are shown below: 

1. Decide if you are going to use one sensor or more than one sensor.  
2. Connect the sensor(s) to the NI roboRIO using the wiring instructions provided.  
3.  Program the roboRIO with the code to read the sensor.
4.  Now use range values from your sensor in the guidance of your robot. 

Sensor Wiring

Our sensors can easily be connected and powered by the analog inputs on your NI roboRIO. If you use multiple sensors, you will have to connect the trigger pin of the sensor to a digital output on the NI roboRIO. It is recommended to do multitasking such as creating a new thread to trigger the sensor while your main robot code is still running.

In our examples, the Analog Output (Pin 3) is the pin where you read the range value reported from the sensor. 

The sensor pinout is shown below.  The square pad with a hole is Pin 1.  If you are using more than one sensor, you will also connect Pin 4 of the sensor to DIO.  

MB1122 Pinout

Connect these pins to an Analog Input port on your RoboRIO. Our example uses Analog Port 0. That's all we need to do to connect our Sensor to the RoboRIO.  

RIO Analog Input
  • Sensor Pin 3 connected to S 
  • Sensor Pin 6 connected to 5V
  • Sensor Pin 7 connected to 



Single or Multiple Sensor Setup Analog Voltage Example

Using Your Ultrasonic Sensor with your NI roboRIO

Programming for use with a single sensor

Our sensors communicate with your RoboRIO using one of three methods:

  • Analog Voltage Output (Pin 3) (example shown above)
  • Pulse Width Output (Pin 2)
  • 5 Volt RS-232 Serial Output (Pin 5)

When power is applied to Pins 6 and 7 of our sensor, the voltage on pin 3 will change according to the distance between the sensor and the object in front of it. The sensor will report a voltage on pin 3 which represents the distance.  

Use the RoboRIO to measure the voltage on Pin 3. This can be done using the WPILib Analog Input Library. First, let's import the library:

Java: C++: Next, let's create an instance of the Analog Input class and specify that it should use Analog Pin 0: Java: C++: Now that our sensor is setup, let's grab a distance value from the sensor: Java: 

This will return our distance in Centimeters or Inches. The Maximum range of our MB1122 sensor is 5 Meters, and the minimum range is 30 centimeters. For a detailed description of how this math is determined, please see our MB1122 datasheet.

A complete example that takes readings from one sensor during the Autonomous period, and a different sensor during the Teleoperated period and publishes both to SmartDashboard can be found in and robot.cpp which can be found at the bottom of this page, or in the Github repository.

Programming for use with multiple sensors

You will use Pin 4 for multiple sensor operations. Pin 4 (Ranging Start/Stop pin) functions as follows: 

  • High = Sensor takes range readings
  • Low = Sensor stops ranging

If Pin 4 is unconnected, the default state is high and the sensor will range. 

Use the Digital Output on the RoboRIO to trigger each sensor.  

We can control the Ranging Start/Stop pin using the WPILIB DigitalOutput Library.

RIO Analog Input
  • Sensor Pin 3 connected to S 
  • Sensor Pin 6 connected to 5V
  • Sensor Pin 7 connected to 
  • Sensor Pin 4 Connected to DIO0(S) and DIO1(S)


Single or Multiple Sensor Setup Analog Voltage Example 

MB1122 Wiring Diagram

Multiple Sensor Setup


It takes approximately 100 Milliseconds for each sensor to complete a range reading. Allow this time for the sensor to complete a range reading. For more information on the timing of the MB1122, please reference our datasheet.

Users with more experience in programming/timing might also find the following diagram helpful, which allows multiple sensors to be chained together such that only one digital pin is needed to cause all the sensors to range one after the other. How this helps you

Once you have your ultrasonic sensor hooked up, you can write code to control your Robot. For example, your robot could use these values to drive a certain distance in Autonomous.

  • You could use range information to automatically perform an action when you approach a target.
  • You could also use this data to assist your drivers during the Teleoperated period.
  • Even if you are using other sensors, ultrasonic sensors are a great addition. Only ultrasonic sensors can reliably detect certain surfaces such as glass. Transparency and color of objects have no effect on an ultrasonic sensor's ability to see an object. This is especially useful if you don’t know what kind of environment your robot will be operating in.

If you need any help using our sensors or want to contact us for any other reason, you can reach us by email at or call 218-454-7363.

Feedback is appreciated! If you'd like to purchase additional sensors, visit us at, or contact us at Thank you, and Have a great season!

Additional Resources:

Download .Cpp Sample Code                    Download .Java Sample Code

Additional FIRST FRC Blog Posts

Triangulation Finds the Direction and Distance to a Pole

Back to blog