Case 6 - Read the value of ultrasonic

Part 1 Objective

User writes a program to display the real-time distance value detected by the external ultrasonic sensor in the stage area of the computer.

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

 

Part 2 Preparation

  • mBot x1
  • USB cable x1
  • Computer with network access
  1. Use a data cable to connect the mBot to the computer.

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

  1. Open MBlock5 (PC, Web, APP), click "Add" in the lower left device area, select mBot in the device library, and click “Connect”.(Live mode: you can click the building block to observe the real-time running effect, but you need to keep the data cable connected to the computer; Upload mode: You can upload the program to mBot, at which time you can unplug the data cable to run the program. ), this course needs to switch to "Live mode".

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

 

Part 3 Programming

Create a new variable and rename it to "Distance" to store the distance value of the ultrasonic detection, select it to display in real time in the stage area. Note that the interface number that matches the sensor connection interface is selected.

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

Source program diagram

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

 

Part 4 Procedure source code

Get the distance value.mblock

 

Part 5 Practice

  1. Set the distance value detected by the ultrasonic sensor as an integer
  1. Use ultrasonic sensors to measure the length of an object

 

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

Comments

0 comments

Please sign in to leave a comment.