Microbit Robotics & Engineering Teacher Training
15 mins
+100 XP
What you need:
Chromebook/Laptop/PC

How to program a Servo

Learn the concepts and techniques of programming a servo motor for precise angular movement.
Learning Goals Learning Outcomes Teacher Notes

Live Class Feed

This is a live feed of the latest activity by your students on this lesson. It will update in real-time as they work on the lesson.
Load previous activity

    1 - Understanding Servo Motors

    Servo motors are a type of motor that can be controlled to move to a specific angular position. They are commonly used in robotics for tasks such as steering and controlling robotic arms. In this lesson, we will learn about the concepts and techniques for programming a servo motor.

    2 - Servo Control Signals

    Servo motors typically use Pulse Width Modulation (PWM) signals to control their position. PWM signals consist of a series of pulses with varying widths. The width of the pulse determines the desired angular position of the servo motor.

    3 - Programming a Servo with Micro:bit

    To control the servo motor's position, you will write code that sends specific signals to the motor. These signals are in the form of Pulse Width Modulation (PWM) signals, which are a series of pulses with varying widths. The width of the pulse determines the position of the servo motor.

    In this example, we set the servo motor to a neutral position (90 degrees) initially. When button A on the Micro:bit is pressed, the servo motor will move to 0 degrees, and when button B is pressed, it will move to 180 degrees. This will be achieved by sending appropriate PWM signals to the servo motor through the Micro:bit's pins.


    4 - Understanding Servo Speed

    Now let's learn about servo speed and how it affects the movement of a servo motor. Observe the difference in speed by looking at the two images.

    The first image sets the speed to 10% and the second sets the speed to 80%.

    By controlling the speed of a servo motor, you can achieve smoother and more precise movements in your projects.



    5 - Setting Servo Rotation Range

    If you want to limit the rotation range of a servo you can set it’s minimum and maximum rotation angle. The minimum angle limit is set in degrees from 0 to 90. The maximum rotation angle is set in degrees from 90 to 180.

    Let's understand the given code snippet:

    1. The code sets the range of the servo motor connected to Pin P0. In this case, the servo motor's minimum angle is set to 45 degrees and the maximum angle is set to 90 degrees. This means that the servo motor will only rotate within this specified range.
    2. The code listens for Button A to be pressed. When Button A is pressed, the servo motor connected to Pin P0 will be set to a 45-degree angle.
    3. The code listens for Button B to be pressed. When Button B is pressed, the servo motor connected to Pin P0 will be set to a 90-degree angle.

    Unlock the Full Learning Experience

    Get ready to embark on an incredible learning journey! Get access to this lesson and hundreds more in our Digital Skills Curriculum.

    Copyright Notice
    This lesson is copyright of Coding Ireland. Unauthorised use, copying or distribution is not allowed.
    πŸͺ Our website uses cookies to make your browsing experience better. By using our website you agree to our use of cookies. Learn more