This project lets you control DC motors and a servo wirelessly using a BBC Micro:bit. Send commands over Bluetooth ("up", "down", "left", "right") and the Micro:bit converts them to PWM signals that drive the motors. I built this for a robotics course and it works well for small RC vehicles or prototype robots.
Features
- Bluetooth UART for wireless command input
- PWM motor control for variable speed and direction
- Servo positioning for angle control
- Real-time response suitable for mobile platforms
Here's the wiring setup I used. The motor driver connects to the Micro:bit pins and handles the actual current for the DC motors. The servo runs off pin P0.
| Component | Notes |
|---|---|
| BBC Micro:bit | Main controller board |
| DC Motors (2x) | Left and right drive motors |
| Hobby Servo | For steering or other angle control |
| Motor Driver Module | H-bridge driver to control motor direction and speed |
| Bluetooth Device | Phone app or another Micro:bit for sending commands |
To run or modify this code:
- Go to MakeCode for Micro:bit
- Click Import → Import URL
- Paste:
https://github.com/alnezar/kart-microbit-motor-control - The project opens in the browser editor
| Command | Result |
|---|---|
up |
Move forward |
down |
Move backward |
left |
Turn left |
right |
Turn right |
stop |
Stop motors |
c |
Set servo range |
The main logic listens for UART data over Bluetooth and maps commands to motor control functions. Each direction function sets the appropriate pin states for the motor driver.
let recvievestring = ""
// Motor control functions
function Forward() {
pins.analogWritePin(AnalogPin.P4, 1023)
pins.digitalWritePin(AnalogPin.P5, 1)
pins.digitalWritePin(AnalogPin.P6, 0)
pins.analogWritePin(AnalogPin.P10, 1023)
pins.digitalWritePin(AnalogPin.P11, 0)
pins.digitalWritePin(AnalogPin.P12, 1)
}
function Backword() {
pins.analogWritePin(AnalogPin.P4, 1023)
pins.digitalWritePin(AnalogPin.P5, 0)
pins.digitalWritePin(AnalogPin.P6, 1)
pins.analogWritePin(AnalogPin.P10, 1023)
pins.digitalWritePin(AnalogPin.P11, 1)
pins.digitalWritePin(AnalogPin.P12, 0)
}
// Bluetooth event handlers
bluetooth.onBluetoothConnected(function () {
music.play(music.builtinPlayableSoundEffect(soundExpression.sad),
music.PlaybackMode.UntilDone)
})
bluetooth.onUartDataReceived(serial.delimiters(Delimiters.NewLine), function () {
recvievestring = bluetooth.uartReadUntil(serial.delimiters(Delimiters.NewLine))
if (recvievestring == "up") Forward()
if (recvievestring == "down") Backword()
if (recvievestring == "right") Right()
if (recvievestring == "left") Left()
if (recvievestring.charAt(0) == "c") {
servos.P0.setRange(0, 180)
}
})
// Setup
music.play(music.stringPlayable("C D E F G A B C5 ", 120),
music.PlaybackMode.UntilDone)
led.enable(false)
bluetooth.startUartService()
servos.P0.setRange(0, 180)
stop()- Platform: Microsoft MakeCode
- Language: TypeScript
- Hardware: BBC Micro:bit, DC motors, hobby servo, motor driver


