In this project, we adopt a capacitive touch sensor and an 130 motor to combine a fan in manual mode. We can control the startup of the fan by the capacitive touch sensor.
Required Components
Step 1
Step 2
Step 3
Step 4
Step 5
Step 6
Step 7
Completed
Open KidsBlock and connect the board to computer. Choose File –> Load from your computer.
Choose path D:\Code\2.Code_kidsIOT and open 4.4Manual mode.sb3
Click to connect to port and then .
Code Blocks
Blocks |
Code block |
---|---|
Build blocks:
Click to import library DC Motor for esp32.
Initialization
Set the sensor pin to IO27. Define a variable press with an initial value of 0 to monitor the state of motor.
Main Code
Loop:
When the module is touched (IO27 reads 1) and press = 0, the fan rotates, and press will be reassigned to 1.
When the module is touched (IO27 reads 1) and press = 1, the fan stops, and press will be reassigned to 0.
Test Result
After uploading code, touch the module and the fan starts to work. Touch it again, and the fan will stop.