

Open KidsBlock and connect the board to computer. Choose File –> Load from your computer.

Choose path D:\Code\2.Code_kidsIOT to open 4.2Trigger mode.sb3.

Click
to connect to port and then
.

Q :After uploading the code, the detected distance is closer than the set value, and the fan starts to work, yet the monitor stops outputting distance values, with a prompt reading:

A :The power supply may be insufficient, so an external power supply may be required.


Code Blocks
|
Blocks |
Code block |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|

Build blocks:
Click
to add libraries DC Motor for esp32 and Ultrasonic.

Initialization
Initialize the serial port first.


Main Code
Loop: the ultrasonic sensor reads the distance values and the serial monitor prints them. It determines whether the value is less than 10cm(this threshold can be modified).
Distance < 10, fan rotates.
Distance > = 10, fan stops.




