While I'm IoT, my servo is humming in almost every position. I hear annoying noise every time it's not moving.
After asking Dr. Google, I know that: servo is bad and I need to use another one, or is set to position which it unable to achieve and need to find another position , or sigal transmitter makes inaccurate signal and servo set different possition each time and I need to add capacitor to average it , or it's connected to two different sources of DC  or grounds are not connected.
None of suggestions above worked. All my servos jitters, I tried various combinations about DC sources, ground is common and I tried all available servo position. It makes noise all the time. Louder or more silent, but almost all the time. `
So, I decided to just ... turn off servo, once it reach the target.
I asumed that 1 second is enough for servo to turn from min to max position (may vary in different servos), the code is here:
from random import random import machine import time class Servo: def __init__(self, pin_num): self.pin = machine.Pin(pin_num, machine.Pin.OUT) self.pwm = machine.PWM(self.pin) self.pwm.freq(50) self.pwm.duty(0) self.pos = None def set(self, pos): ftime = 1.0 if self.pos is None: sleeptime = ftime else: sleeptime = ftime * abs(pos - self.pos) self.pos = pos duty = int(40 + (115-40)*pos) self.pwm.duty(duty) print("sleeptime", sleeptime) time.sleep(sleeptime) self.pwm.duty(0)