Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 9

1

www.bluesail.co.in
info@bluesail.co.in
2

Analog Reading / Writing


Servo
3

What is Servo?

A servo (servomechanism) is an electromagnetic device that converts electricity into precise


controlled motion by use of negative feedback mechanisms. Servos can be used to generate
linear or circular motion, depending on their type.

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

Servo Pin Diagram & Connection


6

Knob & Sweep

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

Code for Knob


#include <Servo.h>

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

You might also like