Ultrasonic Sensor

Ultrasonic Sensor

Ultrasonic Module

 The ultrasonic module is an electronic module designed for distance detection. The distance range it can detect is 3-400 cm. mBot Ranger can use this module to avoid obstacles or for other programs about 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.

Technical Specifications

 ● Operating voltage: 5V DC

 ● Operating temperature: -25~80℃

 ● Detection angle: < 30°

 ● Detection range: 3-400 cm (error < 1 cm)

 ● Ultrasonic frequency: 42kHz

 ● Control mode: Single digital interface

 ● Dimensions (L x W x H): 56 x 36 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 with a runtime library;

 ● The module supports block-based coding on mBlock 5 and mBlock 3, which is suitable for users of all ages;

 ● The connection is easy with RJ25 connector;

 ● The module features modular installation, compatible with Lego parts;

 ● The module has pins which support most of 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 connection

 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.

 ● Dupont cable connection

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

Programming Guide

 ● Programming 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
   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.

 ● Programming 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
 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.

 ● Arduino Programming

 If you use Arduino programming, 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 code and the values can be transmitted to the serial monitor in Arduino IDE every 100ms. Upload the code 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 340m/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=340m/s×t/2.

Schematic Diagram

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 mBot Ranger and an obstacle. In this way, mBot Ranger can avoid obstacles.