from machine import Pin, PWM
from utime import sleep
# Connect servo to pin 21 using PWM
servo1 = PWM(Pin(21), freq=50)
# Move servo to the left
servo1.duty(30) # Small number = left
sleep(1) # Wait 1 second
# Move servo to the middle
servo1.duty(50) # Middle position
sleep(1)
# Move servo to the right
servo1.duty(70) # Big number = right
sleep(1)
# Back to middle
servo1.duty(50)