Me Ultrasonic Sensor is an electronic module that can measure a distance of 3 cm to 400 cm. You can use it to help a robot car avoid obstacles or in any projects where distance measurement is required. The port is marked yellow, indicating that it is a single-digital port and needs to be connected to one maked yellow on a Makeblock main control board.
- Operating voltage: 5 V DC
- Measurement angle: 30 degrees
- Measurement range: 3 cm – 400 cm (with error less than 1 cm)
- Ultrasonic frequency: 42 kHz
- Control mode: Single-digital port control
- Module size: 56 mm x 36 mm x 31 mm (L x W x H)
- Protection against reverse connection, protecting the IC from damage at reverse power connection
- The area marked white is the area recommended for contact with metal beams.
- Supporting the Arduino IDE and providing a library to simplify programming
- Support mBlock 5 block-based programming, applicable to users of all ages
- Adopting a RJ25 port for easy connection
- Modular installation, compatible with Lego bricks
- Providing a pin-type port, supporting most of the Arduino series main control boards
You can use this module with main control boards (such as mCore and Orion) with RJ25 ports to create some interesting projects, such as obstacle avoidance car, ultrasonic wave-based distance measurement, and parking radar.
The port of Me Ultrasonic Sensor includes three pins, and their functions are as follows:
Yellow-marked port: allows you to connect to a main control board with an RJ25 cable and program it
VCC: power supply
SIG: distance signal output
● RJ25 Connection
The port of Me Ultrasonic Sensor is marked yellow, and therefore you need to connect it to a port marked blue on a Makeblock main control board.
Taking Makeblock Orion as an example, you can connect it to one of ports 3, 4, 6, 7, and 8 as follows:
Port 5 is used to connect the Bluetooth module.
● Dupont connection
When using a Dupont cable to connect the module to the Arduino UNO main control board, you need to connect the SIG pin to the digital port as follows:
Note: To connect the module in Dupont mode, you need to weld the pin headers on the module.
You can program Me Ultrasonic sensor using the block-based or C/C++ programming. For block-based programming, you don't need to be very experienced in programming. Whether you are new or exprienced in programming, you can easily master block-based programming in a short period of time.
Compared with block-based programming, C/C++ programming is a more tranditional programming language. It works better for users understand the C language or other programming languages.
The following uses the Orion main control board as an example to describe how to program Me Ultrasonic Sensor.
Block-based programming—mBlock 5
Before you use mBlock 5, download mBlock based on the system running on your PC read the online help of mBlock 5 to get to know the UIs and basic operations of mBlock.
Use the Orion main control board as an example.
After adding the Orion device from the device library, you can find the block for Me Ultrasonic Sensor in the Sensing category.
Parameter: select the port based on the one you connect Me Ultrasonic Sensor to on the main control board
Function: outputs the value of the distance between the module and the object detected (unit: cm)
C/C++ programming—Arduino IDE
Programming environment configuration
To program Me Line Follower using the C/C++ programming language, you can configure the Arduino IDE environment by referring to the following;
(1) Get Arduino IDE and Makeblock program library
Login Arduino's official website to download Arduino IDE:
You should download the installation package for corresponding operating system (Subject to the latest version).
(2) Download Makeblock library functions:
Decompress the makeblock folder in the zip to the Arduino default library. Your Arduino library folder should now look like this:
- Windows 7(on Windows):
[arduino installation directory]\libraries\makeblock\src
[arduino installation directory]\libraries\makeblock\example
- or like this (on Mac):
(3) Open the Arduino Application. If you already open it, you need to restart to see changes.
After configuring the Arduino IDE environment, choose Examples > MakeBlockDrive > Me_UltrasonicSensor > UltrasonicSensorTest to program Me Ultrasonic Sensor.
Program function description
UltrasonicSensorTest reads the value of the distance between the module and the object detected (unit: cm) and outputs the results to the serial monitor in Arduino IDE every 100 ms.
Upload the code segment to Makeblock Orion and click the Arduino serial monitor, and you will see the running results as follows:
Define the port based on the one you connect Me Ultrasonic Sensor to on the main control board
Reads the value of a distance in cm
Reads the value of a distance in inch
Me Ultrasonic Sensor comes with two “eyes”, one of which (marked with T) is an ultrasonic transmitter, the other of which (marked with R) is an ultrasonic receiver. The ultrasonic transmitter transmits an ultrasonic wave in a direction and starts timekeeping. The ultrasonic wave spreads in the air, returns back immediately when meeting an obstacle in the way, and stops timekeeping immediately when the ultrasonic receiver receives the reflected wave. The transmission speed of sonic wave in the air is 340 m/s. Use the time recorded by the timer to calculate the distance from the transmission point to the obstacle, that is, s=340×t/2.