0 0 M
Chapter 7
Little Ranging Expert
We have known that Maqueen Plus is such a changeable robot with
various functions, but more surprisingly, he can measure distance
using his ultrasound eyes. With this buddy, you can say goodbye to
your measuring tools.
Goal
1.Get to know ultrasound
2.Learn the principle of ultrasound
Electronic Component
Ultrasound Brief
Ultrasonic sensor
The transmitter sends out ultrasound,
and when hitting the object, the
ultrasound reflects as echo and will
be sensed by the receiver.
Command Learning
Block Brief
Read ultrasonic sensor Read the value the ultrasonic
sensor detects, unit: cm.
read ultrasonic sensor T P0 E P0 cm
(Preset the transmitter and
receiver on the sensor)
What is ultrasound?
As we know, when vibrating, objects produce sound waves. Some of them can be heard by human ears, while
others cannot. Scientists named the vibrating times per second as the sound frequency with its unit named as Hertz.
Almost all human beings are able to hear the sound frequencies ranging from 20 to 20000Hertz. Sound frequencies
out of that range are inaudible to humans. For those sound, the scientists name it as “Ultrasound”.
How does an ultrasonic sensor measure distance?
Ultrasonic sensors work by sending out a sound wave at a frequency above the range of human hearing. The
sensors determine the distance to a target by measuring time lapses between the sending and receiving of the
ultrasonic pulse.
t
Ultrasonic sensors will convert the reflected sound
the transmitting end
into an electrical signal. A commonly used sensor consists
S of a piezoelectric wafer that can emit ultrasonic waves.
obstacle Vibrating plate
H
the receiving end Electrode Piezoelectric wafer
θ
Hands-on Practice
Hardware Connection:
The pin connection is shown below:
+5V
GND
P2
P1
TRIG
ECHO
GND
+5V
Step 1 Create a New Project
1.Input https://makecode.microbit.org/ into your browser to enter MakeCode editor.
2.Click “new project” to enter MakeCode programming interface.
3.Add the Maqueen Plus library:https://github.com/DFRobot/pxt-DFRobot-Maqueenplus
https://makecode.microbit.org/
New Project
1.Enter MakeCode editor 2.Enter programming interface
Input the library address
3.Add the extension library
Step 2 Programming
1.Place the “show number ” block into the “forever ” block, shown as below.
2.Put the ultrasonic sensor value inside the “show number ” block to display the current distance. Add a “pause”
block to prevent the serial reading the value too fast.
Knowledge Expansion
“T” is the transmitting end, corresponding to the
“trig” on the ultrasonic sensor; “E” is the receiving
end, corresponding to the “echo” . On Maqueen
Plus, trig is the P1, echo is the P2, so we need to
set the pins in the ultrasonic block to P1, P2.
3.The entire program is shown below.
4.Name your project as “Little ranging expert” and save it.
Step 3 Download Program
Download
MICROBIT(I:)
File name: xxxxxxx.hex
1.Connect to computer 2.Download program 3.Plug in micro:bit
Step 4 Effect Display
Turn on the power switch, then we can use Maqueen Plus to measure distance. The detected distance will be
displayed on micro:bit. We can use two different measuring ways to test the accuracy of Maqueen Plus. As shown
below:
Think & Explore ?
How to use an ultrasonic sensor to measure the height of a person?
110
100
90
80
To make the measurement more accurately, you have to:
70
Pay attention to the position and direction of the ultrasound.
60
Calibrate the sensor within 10cm to prevent large error.
50
40
30
20
10