For this tutorial we used the 180 Mini Servo, this servo is great for this application. We have used this particular servo for several different projects as it is small and has a decent amount of torque.

Note:

Problem: Although we have used the BBC micro:bit as a power source for the servo, in this and other projects, this isn't the ideal method. This has to do with the maximum amount of current that the BBC micro:bit can handle, using the BBC micro:bit to supply power to a servo has you very close to this limit.

Solution: Using a battery pack to provide power directly to the servo and only using the BBC micro:bit to supply the control signal to the servo is the best way to protect your BBC micro:bit from harm and to ensure that you are getting the full amount of torque from the servo.

Using The BBC micro:bit To Control A Servo Process:

Step 1 Connecting The BBC microbit To The Servo:

The servo has a three wire connector. The brown wire is ground, the red wire is positive and the orange wire is the signal wire. The BBC microbit will send instructions to the servo from the P0 pin via the servo's signal wire.

Push the BBC micro:bit into the Breakout Board.

Use the 3 x M/F Jumper wires to connect the Servo to the Breakout Board, the table below shows how the connections are made.

BBC micro:bit Edge Connector Breakout Board

180 Mini Servo

3V Pin.

Red Wire.

GND.

Brown Wire.

P0 Pin.

Orange Wire.

Note: This experiment can also be done without the Edge Connector Breakout board. In order to do this you will need 3 x Crocodile Leads and you will need to cut off the Servo's connector and strip the three wires. The connections in the above table remain the same if using this method, though you will be connecting the Crocodile Leads directly to the BBC micro:bit.

Step 2 Write The Code:

As you can see in the picture below, we produced two code examples. This was just to illustrate that there is more than one way to get the job done.

In Code Example 1 we made use of both of the BBC micro:bit's buttons. Button A makes the servo spin around one way and Button B returns it to its starting position.

In Code Example 2 we used button A on the BBC micro:bit to start the process, the servo then continues to move one way and then the other until the BBC micro:bit is either reset or its power source is disconnected.

You can download the code directly from the links below:

We added an extra line of code in the examples below, the extra line displays either a number 1 or 2 on the BBC micro:bits LEDs to indicate when the servo changes direction.

Step 3 Download The Hex File To The BBC micro:bit And Test:

To Download: Choose your preferred option from the links above. Press the Edit button to view the code and then select compile. The code will now download to the default download folder on your computer.

Once you have downloaded the code from one of the links above, connect your BBC micro:bit to your computer via USB. Navigate to the file you downloaded in your downloads folder and drag it straight onto the BBC micro:bit in File Explorer (Windows).

Once the .hex file is on the BBC micro:bit, press button A and the servo should move. If you used Code Example 1 pressing A will make the Servo move in one direction only. If you used code example 2, pressing button A will make the servo rotate one way and then the other until you press the reset button on the BBC micro;bit or disconnect it from the power source.

Step 4 Troubleshooting:

Check that you have connected the servo to the breakout board correctly, refer to the table in Step 1 for guidance.

Ensure that the M/F jumper wires are pushed into the servo connector securely.

Note: If writing your own code, using a forever loop 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.