Learn the basics

Servo

A small motor with a gearbox that turns to an angle, or spins round: the two kinds, the three wires, and how a pin controls it.

A small blue servo with its three wires

Servo

A servo is a small motor with gears and a little control chip. A 180° servo turns to an angle and stays there. A 360° servo (continuous) spins round, forwards or backwards: that one can drive a wheel.

Three wires: brown or black to GND, red to +, orange or yellow is the signal from a pin.

More: how a pin controls it

The board sends a short pulse 50 times a second. A pulse of 1 millisecond means 0°, 1.5 milliseconds 90°, 2 milliseconds 180°. A 360° servo reads the same pulses as a speed: 90 stands still, below 90 turns one way, above 90 the other way. Servos can take more current than a board pin gives, so a servo board like the Kitronik Simple Servo board gives them their own battery power.

The MakeCode blocks of this program
The same in Python
def on_button_pressed_a():
    pins.servo_write_pin(AnalogPin.P0, 0)
input.on_button_pressed(Button.A, on_button_pressed_a)

def on_button_pressed_b():
    pins.servo_write_pin(AnalogPin.P0, 180)
input.on_button_pressed(Button.B, on_button_pressed_b)
#include <Servo.h>
Servo arm;                 // one Servo object per servo

void setup() {
  arm.attach(9);           // the signal wire on pin 9
}

void loop() {
  arm.write(0);            // to 0 degrees
  delay(1000);
  arm.write(180);          // to 180 degrees
  delay(1000);
}