BBC micro:bit
Driving A Motor

Introduction

Circuit

In this circuit you have,

  • Motor
  • 470 Ohm Resistor
  • NPN transistor
  • Diode 1N4148

micro:bit Circuit

Program

We'll turn the motor on when the A button is pressed, otherwise we'll switch it off.

from microbit import *

while True:
    if button_a.is_pressed():
        pin0.write_digital(1)
    else:
        pin0.write_digital(0)
    sleep(50)

Challenge

Stick to the single motor and go easy when using this much power from the micro:bit. Make a spinning circle out of card and place it on the axle of the motor. Use this in a game, as a pretty colour wheel or as a nice little fan.