To test servo motor using Raspberry Pi Pico
Required Components
- Servo motor (5V) _ 1 no
- Raspberry Pi Pico board _ 1 no
- Connecting wires _ 1 set
Circuit
Steps
- Make sure the components are working properly.
- Connect Raspberry Pi Pico board VBus and GND pin to the servo motor by using wires.
- Connect servo motor data pin to the Raspberry Pi Pico pin GP15.
- Check the Python program.
- Check the circuit connections.
- Run the Python program.
Python Program
from machine import Pin,PWM
import utime
MID = 1500000
MIN = 1000000
MAX = 2000000
led = Pin(25,Pin.OUT)
pwm = PWM(Pin(15))
pwm.freq(50)
pwm.duty_ns(MID)
while True:
pwm.duty_ns(MIN)
utime.sleep(1)
pwm.duty_ns(MID)
utime.sleep(1)
pwm.duty_ns(MAX)
utime.sleep(1)