

MaxBotix MB1240 vs Chinese Manufactured, 2 Transducer Sensor So you can simply multiply the TOF reading by 1 to get the distance in millimeters.įor other types of sensors, you can find the scaling factors in the datasheets. For the MB7389, the scaling factor is 1 µs/mm. To get the distance, you need to multiply this reading with a constant scaling factor.
#Ultrasonic sensor arduino 4 pin code#
You can use the pulseIn() function in the Arduino code to read the length of this output pulse in microseconds (µs). This pin outputs a pulse width representation of the distance. Pulse widthĪnother option is to use the pulse width output. We can read this output with a microcontroller like the Arduino and calculate the distance by multiplying the reading by a constant scaling factor (this factor depends on the exact sensor type, see datasheet). The analog voltage output of the sensor outputs a linear voltage that gets larger as a target moves further away from the sensor. This is probably the easiest way to read the measured distance from the sensor. In this tutorial, we will look at both the analog voltage and pulse width outputs.

#Ultrasonic sensor arduino 4 pin serial#
*The sensor has virtually no dead zone, objects closer than 20 cm range as 20 cm.įor more information, you can check out the datasheet here:Īs you might have seen in the specifications table above, the MaxBotix sensors of the MaxSonar family have different outputs: analog voltage, pulse width and RS232 serial ( I2C sensors are also available ). Small, light weight, narrow beam, automatic calibration (voltage, humidity, ambient noise), firmware filtering, easy to use MB1240 XL-MaxSonar-EZ4 Specifications Operating voltage The HR line of sensors also features internal temperature compensation. Maxbotix also sells sensors with a 1 mm resolution ( HRLV-MaxSonar-EZ ) and a higher refresh rate ( LV-MaxSonar-EZ ). The MB1240 that I used in this tutorial has a range of up to 765 cm and offers a 1 cm resolution. This means you can use it for robotic applications with multiple motors and servos. The XL-MaxSonar-EZ family has a high tolerance for interference from acoustic or electric noise. The MB1240 is one of their most popular sensors and is ideal for robotic applications. They make sensors for all kinds of applications, both for indoor and outdoor use. MaxBotix is a US-based manufacturer that specializes in ultrasonic sensors. The MB1240 XL-MaxSonar-EZ4 is an ultrasonic distance sensor made by MaxBotix Inc. So the distance between the sensor and the object is only half the distance that the sound waves traveled. This is because the sound waves traveled from the sensor to the object and back from the object to the sensor.

Note that you need to divide the result by two. Where Time is the time between sending and receiving the sound waves in microseconds. By measuring how much time passed between sending and receiving the sound waves, you can calculate the distance between the sensor and the object.ĭistance (cm) = Speed of sound (cm/µs) × Time (µs) / 2 These ultrasound waves get reflected by an object and the ultrasonic sensor detects them. How does an ultrasonic sensor work?Īn ultrasonic distance sensor works by sending out ultrasound waves. We will look at the different outputs of the sensor and how you can trigger the sensor with a push button.Īfter each example, I break down and explain how the code works, so you should have no problems modifying it to suit your needs. I have included 3 examples with wiring diagrams that show the basic operation of the sensor. In this tutorial, you will learn how the sensor works and how you can use it with an Arduino. Although this tutorial is written for the MB1240, it can also be used for other MaxBotix sensors. The MB1240 XL-MaxSonar-EZ4 is a high-performance ultrasonic distance sensor with a range of 20 to 765 cm. This article is a summary of the tutorial written by Benne de Bakker of
