Difference between revisions of "SG90 Servo"

From Sketching with Hardware at LMU Wiki
Jump to navigation Jump to search
(Created page with "In many computers the current is not enough to drive the servo!!! If it does not work, keeps disconnecting, or rebooting the ESP the power is not sufficent and you need an ex...")
 
Line 1: Line 1:
In many computers the current is not enough to drive the servo!!!
+
'''In many computers the current is not enough to drive the servo!!!'''
  
If it does not work, keeps disconnecting, or rebooting the ESP the power is not sufficent and you need an extra power supply.
+
'''If it does not work, keeps disconnecting, or rebooting the ESP the power is not sufficent and you need an extra power supply.'''
  
 
= Schematic - Connecting the SG90 =
 
= Schematic - Connecting the SG90 =

Revision as of 00:53, 22 December 2020

In many computers the current is not enough to drive the servo!!!

If it does not work, keeps disconnecting, or rebooting the ESP the power is not sufficent and you need an extra power supply.

Schematic - Connecting the SG90

Code Example ESP8266

A0 is the analog input with 10 bit resolution. It reads the analog value every second and print it to the console and sets the servo based on the analog input.

 1 from machine import Pin, ADC, PWM
 2 from time import sleep
 3 
 4 analogPin = ADC(0)
 5 servoPin = Pin(5, Pin.OUT)
 6 pwm =  PWM(servoPin, freq=50)
 7 pwm.deinit()
 8 pwm = PWM(servoPin, freq=50)
 9 
10 while True:
11   analogVal = analogPin.read()
12   pwm.duty(int(analogVal/10))
13   print(analogVal)
14   sleep(1)