Servo Motor
What you'll build¶
Press button A to turn the servo to 90°, button B to return it to 0°.
Wiring¶
| Part | Part pin | micro:bit pin |
|---|---|---|
| SG90 servo | Signal (orange) | P0 |
| SG90 servo | Power (red) | 3V (or an external 5 V supply for heavier loads) |
| SG90 servo | Ground (brown) | GND |
Code¶
How it works¶
Hobby servos read the width of a repeating pulse to choose their angle. set_angle() maps 0–180° onto an
analog duty value and writes it with pin.write_analog().
Try this next¶
- Sweep smoothly from 0° to 180° in a loop.
- Control the angle by tilting the board with
accelerometer.get_x(). - Build a pointer that shows the temperature on a dial.