About Me Ultrasonic Sensor (for mBot Ranger)

1280X1280__83_.PNG

Ultrasonic module

The ultrasonic module is an electronic module designed for distance detection. The distance range it can detect is 3–400 cm. This module can help mBot Ranger avoid obstacles or be used in other programs for distance detection. The yellow tag on the interface of this module indicates that it is a single digital interface and that it should be connected to a port with the yellow tag on the main control board.

 

Specifications

Operating voltage: 5 V DC
● Operating temperature: -25–80℃
● Detection angle: <30°
● Detection range: 3–400 cm (error < 1 cm)
● Ultrasonic frequency: 42 kHz
● Control mode: Single digital interface
● Dimensions (L x W x H): 56 mm x 36 mm x 31 mm

 

Features

● Reverse connection of power does no harm to the IC;
● The white zone on the module is for connection with metal beams;
● The module supports programming in Arduino IDE, and simplifies the programming process with a runtime library;
● The module supports block-based coding on mBlock 5 and mBlock 3, which is suitable for all ages;
● The connection is easy with RJ25 connectors;
● The module features modular installation, compatible with LEGO parts;
● The module has pins which support most Arduino main control boards.

 

Pin definition

The connector of the ultrasonic module has 3 pins. The features of the pins are shown in the following table.
SN Pin Feature
1 GND Connect the ground electrode
2 5V Connect the power cord
3 SIG Output the distance signal

 

Wiring mode

● RJ25 cable
The tag color on the interface of the ultrasonic sensor is yellow. When you use an RJ25 connector, you need to connect it to a port with the yellow tag on the main control board. Take Makeblock Orion as an example. You can connect it to port 3, port 4, port 5, port 6, port 7, or port 8 as shown in the following figure.

1280X1280__84_.PNG

 

● Dupont cable
When you use a Dupont cable to connect to Arduino Uno, the pin SIG of the module should be connected to a digital interface as shown in the following figure.

 

Programming guide

● Program with mBlock 5
The ultrasonic module supports programming with mBlock 5. The following is a brief description of a block on this module:
Block Features
output__13_.png Select a port
Return a distance reading in the unit of cm

 

The following figure shows an example of how to control the ultrasonic module on mBlock 5.
The program makes Panda tell the distance detected by the ultrasonic sensor. The running result is as follows.

46629cea-d828-47a8-864d-09d839e296d3.png

● Program with mBlock 3
The ultrasonic module supports programming with mBlock 3. The following is a brief description of a block on this module:
Block Features
output__14_.png Select a port
Return a distance reading in the unit of cm
The following figure shows an example of how to control the ultrasonic module on mBlock 3.
The program makes Panda tell the distance detected by the ultrasonic sensor. The running result is as follows.

3c489a88-d59f-4757-8cf9-5bf6f93a7964.png

● Program in Arduino
If you program in Arduino, you need to use Makeblock-Library-master to control the ultrasonic module. Distance can be detected with this module in the program through Arduino programming.
Function Feature
MeUltrasonicSensor(uint8_t port) Select a port
long distanceCm() Detect the distance in the unit of cm
long distanceInch() Detect the distance in the unit of inch
Distance can be detected in two units with this program and the values can be transmitted to the serial monitor in Arduino IDE every 100ms. Upload the program to the Makeblock main control board, click the Arduino serial monitor, and the running result is shown in the following figure.

 

Working principle

The ultrasonic transmitter in the ultrasonic module emits ultrasonic waves to a certain direction. Start the timer at the beginning of the emission. The ultrasonic waves are transmitted in the air and return immediately after meeting an obstacle. The timer stops once the ultrasonic receiver receives the reflected waves. The transmission speed of ultrasonic waves in the air is 340 m/s. Based on the time (t) recorded by the timer, the distance (s) between the ultrasonic wave emission point and the obstacle can be calculated by the formula: s = 340 m/s × t / 2.

 

Schematic

c00a7bd2-524d-4049-8836-c898dbf1da04.png

 

Basic obstacle avoidance program on mBlock 5

The following figure shows a simple obstacle avoidance program on mBlock 5. Judge whether to move forward or turn right by using the ultrasonic sensor to detect the distance between the mBot Ranger and an obstacle. In this way, the mBot Ranger can avoid obstacles.
2c23159f-7acf-4179-9a88-11d1c2d12c84.png

 

Was this article helpful?
3 out of 4 found this helpful

Comments

0 comments

Please sign in to leave a comment.