Friday, August 17, 2018

Servo - Direct to Arduino


This covers controlling a micro-servo directly connected to the Arduino.  I say directly connected as opposed to using a motor shield.



Wiring

In the case of a micro servo like the SG90 shown below, it takes 5V power.

  • Brown: Ground
  • Red: 5V
  • Orange: Digital Pin



Code

The example script to refrence is:  Examples > Servo > Sweep

  • attach(digital pin #)
  • write(pos)  //values 1-180 are treated as degrees
  • writeMicroseconds(#) // values 700-2400  (fine control)
Note: if you set the the position too close to the minimum (i.e. 0 degrees or below 700us), the servo will do a full spin to the other 180.

Note2:  duty cycle is 20ms, so it's no benefit to command it any faster than that.

No comments:

Post a Comment