In this lab, we'll be getting started with Parallax continuous rotation servo motors. You can learn more from Parallax.
Servo motors come in two types:
the basic Servo motor allows 180° rotation
a continuous Servo motor will allow full 360° continuous rotation
Since we will be using 2 Servo motors to move the wheels on a robot, we will need to use continuous Servo motors.
Keep in mind that motors differ from the basic electronic components we've used in that they draw significantly more power. This means we must be careful to manage the power supply carefully.
Electronics and microcontroller
1 x continuous rotation servo motor
1 x Arduino Uno
jumper wires
Power supply
1 x battery holder for 6 AA
6 x AA batteries (rechargeable is fine)
1 x snap attachment to DC power jack
It is extremely important that you only connect the black wire to GND and the red wire to 5V! Never mix them up!!!
The white wire (yellow in the diagram below) is for control; we'll hook it up to pin 9.
In this part of the lab, get started with a single continuous Servo motor by following the steps below.
Copy sketch from below
Upload sketch
Unplug USB
Plug in servo wires (red -> 5V, black -> GND, white -> pin 9)
Plug in battery supply
Check that your servo rotates counter clockwise for 2 seconds, then clockwise for 2 seconds, then stops for 2 seconds (and repeats this sequence).
NEVER attach both power supplies to the Arduino -- you should have the USB cable or the DC jack or neither!
Any time you want to change your sketch, follow the sequence below.
DO NOT PLUG IN THE USB cable to the computer until told to do so!
unplug your battery supply
unplug your VCC (5V) and GND wires
plug in your USB cable to the computer
upload your sketch
unplug your USB cable
plug in your VCC (5V) and GND wires
plug in your battery supply
The stop value seems to differ slightly among each servo motor part. You will have to figure out the right number for your specific servo motor. When you do, write it on a piece of masking tape and attach it to your motor.
Update: there is a little calibration dial (yellow). To calibrate, run the following sketch and rotate until the motor stops turning.
#include <Servo.h>
Servo myServo;
void setup() {
myServo.attach(9);
myServo.writeMicroseconds(1500); // Stop
}
void loop() { }
Once you've calibrated, use the following sketch to get started with the motor.
/**
* Basic code to test Parallax continuous rotation servo
* From http://learn.parallax.com/KickStart/900-00008
**/
#include <Servo.h>
Servo myServo; // Create Servo object to control the servo
int stopValue = 1500; // this may differ depending on your motor
void setup()
{
myServo.attach(9); // Servo is connected to digital pin 9
}
void loop()
{
myServo.writeMicroseconds(1700); // Counter clockwise
delay(2000); // Wait 2 seconds
myServo.writeMicroseconds(1300); // Clockwise
delay(2000);
myServo.writeMicroseconds(stopValue); // Stop
delay(2000);
}