Activities
A servo is a combination of a dc motor and a position sensor, usually a potentiometer. The movement of the motor is constrained so that the output arm can only turn through a 180 degree arc. The servo takes a constant dc power supply and a PWM signal. The ratio of high to low in the PWM signal tells it what angle is required on the output. The control system within the servo takes care of monitoring and adjusting the motor to maintain this position.
These devices are used heavily in radio control (rc) models, for steering, moving throttles, adjusting flaps and ailerons etc.
The three pins of the servo connector should plug directly into one of the two 'servo' connectors on the motor control board. With the wires from the servo being red (5v), brown/black (gnd), and orange (signal).
On our control board the two servo control pins correspond to Arduino pins D9 and D10
Arduino reference docs for the Servo Library
We will use the servo to rotate the direction that the Ultrasonic Sensor points in, enabling the robot to look from side to side for obstructions.
Test the servo is wired correctly using Examples -> Servo -> Sweep
This example should move the servo arm through its full sweep.
Next try an interactive example:
#include <Servo.h> Servo myservo; void setup() { myservo.attach(9); Serial.begin(9600); } void loop() { if (Serial.available()) { int angle = Serial.parseInt(); if (angle < 0) angle=0; if (angle > 180) angle=180; myservo.write(angle); } delay(500); }