Servo



So here is everything (except jumper wires) you need to control an RC (Radio Control) servo with a potentiometer. The Arduino, tiny breadboard, potentiometer and jumper wires are from your Adafruit Industries starter kit that you picked up on the first day. You can get a screwdriver from the kit in the Smartsurfaces team boxes. Servos are electromechanical devices that respond to a control signal, which instructs them to move their output shaft to a certain position. A servo is normally plugged in with a three pin connector: power, ground and signal. The signal wire carries a PWM (Pulse-Width Modulation) signal - a pulse that tells the servo to move its output shaft. A potentiometer (pot) is a three-terminal resistor with a sliding contact that forms an adjustable voltage divider. Potentiometers are used to adjust the level of analog signals (e.g. volume controls on a radio or a dimmer on a lamp), and as control inputs for electronic circuits.


Put the pins on the potentiometer into the breadboard. Note that the pins are on one side of the base of the potentiometer. There are grooves in the plastic on this side also.


The middle pin is for the signal.


Make sure you have left some rows on the breadboard that you can attach jumper wires to.


The servo you have been provided with has a 3-pin (female) connector attached. You could connect this to your breadboard with jumper wires but that would be a bit ungainly. Instead modify some (male) breakable header strip so that the pins on either side of the plastic strip are an even distance. This should be fairly easy to do.


The pins should slide when you apply a bit of pressure from some pliers.


Put the header pins into the connector on the end of the servo cable.


Note the orientation of the individual wires. The orange wire in this case carries the signal (other brands of servo may be have different colored wires).


Now you can attach the servo to the breadboard.


So far, so good. How to specify a servo:

Motor Type

The standard motor used in an RC servo is a three pole ferrite motor. Five pole coreless motors are used in some high speed servos, and heavy duty coreless motors are using in some high end heavy duty RC servos.

Bearing Type

Standard servos have bushings supporting the main shaft, heavy duty servos typically have one or two ball bearings supporting the main shaft.

Speed

The speed of a servo is measured in the number of seconds it takes to move a certain amount of rotation, usually 60 degrees. The smaller the number, the faster the servo is. A servo that is rated 0.15 seconds is able to rotate 60 degrees in 0.15 seconds.

Torque

The torque rating specifies how much force the servo can exert. It is typically expressed in units of ounce-inches (oz-in) or kilogram-centimeters (kg-cm). The higher the number, the more force the servo can exert. If you know the length of the servo arm that will be used, you can use this measurement and the servo torque rating to calculate how much force end of the arm can exert. A long arm will reduce the maximum possible force, and a short arm will increase it.

Size and Weight

The size and weight of a servo are important considerations when used in a small airplanes or other RC devices where there is not much room, or weight is an issue. Typically, smaller servos will have lower torque ratings.

Here are the specifications on the servo you have been given:
3 pole ferrite, all nylon gear
Top ball bearing
Operating Voltage: 4.8V~6.0V
Operating speed:
    0.20sec/60degree (4.8V)
    0.16sec/60degree (6.0V)
Stall torque:
    5.2kg*cm (4.8V)
    6.5kg*cm (6.0V)
Temperature Range: -20℃~60℃
Dead band width: 4ms
Dimension:
41 x 20 x 38mm
Weight: 41g


The servo you have been provided with comes with a little zip bag of hardware. There are several 'horns' that will fit on the nylon gear shaft that you can attach to whatever you want to rotate. Pick one and attach it with the short, fat, screw. The longer, thinner screws are for attaching things to the servo through the holes in the 'horns'.


Attach your breadboard to +5v and gnd on your Arduino.


Use another 2 jumper wires to attach both the gnd pins of the servo and the potentiometer to the row on the breadboard that is connected to gnd on the Arduino.


Use 2 more jumper wires to attach the +v pins of the servo and the potentiometer to the row on the breadboard that is connected to +5v on the Arduino.


Attach the signal pin of the potentiometer to pin 0 on the Arduino.


Attach the signal pin of the servo to pin 9 on the Arduino (in the photo this wire is white).


The circuit is complete. Attach your USB cable to your Arduino and upload the code.

Here is the code for this exercise:

// Controlling a servo position using a potentiometer (variable resistor) 
// by Michal Rinott 
// Modified by J. Marshall so that what is happening with the pot can be seen in the monitor
// Adjust your servo so that when the reading is 90 it is completely stationary

#include <Servo.h>
 
Servo myservo; // create servo object to control a servo
 
int potpin = 0; // analog pin used to connect the potentiometer
int val; // variable to read the value from the analog pin
 
void setup()
{
  Serial.begin(9600); // start the monitor
  myservo.attach(9); // attaches the servo on pin 9 to the servo object

 
void loop()

  val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)
  val = map(val, 0, 1023, 0, 179); // scale it to use it with the servo (value between 0 and 180)
  myservo.write(val); // sets the servo position according to the scaled value
  Serial.println(val); // print the reading in the monitor
  delay(15); // waits for the servo to get there
}

You can watch what is happening in the serial monitor:





The servo you have is a standard servo. This is composed of an electric motor mechanically linked to a potentiometer inside the black, plastic housing. Pulse-width modulation (PWM) signals sent from the microcontroller are translated into position instructions inside the servo. When the servo is commanded to rotate, the motor is powered until the internal potentiometer reaches the requested position. Continuous rotation servos are also available - these can pan through 360 degrees of arc smoothly - useful for driving a robot forwards and backwards, for example. Most continuous rotation servos have a hole in their sides that provides access to the centering potentiometer. This can be adjusted with a small screwdriver and makes it easy to match multiple servos (i.e. you can set the center - static - position to 90). This video shows the same code and circuit as above, but with a continuous rotation servo:
 

Comments