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.

fd408a16-5cd7-4e41-bb13-2cbc15f978d1.gif

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.

97145ee6-e1d4-4e22-987b-273f7e4f6319.gif

  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.)

c2e09838-6d4d-4bdd-a675-7ee3d22445a8.gif

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.

1c47f528-24e9-4d88-a213-b7674f9013e1.gif

Script image

4061526e-0644-4bdb-9215-49eefa8a0454.png

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?
1 out of 3 found this helpful

Comments

0 comments

Please sign in to leave a comment.