Chapter 09
Question 6
Explain the operation of the Arduino “servo.write()” library function and discuss how it effects a
standard and continuous rotation servo.
Answer
• Used to write an angle value from 0 to 180 degrees, to control the servo shaft position.
• On a standard servo this will set the angle of the shaft in degrees, moving the shaft to the
desired degree position.
Where a value of:
0 is fully counter clockwise, 90
is in the middle position, and 180
is fully clockwise.
On a continuous rotation servo, this will set the direction and speed of the servo shaft. Where
a value of:
0 is full speed counter clockwise rotation,
90 results in no rotation, and
180 is full speed clockwise rotation.
Question 10
Write an Arduino C program to control a servo motor with a potentiometer. The servo motor signal
control wire is connected to pin 10 and its control range is from 700 us to 2300 us The 10k pot is connect
to the Arduino A3 pin Update the servo motor position with the pot setting every 100 ms.
Answer
#include <Servo.h>
Servo servoM1;
const int pinPot = A3;
const int servoPin = 10; int
iVal;
void setup() {
servoM1.attach(servoPin);
void loop()
iVal = analogRead(pinPot); int pulseWidth =
map(iVal, 0, 1023, 700, 2300);
servoM1.writeMicroseconds(pulseWidth);
delay(100);