Professional Documents
Culture Documents
Servo
Servo
www.bluesail.co.in
info@bluesail.co.in
2
What is Servo?
Servo motor works on the PWM ( Pulse Width Modulation ) principle, which means its
angle of rotation is controlled by the duration of pulse applied to its control PIN. Basically
servo motor is made up of DC motor which is controlled by a variable resistor
(potentiometer) and some gears.
4
Servo Working
5
The sweep program will drive the arm of the servo back and forth while the Knob program
will move the arm of the servo when you turn a potentiometer.
7
Servo myservo;
int potpin = 0;
int val;
void setup() {
myservo.attach(9);
}
void loop() {
val = analogRead(potpin);
val = map(val, 0, 1023, 0, 180);
myservo.write(val);
delay(15);
}
Code for Sweep
8
#include <Servo.h>
Servo myservo;
int pos = 0;
void setup() {
myservo.attach(9);
}
void loop() {
for (pos = 0; pos <= 180; pos += 1) {
myservo.write(pos);
delay(15); }
for (pos = 180; pos >= 0; pos -= 1) {
myservo.write(pos);
delay(15);
}}
9
www.bluesail.co.in
info@bluesail.co.in