Datasheet
Chapter 2 • Shield, Lights, Servo Motors
58 • Robotics with the BOE Shield-Bot
4. Use the writeMicroseconds function to set the pulse time. You can do this
inside either the
setup or loop function:
servoLeft.writeMicroseconds(1500); // 1.5 ms stay-still signal
Seconds, Milliseconds, Microseconds
• A millisecond is a one-thousandth of a second, abbreviated ms.
• A microsecond is a one-millionth of a second, abbreviated μs.
• There are 1000 microseconds (μs) in 1 millisecond (ms).
• There are 1,000,000 microseconds in 1 second (s).
Example Sketch: LeftServoStayStill
For calibrating servos, your sketch will need to send signals with 1.5 ms pulses. Take a look
at the timing diagram below. This stay-still signal’s high pulses last 1.5 ms. That’s halfway
between the 1.7 ms full-speed-counterclockwise and 1.3 ms full-speed-clockwise pulses.
Create and save the LeftServoStayStill sketch, and run it on your Arduino. The
pin 13 LED should glow, about halfway between the two brightness levels you
observed earlier.
/*
Robotics with the BOE Shield – LeftServoStayStill
Generate signal to make the servo stay still for centering.
*/
#include <Servo.h> // Include servo library
Servo servoLeft; // Declare left servo
void setup() // Built in initialization block
{
servoLeft.attach(13); // Attach left signal to pin 13
servoLeft.writeMicroseconds(1500); // 1.5 ms stay still signal
}