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))

Powered by BetterDocs

Leave a Reply

Your email address will not be published. Required fields are marked *

Select the fields to be shown. Others will be hidden. Drag and drop to rearrange the order.
  • Image
  • SKU
  • Rating
  • Price
  • Stock
  • Availability
  • Add to cart
  • Description
  • Content
  • Weight
  • Dimensions
  • Additional information
Click outside to hide the comparison bar
Compare
What are you looking for in Partdo?
× How can I help you?