A servomotor is any kind of motor which has “awareness” of the position of its output. Simple motors, like the one that makes a fan blow, do not have sensors built in to know exactly what position their shaft is in, because it doesn’t matter. For more complex appliations, for instance the motor that moves paper through a printer, it’s important to get the “feedback” of knowing the position of the motor’s output to do the job right.
A “hobby servo” is so called because these little devices are used in hobby projects: radio controlled model cars, planes, and boats. It’s also because they’re widely used for these crafts that their cost is low and supply abundant.
Using these motors is quite simple: the Arduino tells the motor what position to go to, and the motor’s control circuitry goes there as quickly as possible and holds that position.
Wiring is easy because servo wire colors are standardized:
If you’re using the very smallest hobby servos (such as those included in the course kit) you can use the Arduino 5V supply to run the servo. However, it will run slow and may well cause the Arduino to “brown out,” i.e. suffer a voltage droop and produce unexpected effects. That’s why it’s good practice to use an external power source like a battery or bench supply as shown in the schematic.
Sample Arduino sketch to move the servo back and forth between 10º and 270º:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | #include <Servo.h> // this allows you to use the Servo library
Servo myLittleMotor; // you can call the servo whatever you want
int servoPin = 3; // pin the servo data line is plugged into
void setup() {
myLittleMotor.attach(servoPin); // set up the servo on that data pin
}
void loop() {
myLittleMotor.write(10); // tell the servo to go to 10º
delay(500); // wait a half second
myLittleMotor.write(170); // tell the servo to go to 170º
delay(800); // 8/10ths of a second
}
|
Download link for the above code: simpleServo.ino.