CAVEDU EducationDFRobotDFRobot Robotics
Published © GPL3+

Smart Fan Control System with Micro:bit

In this article, we will show you how to create a smart fan control system with BBC micro:bit.

IntermediateFull instructions provided3 hours5,302
Smart Fan Control System with Micro:bit

Things used in this project

Story

Read more

Code

demo1.py

Python
from microbit import *
mode = [700, 900, 1023]
while True:
   for speed in mode:
      print(speed)
      pin8.write_analog(speed)
      sleep(1000) 

demo2.py

Python
from microbit import *
fan_switch = False
while True:
   if pin12.read_digital():
      fan_switch = not fan_switch
      print('ON' if fan_switch else 'OFF')
      pin8.write_digital(int(fan_switch))
      while pin12.read_digital():
         sleep(100)  

demo3.py

Python
from microbit import *
fan_switch = False
fan_mode = ["slow", "medium","fast"]
fan_power = [700, 900, 1023]
def fan_mode_switch(value):
   interval = int(1023/3)
   for i in range(3):
      if value >= i * interval and value < (i+1)*interval:
         break
   return fan_mode[i], fan_power[i]

previous_mode, power = fan_mode_switch(pin0.read_analog())

while True:
   if pin12.read_digital():
      fan_switch = not fan_switch
      print('Fan status: ' + ('ON' if fan_switch else 'OFF'))
      while pin12.read_digital():
         sleep(100)
   if fan_switch:
       mode, power = fan_mode_switch(pin0.read_analog())
       if mode is not previous_mode:
          previous_mode = mode
          print("Fan mode: ", mode)
          pin8.write_analog(power)
       else:
          previous_mode = 'OFF'
          pin8.write_analog(0)
       sleep(300) 

Credits

CAVEDU Education

CAVEDU Education

11 projects • 28 followers
We provide tutorials of robotics, Arduino, Raspberry Pi and IoT topics. http://www.cavedu.com
DFRobot

DFRobot

62 projects • 143 followers
Empowering Creation for Future Innovators
DFRobot Robotics

DFRobot Robotics

7 projects • 13 followers

Comments