Using a servo with the micro:bit : Help & Support
Technology

Using a servo with the micro:bit : Help & Support

Using a servo with the micro:bit : Help & Support

How to connect servo to microbit

general description

This article explains how to connect a servo motor to the micro:bit and how to code it in the micro:bit editors. also provides troubleshooting and further usage information.

content

  • connect a servo

    program a servo

    troubleshooting using a servo with the micro:bit

    more information

    connect a servo

    It’s easy to connect a servo to the micro:bit, either using alligator/alligator cables or a breadboard. a microservo like the sg90 or tower servo (either 180 degree or 360 degree rotation) can be connected from pin0, 3v and gnd and controlled by sending the signal on pin0. usually the wiring color is orange = signal, red = 3v, brown = ground (gnd)

    micro:bit and servo

    While these microservos can be powered by the micro:bit, the specified operating voltage for most servo motors is around +5v and the micro:bit can only supply a small amount of power to connected circuitry (3v and 90ma v1 and 190ma v2max). trying to consume more power than the micro:bit can safely supply could damage the device.

    for micro:bit v1 the most reliable way to use this type of servo is to power the micro:bit through a battery and use fresh batteries, as the battery voltage drops the servo will become less reliable .

    connect an external power supply to a servo

    The optimal method for connecting a servo is to use a separate battery to power the servo and use the micro:bit to control it. this way you are just connecting pin0 and gnd from the micro: bit to the servo (we still need to use gnd to share a common ground with other parts of the circuit).

    Additional battery packs often come as 4.5v (3 batteries) or 6v (4 batteries). the micro: bit will supply 0v or 3v on pwm pin0, and this has to be above the threshold of the servo’s digital input pin (this will be defined in the servo’s datasheet, and is often 0.7*vcc) . if the voltage supplied to the servo is too high, half of that voltage becomes the threshold of the pin and the 3v from the micro:bit might not be enough to drive the servo.

    micro:bit, servo and external battery pack

    With the extra connections, you may find it easier to use a breadboard and micro:bit edge connector to make building the circuit easier.

    program a servo

    servos determine their position by the ratio of the on time to the off time in a pulse of (approximately) 20 milliseconds (ms). The micro:bit makes use of pulse width modulation (pwm) as a way to simulate an analog output on a digital pin. sends a series of high-speed on/off pulses to the servo that sets its target position. for example, 0, -90, 180 degrees, or in the case of a continuous rotation servo, the speed and direction of rotation.

    make code

    To program the micro:bit to control the servo, we’ll need to send it a signal on pin0. makecode has a useful reference for servos that describes the use of the servo write pin block. note the difference in usage for 180 degree rotation and 360 degree continuous rotation servos.

    Using a servo with the micro:bit : Help & Support

    python

    in micropython, we need to set our initial pwm period for the pin and then write an analog value to it

    There is a video example of driving a servo in micropython with a useful pwm demo. there is also a third party micro:bit servo class that you can import using the micro:bit file system available in micropython.

    There are some mixed standards as to which pulse width causes which specific servo position (or servo speed and direction). This data can be found by looking in the data sheet for the model number of the servo, for example, sg90.

    troubleshooting using a servo with the micro:bit

    if the servo vibrates or does not move at all. Try these troubleshooting tips:

    • drive the servo(s) externally, not from the micro:bit. the micro:bit can only provide 3v and most servos run at around 5v.
    • in micro:bit v2, the battery power supply goes through a built-in voltage regulator. this is not the case in micro:bit v1, where the servo draws power directly from the battery.
    • use fresh batteries
    • touch the servo arms to make it start moving. a servo requires more power to start it than to keep it moving. power consumption also depends on what is connected to the servo. a heavier object will require more power.
    • check the type of servo you have. for 180 degree servos, you can control the position of the target, for continuous rotation servos, you can control the direction and speed of rotation.
    • if your project uses multiple servos, consider a connection plate/accessory dedicated servo motor. the number of pwm pins available may limit the number of servos you can control.

    more information

    kitronik’s brief guide to servos

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button