Data Sheet
29
14.Lesson14 MOSFET Control Fan
The MOSFET is a kind of switch. It enables you to control higher voltage project with low
voltage. There are two screw terminals on the board. One for input power source and the other
for device you want to control. In this lesson we will teach you how to use the MOSFET to control
a fan.
Material:
Crowtail- ESP8266 NodeMCU x 1
Crowtail- MOSFET x1
Hardware Connection
Open the LuaLoader, click the “Upload File…”cho ose ESP826 6 No deMCU kit demo code
-> P14_MOSFET_Control_Fan -> init.lua. After the upload completed then click “Download ” to
download the init.lua file.
print("Crowtail- MOSFET Test")
while (1) do
i=0
if (i==0) then
for i=0,1020,4 do
pwm.setup(1,500,512)
pwm.start(1)
pwm.setduty(1,i)
tmr.delay(20000)
if(i==1020) then
for i=0,1020,4 do
b=1020-i
pwm.setup(1,500,512)
pwm.start(1)
pwm.setduty(1,b)
tmr.delay(20000) -- delay 20ms
end
end
end
end
end
After successful download the file you will see the fan rotating faster and faster, when it
reach the fastest speed, it will become rotating slower and slower, and circulating.