The MB1240 ultrasonic distance sensor from the XL-MaxSonar-EZ family is made by a US-based manufacturer company like MaxBotix Inc. They manufacture different sensors to use in different indoor and outdoor applications. Among them, the MB1240 ultrasonic sensor is one of the most popular types and is used in robotic applications with various servos & motors. The Maxbotix also sells 1 mm resolution sensors with a higher refresh rate. This article provides brief information on MB1240 ultrasonic sensor, their working, and their applications.
What is MB1240 Ultrasonic Sensor?
The MB1240 is a high-performance ultrasonic distance sensor from XL-MaxSonar-EZ4 with a 20 – 765 cm detection range and it is used to detect larger objects. This ultrasonic sensor is very small below one cubic inch and this sensor is available with mounting holes so that installation on the circuit board will become accessible in various applications. The MB1240 sensor provides almost noise-free distance readings with high-output acoustic power combined through constant variable gain, signature analysis of real‑time waveform, and automatic calibration of real‑time background & noise rejection algorithms.
Working
An ultrasonic distance sensor simply works by transmitting out ultrasound waves which get reflected through an object & the sensor detects them. To measure the time taken to pass between transmitting & receiving sound waves, the distance needs to be calculated between the ultrasonic sensor & the object.
Distance in cms = (Speed of sound (cm/µs) * Time (µs)) / 2
Here the result needs to be divided by two because the sound waves traveled to the object from the sensor & back from the object toward the ultrasonic sensor. Thus the main distance between the ultrasonic sensor & the object is simply half the distance to the sound waves moved.
Pin Configuration:
The pin configuration of the MB1240 ultrasonic sensor is shown below. This Sensor includes four pins which are discussed below.
- Pin-1 (Leave Open): This pin is left open for serial o/p on the Pin-5 o/p. Once this pin is held low then the output of Pin 5 transmits a pulse that is apt for low noise chaining
- Pin-2 (PW): This pin provides a pulse width representation of range.
- Pin-3 (AN): It is an analog pin that provides an analog voltage by a (Vcc/1024)/cm scaling factor.
- Pin-4 (RX): This pin is pulled high internally. If this pin is held high then the sensor will measure range continually.
- Pin-5 (TX): Once pin-1 is held high, the output of pin-5 sends asynchronous serial through an RS232 format.
- Pin- 6 (Vcc): It is a +5v voltage supply pin.
- Pin-7 (GND): It is a ground pin.
Features & Its Specifications
The features and specifications of the MB1240 ultrasonic sensor include the following.
- It is a very small and lightweight module.
- It is designed to integrate into your product or project easily.
- It has Real-time automatic calibration.
- Firmware filtering for rejection of clutter & better noise tolerance.
- It has maximum noise tolerance for the XL-MaxSonar-EZ products.
- Its resolution is 1 centimeter.
- It has the highest tolerance for noise.
- It has the narrowest beam width.
- Its detection range is 20cm -765cm.
- Its read rate is 10Hz.
- It has different output options like analog voltage, pulse width & RS232 serial.
- Its operating voltage ranges from 3.3 to 5.5 Volts.
- Its operating current is 3.4 mAmps.
- Its frequency is 42 kHz.
- Its dimensions are; 22.1 * 19.9 * 25.11 mm.
- Its operating temperature ranges from 0 to 65 °C.
Please refer to this for How to Choose an Ultrasonic Sensor.
MB1240 Ultrasonic Sensor Interfacing with Arduino
The interfacing of the MB1240 ultrasonic sensor with Arduino is shown below. MaxBotix MB1240 sensor has different o/ps like analog voltage, RS232 serial & pulse width. Here we will look at the analog voltage output. This is possibly the easiest method for reading the distance measured from the ultrasonic sensor. The sensor’s analog output voltage o/ps a linear voltage that obtains larger when an object moves further away from the ultrasonic sensor. This output can be read through an Arduino & measure the main distance by simply multiplying the reading through a constant scaling factor.
The required components to make this interfacing mainly include; MB1240 ultrasonic sensor, Arduino, and connecting wires. The analog voltage wiring diagram connections follow as;
MaxBotix MB1240 sensor GND is connected to the GND pin of the Arduino board. The V+ pin of the sensor is connected to a 5V of the Arduino board. The pin3 of the sensor is connected to A0 of the Arduino Uno board.
Code
#define sensorPin A0
int distance = 0;
void setup() {
Serial.begin(9600);
}
void read_sensor() {
distance = analogRead(sensorPin) * 1;
}
void print_data() {
Serial.print(“distance = “);
Serial.print(distance);
Serial.println(” cm”);
}
void loop() {
read_sensor();
print_data();
delay(1000);
}
This Arduino code is used for reading the distance from an analog ultrasonic distance sensor which is connected to the A0 pin of the Arduino.
At first, the above code simply defines the sensorPin like A0 to indicate that the ultrasonic sensor is connected simply to analog input 0.
The setup function initializes the serial communication at a 9600 baud rate.
The function of read_sensor reads the value of the ultrasonic sensor by simply changing the analog value obtained from the sensor to distance by simply multiplying it through one.
The function of print_data prints the main value of distance on the serial monitor and preceded through a string “distance = ” & followed through the cm unit.
At last, the code in the loop function reads the value of the sensor continuously and prints it on the serial monitor with the print_data function & adds a 1000ms delay before repeating the procedure.
Interfacing this sensor with an Arduino board can be used in creating interactive electronic projects & gadgets because the Arduino board is very popular, simple to use, and versatile board. This sensor is capable of measuring distances accurately by interfacing with Arduino in different applications like robotics, home security systems & automation.
Applications
The applications of MB1240 ultrasonic sensors include the following.
- The MB1240 ultrasonic sensor is used to detect large objects.
- This ultrasonic sensor is used within robotics for detecting obstacles & also decides the distance between an object & the robot.
- The MB1240 ultrasonic sensor is used in automated systems for monitoring the objects within assembly line operations.
- The ultrasonic sensor is used within safety systems to notice the existence of an intruder & calculate the distance between the sensor & the intruder.
- This ultrasonic sensor is used for monitoring the flow of traffic & notice the vehicle’s presence on a road.
- This sensor is used in parking areas for detecting the central distance between a car & an object.
- This distance sensor is used with Raspberry Pi, and Arduino to detect a person or in robotics.
Please refer to this link for MB1240 Ultrasonic Sensor Datasheet.
Thus, this is an overview of the MB1240 ultrasonic sensor, its features, specifications, and its applications. The MB1240 Ultrasonic Distance Sensor measures the leading distance between an object & the sensor by using sound waves. This sensor is capable of measuring distances accurately from 20 cm – 765 cm with a 1 cm resolution. Here is a question for you, the ultrasonic sensor also called?