View Categories

Kontrol Servo SG90 Dengan Potensio Di PI PICO

Persiapan Bahan #

– Raspberry Pi Pico / Pico W
– Servo SG90
– Potensiometer
– Breadboard
– Kabel Jumper Male to Male
– Kabel Micro USD
– Aplikasi Thonny IDE

Wiring Servo SG90 Raspberry Pi Pico #

Sampling Code – main.py #

#Include the library files
from machine import Pin,PWM,ADC
from time import sleep

servo = PWM(Pin(0))#Include the servo motor pin
potentiometer = ADC(28)#Include the potentiometer pin
servo.freq(50)#Set the frequency

#PWM min and max value
in_min = 0
in_max = 65535
#Servo motor min and max degrees
out_min = 1000
out_max = 9000


while True:
    #Get the potentiometer values
    value = potentiometer.read_u16()
    #Convert PWM values from 0 to 180
    Servo = (value - in_min) * (out_max - out_min) / (in_max - in_min) + out_min
    #Rotate the servo motor
    servo.duty_u16(int(Servo))
What are you looking for in Partdo?