(Pin 4) If this pin is held high or left disconnected, the sensor will continuously free run. To resolve this, MB1043 MaxSonar sensors are equipped with a Ranging Start/Stop pin. Using multiple ultrasonic sensors requires a little more work, as the sensors may interfere with each others readings. Programming for use with multiple sensors For a detailed description of how this math is determined, please see our MB1043 datasheet.Ī 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 robot.java and robot.cpp. The Maximum range of our MB1043 sensor is 5 Meters, and the minimum range is 30 centimeters. This will return our distance in Centimeters or Inches. getVoltage5V() ĭouble currentDistanceCentimeters = raw_value * voltage_scale_factor * 0.125 ĭouble currentDistanceInches = raw_value * voltage_scale_factor * 0.0492 voltage_scale_factor allows us to compensate for differences in supply voltage.ĭouble voltage_scale_factor = 5/ RobotController. Now that we know what voltage the sensor is outputing, let’s scale this to our distance range: 0 represents 0V applied, and 4095 represents 5V applied. Now that our sensor is setup, let’s grab a distance value from the sensor: Private final AnalogInput ultrasonic = new AnalogInput(0) Next, let’s create an instance of the AnalogInput class and specify that it should use Analog Pin 0: This can be done using the WPILib AnalogInput Library. So in order to read this distance, we need the RoboRIO to measure the voltage on Pin 3. 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. In this example we are using Analog Voltage Output for simplicity.
Our sensors communicate with your RoboRIO using one of three methods: Analog Voltage Output (Pin 3), Pulse Width Output (Pin 2), or 5 Volt RS-232 Serial Output (Pin 5). That’s all we need to do to connect our Sensor to the RoboRIO. Pin 3 should be connected to the pin labeled “S”. Pin 6 on our sensor should be connected to the RoboRIO pin labeled “5V”, Pin 7 should be connected to the pin labeled with the Ground Symbol. We will use Analog Port 0 in our example. We need to connect these pins to an Analog Input port on your RoboRIO. The pins are also labeled on the back of the Circuit Board. The square pad is Pin 1, and they count up along the board.
To identify which pins these are on your sensor, you can note that one of the 7 pins on the sensor has a square copper pad around it, instead of a circular one. Secondly, we need to connect the Analog Output (Pin 3) so that we can read values from the sensor. You will need to wire up 3 pins in order to use our sensors.įirstly, we need 5 Volt power (Pin 6) and Ground (Pin 7) to power the sensor.
It is recommended to do multitasking such as creating a new thread to trigger the sensor while your main robot code is still running. Do note that if you choose to use multiple sensors you will have to connect the trigger pin of the sensor to a digital output on the NI roboRIO. Hook Up One Sensor To Your ROBORIO Our sensors can easily be connected and powered by the analog inputs on your NI roboRIO. Using Your Ultrasonic Sensor with your NI roboRIO
The sensor then uses the known speed-of-sound to turn the time-of-flight into a range reading. 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 diagram below shows how the sensor sends and receives the sound waves. Take a look at our data sheet for more information on your sensor’s specs! How Ultrasonics workĪll of our ultrasonic rangefinders will measure distance by tracking the time-of-flight of a sound wave. This small and lightweight sensor is designed for easy integration into your project, and it is a great option for autonomous robot navigation. FRC competitors, once again we are supporting your work in the field of robotics by giving each team a free MB1043 MaxSonar Sensor from our HRLV-MaxSonar-EZ line.