11. Servo control

Kitronik has some very clear and simple instructions for using the servo with the micro:bit. I have used content from their website (https://www.kitronik.co.uk/blog/using-bbc-microbit-control-servo) in my notes below, so many thanks to Kitronik.

Connecting the servo to the micro:bit:

The servo shown above has a three wire connector.

The BBC micro:bit will send instructions to the servo from the P0 pin via the servo's signal wire.

micro:bit edge connector Tower Pro SG90 Mini Servo

3V Pin Red Wire

GND Brown Wire

P0 Pin Orange Signal Wire

To make the physical connections to the micro:bit's edge connector strip you will need to cut off the Servo's connector, strip the three wires and attach crocodile clips or 4mm plugs.

Makecode editor script:

The script above uses button A on the BBC micro:bit to start the process, the servo then continues to move 180 degrees in one direction and then returns to its starting position repeatedly until the BBC micro:bit is either reset or its power source is disconnected.


1. Edit the script so that pressing button A will rotate the servo to the right and button B will rotate the servo to the left.

2. Changer the number in servo write block from 180 to 90 (don't go larger than 180 as these small servos only allow 180 degrees of rotation).

3. Automated parking barrier project - Using an LDR as a light sensor, create a system that will raise a barrier to allow a car into a parking space when a light beam is broken.

N.B. The current drain on this servo is between 0.1-0.5A, and the voltage range is between 3.5-6V’s. Using a forever loop in your code in favour of one of the above methods may result in the servo not receiving quite enough power to turn. You can get around this by using a dedicated 4.8v power supply to power the servo directly whilst still using the BBC micro:bit to provide the control signal.