Case 1 - Distance Detection with Ultrasonic Sensor

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.

1.gif

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.

2.gif
3.gif

Update the firmware of Ultimate.

4.gif

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.

5.gif

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.

Was this article helpful?
2 out of 3 found this helpful

Comments

0 comments

Please sign in to leave a comment.