Microbit: DC Fan

It has been a while we play on our Microbit, the last time we use Microbit for lighting up LED and play with Scratch games. This time around, we will continue to explore on DC fan since we has been experiment it in other MCU (eg Arduino). Will microbit is easy to get it to work?

  • Once again, we need to create our schematic diagram for this project. Similar to previous Arduino DC fan project. The list of components as following:
    • 1 x Transistor
    • 1x DC Fan motor
    • 1x Microbit
    • Optional: 1x Resistor 1K ohms
    • Optional: 1x Diode
Microbit DC fan wiring
  • Analog value for PWM signal on the pin, value may be either an integer or a floating point number between 0 (0% of 3.3V) and 1023 (100% of 3.3V).
  • Go to Makecode to create the code for
    • Setup variable for min power as 300 and max power as 1023.
    • Get the difference of max – min power = 1023- 300/ 9 (speed range)
    • Pressing A button to decrease speed by 1, recalculate the power base the new speed and write to PIN 0. Check for if speed = 0 and stay at 0.
    • Pressing B button to increase power step by 1, recalculate the power base the new speed and write to PIN 0. Check for if speed = 9 and stay at 9.

Finally, we run the code and download to microbit to see result.

DC fan control by microbit

Thanks for reading and stay safe and stay home.

Leave a comment