Complete Video
The ultrasonic sensor is an input module that provides excellent non-contact distance detection, stable performance, ease of use, a small blind spot, and high accuracy. The measuring distance ranges from 2 centimeters to 400 centimeters, and the best part is that it is very inexpensive. It is widely used in the maker community, including applications such as robot distance measurement and obstacle avoidance, as well as liquid level detection.
1. Preparation Before Class
Please prepare the following for this lesson:
1. One Arduino UNO main board with an expansion board;
2. One ultrasonic sensor;
3. Four Dupont wires;
4. One USB Type A data cable;
5. Software: Mixly (米思齐, V0.998).
2. Sensor Wiring Method
Connect the ultrasonic sensor to the digital IO ports 2 and 3 of the expansion board:
1. GND (Ground) – Black connects to expansion board Black G (Pin 2);
2. VCC (Power) – Red connects to expansion board Red V (Pin 2);
3. Trig (Control) – Gray connects to expansion board White S (Pin 2);
4. Echo (Receive) – White connects to expansion board White S (Pin 3);
Note: Do not reverse the positive and negative terminals, otherwise, it may damage the sensor or the main board and expansion board.
3. Obtaining the Return Value from the Ultrasonic Sensor
Open Mixly (米思齐, V0.998), use “Serial” → “Print (Auto Line Break)”, “Sensor” → “Ultrasonic Distance Measurement”. Please ensure that the pins for “Trige” and “Echo” match the pins your ultrasonic sensor is connected to on the expansion board, as shown in the following image:
It is recommended that you read the code on the right side of the image and try to analyze its function. At the very least, you should search to understand the meaning of some commands in the code, gradually mastering Arduino syntax and key commands.
4. Distance Measurement Principle
The transmitter of the ultrasonic sensor emits ultrasonic waves in a certain direction while starting the timer. The ultrasonic waves propagate through the air, and when they encounter an obstacle, they immediately return. The ultrasonic receiver stops the timer as soon as it receives the reflected wave. Based on the recorded time t, with the speed of sound in air being 340m/s, the distance s from the emission point to the obstacle can be calculated as follows: s = 340m/s × t / 2. This is known as the time-of-flight distance measurement method.
This lesson ends here. What have you learned? Feel free to leave a message in the comments section.
If you need more related courses, please visit Toutiao, Yidian Zixun, Phoenix News, and Baidu Haokan Video and search for “Initialization Studio”.
Leave a Comment
Your email address will not be published. Required fields are marked *