About Me Ultrasonic Sensor (for mBot)

1280X1280__97_.PNG

Overview

The ultrasonic module is an electronic module designed for distance detection. The distance range it can detect is 3–400 cm. mBot 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.

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.
  • It supports programming in Arduino IDE, and simplifies the programming process with a runtime library.
  • It supports block-based coding on mBlock 5 and mBlock 3, which is suitable for all ages.
  • The connection is easy with RJ25 connectors.
  • It features modular installation, compatible with LEGO parts.
  • It has pins that 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__98_.PNG

● Dupont cable

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.

1280X1280__99_.PNG

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__17_.png

Select a portReturn 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.

21bf67ee-1395-46ad-aed7-a51909a49929.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__18_.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.

60e0eef5-b85a-4e44-b929-8ed46b68a9bc.png

● Program in Arduino

If you program in Arduino, you need to use Makeblock-Library-master to control the ultrasonic module. The distance can be detected with this module in the program through Arduino programming.

77800454-18f4-4c99-b26b-6321788e62be.png

Function

Feature

MeUltrasonicSensor(uint8_t port)

Select a port

long distance Cm()

Detect the distance in the unit of cm

long distance Inch()

Detect the distance in the unit of inch

The 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.

7db5d037-db2c-4f6b-8f0a-0248c208dd95.png

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

d4481173-2fc1-4628-912f-8241075a008b.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 and an obstacle. In this way, mBot can avoid obstacles.

aa9e05a5-cb17-42e3-8099-eddb554f2f49.jpg

 

Was this article helpful?
5 out of 8 found this helpful

Comments

0 comments

Please sign in to leave a comment.