Case 6 - Read the value of the ultrasonic sensor

Part 1 Objective

After you write the program, the stage area of mBlock 5 displays the distance detected by the ultrasonic sensor in real time.


Part 2 Preparation

  • mBot x 1
  • USB cable (Type-B) x 1
  • Computer with network access x 1
  1. Connect mBot to the computer by using the cable.


  1. Open mBlock 5 (PC client or web version), click +add in the lower left Devices area, select mBot from the Device Library, click Connect, and select the Live mode. (Live mode: you can click on the blocks to see the real-time running effect, but you need to keep the cable connected to the computer. Upload mode: you can upload a program to mBot, and you can unplug the cable to run the program.)


Part 3 Programming

Make a variable and name it "distance" to record the distances detected by the ultrasonic sensor and display the distances on the stage area of mBlock 5 in real time. Be sure to select a port that matches the interface of the ultrasonic sensor.


Script image


Part 5 Practice

  1. Program to display the distances detected by the ultrasonic sensor in integers.
  1. Use the ultrasonic sensor to measure the length of an object.


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



Please sign in to leave a comment.