# Servo Motor

## Circuit Python Library

<https://github.com/adafruit/Adafruit_CircuitPython_Motor>

## Code

```python
"""
Servo Demo Code
Breadstick Innovations
April 28, 2024
https://learn.breadstick.ca/breadstick/breadsticks/raspberry-breadstick/code-examples/servo-motor

Servos are controlled via a particularly defined PWM signal.
The freqency of the signal is 50Hz and duty cycle varies between 5% to 10% to swing through 180°.
This can be said another way.
The period of the signal is 20ms, and the positive pulse is varied between 1ms and 2ms.
These timings are guidelines and depend on multiple factors.
Adafruit's motor library has a Servo object that can handle converting angles to pulse widths.
Before creating a Servo object, we must first creat a PWMOut object and set the 50Hz frequency.
When creating the servo object, you can adjust the min_pulse and max_pulse to achieve 180° range.
"""

from board import *
from time import sleep
from pwmio import PWMOut
from adafruit_motor import servo

pwm_16 = PWMOut(D16, frequency=50, duty_cycle=0)
servo_16 = servo.Servo(pwm_16, min_pulse=700, max_pulse=2450)

delay = 2
while True:
    servo_16.angle = 0
    sleep(delay)

    servo_16.angle = 90
    sleep(delay)

    servo_16.angle = 180
    sleep(delay)

    servo_16.angle = 90
    sleep(delay)
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://learn.breadstick.ca/breadstick/breadsticks/raspberry-breadstick/code-examples/servo-motor.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
