Case 1 - Distance Detection with Ultrasonic Sensor
Part 1 Objective
After you compile the program, the stage displays the distance detected by the ultrasonic sensor in real time.
Part 2 Preparation
MegaPi x 1
MegaPi RJ25 adapter x 1
Ultrasonic sensor x 1
RJ25 cable x 1
USB cable (Type-B) x 1
Computer with network access x 1
Install the MegaPi RJ25 adapter on MegaPi, connect the ultrasonic sensor to MegaPi by using the RJ25 cable, connect MegaPi to the computer by using the USB cable, open mBlock 5 (PC client, web version, or mobile app), click +add, select Ultimate 2.0 from Device Library, click Connect, and select the Live mode.
Update the firmware of Ultimate.
Part 3 Programming
Distance detection: In Live mode, after you select the check box on the left of the ultrasonic sensor port 6 distance (cm) block, the stage displays the distance detected by the ultrasonic sensor in real time.
Part 4 Practice
Change the distance output value by changing the distance between the ultrasonic sensor and the obstacle. The distance is detected and displayed on mBlock 5.