# Project objective: Gradually move the servo arm to its min to max position (at 100 increments) and vice-versa
# Additional features: LED indicator, speed adjustment via potentiometer, real-time position display
#
# Hardware and connections used:
# Servo GND to Raspberry Pi Pico GND
# Servo V+ to Raspberry Pi Pico 3.3 V
# Servo PWM pin to GPIO Pin 15
# LED anode to GPIO Pin 14 (with a current-limiting resistor)
# LED cathode to Raspberry Pi Pico GND
# Potentiometer middle pin to ADC Pin 27, other pins to VCC and GND
#
# Programmer: Adrian Josele G. Quional
# https://wokwi.com/projects/439073584985425921
from picozero import Servo, LED
from machine import ADC
from time import sleep
# Creating objects
servo = Servo(22)
led = LED(14)
pot = ADC(27)
# Function to move servo and blink LED at min and max positions
def move_servo_with_led():
for position in range(0, 101): # From 0 to 100%
servo.value = position / 100 # Convert to 0.0 to 1.0
print(f"Servo Position: {position}%")
sleep(speed)
led.on()
sleep(0.5)
led.off()
for position in range(100, -1, -1): # From 100% to 0%
servo.value = position / 100 # Convert to 1.0 to 0.0
print(f"Servo Position: {position}%")
sleep(speed)
led.on()
sleep(0.5)
led.off()
# Continuously move servo and adjust speed based on potentiometer
while True:
pot_value = pot.read_u16()
speed = (pot_value / 65535) * 0.02 # Map pot value to sleep time between 0 and 0.02 sec
move_servo_with_led()