The Servo widget sends values to a device port to set the position of a servo motor. Servos can normally rotate 180 degrees, and the widget accepts values from 0 – 180 corresponding to the position of the servo.
Connect another widget’s output to the input of Servo.
To set the digital output port on your device, type in D plus the port number on the right hand tab. Check with your device documentation to be sure the port can support a servo motor.
Note that the checkbox on the upper right can be unchecked to turn off data for the servo. Sometimes you don’t want the motor to move to prevent breakage of your mechanics, and by unchecking this box, the rest of your project can continue to run.
Even without another widget connected, you can simulate input values by moving the on-screen “knob” to send values out to your hardware. Make sure your input to the Servo widget has the range you want. For example, on the AnalogIn widget, as a starting point, you could set Min to 0 and Max to 180.
Servo accepts values form 0-180, which will position the servo to a position in degrees for the input value. Most servos can rotate in a range of a half circle, i.e. 180 degrees.
Once you have your real input attached to the Servo widget, you can use that input to move the motor.
4 How Servos Work
Standard servo motors allow precise control of the position of a motor, typically rotating up to 180 degrees (a half circle).
- A 0 value will position the motor to one extreme
- 90 will position it in the middle
- 180 will position it to the other extreme
When using a “continuous” servo, the behavior is different. These are modified servos that will turn continuously in either direction, and cannot be set to a specific position. Instead, the value sent to them determines the direction and speed of the rotation.
- 90 (plus or minus a few degrees depending on the individual servo) will tell the servo to stop moving
- 0 sets the highest speed in one direction – values closer to, but below 90 will be slower
- 180 sets the the highest speed in the other direction – values closer to, but above 90 will be slower
5 Wiring a Servo
Servos have 3 wires that are connected to your device:
- Ground – GND – black or brown
- Power – 5V – red or orange (center)
- Control – Digital Pin – white, yellow or orange
To hook a servo up to the Arduino, power and ground go to the standard 5V and GND pins. The control cable is connected to any of the digital pins starting at 2 or greater. Pin 9 is commonly used in examples (Note: the current NTK limits servo Arduino ports to 3,5,6,9,10,11).
Here’s a diagram on how to wire up the servo to your Arduino. You can use any digital pin for the control wire starting at pin 2 (note: in the current version of NTK you are limited to ports 3,5,6,9,10,11). Since most servos have a female, 3 pin connector on the end of their wires, you can use your breadboard jumper wires, putting a one pin in the connector, and the other end of the jumper into the Arduino or other device.
6 Powering a Servo
Method 1 – USB Power
For a single standard servo, you can usually get away with using the power provided by the USB connected on your Arduino or other device.
But if you have two servos, or use the larger, higher power servos, you may need to power your servos with an external power supply.
Method 2 – Power Connector
To provide more power, you can use the device power connector (for a battery or AC power adapter) to give the Arduino more power than the USB can provide.
Method 3 – Power Servos Directly
If your Arduino or other device resets or gets too hot when using your servo(s), you need to power the servos independently from your device. In this method, you provide power directly to the servos, and do not connect servos to a device power port. The important requirement here is that the ground of the external power supply and the ground of Arduino must be connected together. Here’s a diagram of how to wire a power supply like this. Be sure to match the power supply voltage that of your servos. Most servos run at 6V, so your power supply should be about that voltage. In this example, the four AAA or AA batteries are 1.5V each, so this battery pack as a whole will provide 6V.
7 Mechanical Connections
To make projects with servos you often need to make a mechanical connection to something else that the servo moves. Here are some links for commonly used attachments:
- Linkages: https://www.servocity.com/html/linkages.html
- Video showing the use of a linkage: www.youtube.com/watch?v=wey98_Wniv4
- Complete Pan & Tilt kit: http://www.adafruit.com/products/1967
- Pan & Tilt for Standard Servo Size: www.servocity.com/html/spt100_pan___tilt_system.html
- Pan & Tilt for Small Servo Size: www.servocity.com/html/spt50_sub-micro_pan___tilt.html
- Wheel: www.adafruit.com/products/167