Ping trig…echo…unit:
This block is inside
the sonar package we added. We can use
this block to get the time, distance in cm and
distance in inches detected from the
ultrasonic ranging sensor. In this experiment,
we set the trig pin and echo pin of the sensor
are P13 and P15 port of micro:bit. And the
data we want to get is the distance in cm.
Start melody repeating:
We use the
Start
Melody Repeat
block to play a melody to
remind the door is about to close, please be
careful! When the melody ends, the door
begins to close.
Download the program to micro:bit to see what happens.
Have you ever been late for school because you forgot to set the alarm clock? This is really
embarrassing! Let's make an alarm clock with a RTC module together today, and say goodbye
to being late!
Experiment 14 – Make an accurate clock
Instruction
Learn how RTC work and use it to make a clock with buzzer.
Learn how to set time for RTC.
Target
When the distance detected by the ultrasonic sensor is less than 20 cm, open
the door (the servo’ s shaft rotates 180 degrees), and the matrix LEDs of the
micro: bit will display "Welcome". After 2 seconds, the buzzer will play a melody
to warn that the door is about to close. Then, when the distance detected by
the ultrasonic sensor more than 20 cm, the door start closing (the servo’ s
shaft rotates 0 degrees).
Result
How to apply ultrasonic ranging sensors to the car to make the car have an obstacle
avoidance function?
33