Arduino Servo Motor
Arduino Servo Motor
Outline
Tower Pro SG-5010 Wiring Diagram Arduino Servo Shield Arduino Servo Library Communication Protocol Let's Roll...
Operating Voltage: 4.8V~6.0V Stall torque: 5.50 kg-cm (4.8V) 6.50 kg-cm (6.0V) Operating speed: 0.20 sec/60degree (4.8V) 0.16 sec/60degree (6.0V) Dead band width: 10us Temperature Range: 0 ~ 55 Dimension: 40.2 x 20.2 x 43.2 mm Rotational Range: 180 degree
Wiring Diagram
SIGNAL
GND VCC
Functions
attach() Attach the Servo variable to a pin. Syntax: servo.attach(pin) servo.attach(pin, min, max) Parameters pin: the number of the pin that the servo is attached to min (optional): the pulse width, in microseconds, (defaults to 544) max (optional): the pulse width, in microseconds, (defaults to 2400)
Functions
write() Writes a value to the servo, controlling the shaft accordingly. Syntax: servo.write(angle) Parameters angle: the value to write to the servo, from 0 to 180
Functions
writeMicroseconds() Writes a value in microseconds (uS) to the servo, controlling the shaft accordingly. Syntax: servo.writeMicroseconds(uS) Parameters uS: the value of the parameter in microseconds(int)
Functions
read() Read the current angle of the servo (the value passed to the last call to write()). Syntax: servo.read() Returns: The angle of the servo, from 0 to 180 degrees.
Functions
attached() Check whether the Servo variable is attached to a pin. Syntax: servo.attached() Returns: true if the servo is attached to pin; false otherwise.
Functions
detach() Detach the Servo variable from its pin. If all Servo variables are detached, then pins 9 and 10 can be used for PWM output with analogWrite(). Syntax: servo.detach()
Example
#include <Servo.h> Servo myservo; int pos = 0; void setup() { myservo.attach(9); } // create servo object to control a servo // a maximum of eight servo objects can be created // variable to store the servo position // attaches the servo on pin 9 to the servo object
void loop() { for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees { // in steps of 1 degree myservo.write(pos); // tell servo to go to position in variable 'pos' delay(15); // waits 15ms for the servo to reach the position } for(pos = 180; pos>=1; pos-=1) { myservo.write(pos); delay(15); } } // goes from 180 degrees to 0 degrees // tell servo to go to position in variable 'pos' // waits 15ms for the servo to reach the position
Communication Protocol
Communication Protocol
First two bytes (0xFF) as the starting bytes Angel from 0 ~ 180 Check Sum = Byte1^Byte2^Byte3^...^ByteN
Let's Roll...
Try to control two and more servo motor. Try to assign a home position to the robot arm. Try to assign the robot arm to another pose and them back to the home position