{"title":"Servo for Micro:bit by Monk Makes","handle":"servo-for-micro-bit-by-monk-makes","url":"/products/servo-for-micro-bit-by-monk-makes","description":"The MonkMakes Servo for micro:bit board provides a really easy way to attach up to three servomotors to a BBC micro:bit. The board requires a power supply or battery pack to provide 5 or 6V to the servomotors. It includes a voltage regulator that will supply 3V back to the micro:bit, so that you don’t have to power it separately.If you have one of our Servo Kit for micro:bit products, then you will find more information about that&nbsp;here. This is where you will also finds a&nbsp;getting started guide&nbsp;for this board.Features\nHeader pins&nbsp;for three servo motors\nUp to 2A total can be supplied to the servo motors\nRegulated 3V output to power your micro:bit\nPolarity protection for the servomotors\nElectrolytic reservoir capacitor for the servomotors\n1kΩ series resistors to the control signals to prevent accidental sort-circuits of the micro:bit’s output pins.\nOrange LED to indicate that the Servo for micro:bit board has power.\nConnectionsThe picture below shows a typical setup using the Servo for micro:bit board.The following connections have been made:\n3 x servomotors plugged into header pins. These need to be the right&nbsp;way around, with the control signal (yellow or orange wire) to the left (pins marked c).\nAlligator clip lead from GND on the micro:bit to GND on the Servo for micro:bit board.\nOptional alligator clip lead from&nbsp;3V on the micro:bit to&nbsp;3V on the Servo for micro:bit board. You only need this if you want to power the micro:bit from the same battery pack as the servomotors. If you want to power the micro:bit over USB or the JST battery connector then you do not need this connection.\nAlligator clip leads between P0, P1, P2 on the micro:bit to the Servo for micro:bit board. These need to match up with the servomotors you are using, so if you only need the board for one servomotor, then just connect P0 on the micro:bit to P0 on the Servo for micro:bit and make sure that there is a servomotor attached to the header pins marked 0.\nPower to the screw terminal on the Servo for micro:bit. Typically this will be a 4xAA battery pack or other power supply. Make sure that the positive lead goes to the screw terminal marked with a +\nTest SoftwareBlock CodeTo check that everything is working,&nbsp;this Blocks code project&nbsp;will get you started. Flash it onto your Servo for micro:bit and the servo arms should all start waggling in a random manner. You can&nbsp;see a video of this&nbsp;in action here.The servo write pin block allows you to set the angle of the servomotor’s arm between 0 and 180 degrees. Note that servomotors, will not usually travel a full 180 degrees so you may find the actual range is more like 10 to 170 degrees.MicroPythonThe following MicroPython example will move the servo one way or another when you press the A and B buttons.from microbit import *def set_servo_angle(pin, angle):&nbsp; &nbsp; duty = 26 + (angle * 102) / 180&nbsp; &nbsp; pin.write_analog(duty)angle = 90set_servo_angle(pin2, angle)while True:&nbsp; &nbsp; if button_a.was_pressed() and angle &gt;= 10:&nbsp; &nbsp; &nbsp; &nbsp; angle -= 10&nbsp; &nbsp; &nbsp; &nbsp; set_servo_angle(pin2, angle)&nbsp; &nbsp; if button_b.was_pressed() and angle &lt;= 170:&nbsp; &nbsp; &nbsp; &nbsp; angle += 10&nbsp; &nbsp; &nbsp; &nbsp; set_servo_angle(pin2, angle)&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; if button_a.is_pressed() and button_b.is_pressed():&nbsp; &nbsp; &nbsp; &nbsp; display.scroll(str(angle))","vendor":"Monk Makes","product_type":"physical","in_stock":false,"options":[],"variants":[{"id":4950,"title":"Default Title","sku":"MM-SKU00073","price":17.64,"compare_at_price":0.0,"on_sale":false,"in_stock":false,"available_quantity":0,"option1":"Default Title"}]}