0% found this document useful (0 votes)
34 views

Interfacing Servo Motor With Arduino Uno

Uploaded by

pranaysoyam1206
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views

Interfacing Servo Motor With Arduino Uno

Uploaded by

pranaysoyam1206
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Interfacing Servo Motor with Arduino Uno

Specifications Servo Motor

Servo Motor consists of three pins: VCC, GROUND, and


PWM signal pin.
The VCC and GND is for providing power supply, the PWM
input pin is used for controlling the position of the shaft by
varying pulse width.
Minimum Rotational Angle : 0 degrees
Maximum Rotational Angle : 180 degrees
Operating Voltage : +5V
Torque : 2.5 kg/cm
Operating Speed : 0.1 s/60 degree
DC Supply Voltage : 4.8V to 6V
Working of Servo motor

The hobby servo motor which we use here


consists of 4 different parts as below.
Simple DC Motor

Potentiometer

Control Circuit Board

Gear Assembly

Servo Motor Pinout
Interfacing Servo Motor with Arduino Uno
Sweep at 90 and 180 degree
#include <Servo.h>
Servo servo;
void setup() {
servo.attach(3);
}
void loop()
{
servo.write(90);
delay(1000); }
}
Sweep at different angle
#include <Servo.h> servo1.write(60);
Serial.println("SERVO IS AT ANGLE OF
Servo servo1;
60 DEGREE");
int servoPin = 9; delay(2000);
void setup(){ servo1.write(90);
servo1.attach(servoPin); Serial.println("SERVO IS AT ANGLE OF
Serial.begin(9600); 90 DEGREE");
} delay(2000);
servo1.write(180);
void loop(){
Serial.println("SERVO IS AT ANGLE OF
servo1.write(0); 180 DEGREE");
Serial.println("SERVO IS AT ANGLE OF 0 DEGREE"); delay(2000);
delay(2000); }
servo1.write(30);
Serial.println("SERVO IS AT ANGLE OF 30
DEGREE");
delay(2000);
servo1.write(45);
Serial.println("SERVO IS AT ANGLE OF 45
DEGREE");
delay(2000);
Sweep at 0 to 180 degree and 180 to 0 degree
#include <Servo.h>
Servo servo;
void setup() {
servo.attach(3);
}
void loop()
{
servo.write(0);
delay(1000);
servo.write(180);
delay(1000);
servo.write(0);
}
}
Sweep interms of steps using FOR loop
#include <Servo.h>
Servo servo;
int angle = 10;
void setup() {
servo.attach(3);
}
void loop() { // rotate from 0 to 180 degrees
for(angle = 10; angle < 180; angle++) {
servo.write(angle);
delay(15); } // now rotate back from 180 to 0 degrees
for(angle = 180; angle > 10; angle--)
{
servo.write(angle);
delay(15); }
}
Using Potentiometer

#include <Servo.h>
int potPin = 0; // New Variable potPin has added
int servoPin = 9; //declare the Arduino pin to which the servo motor’s control pin is
connected.
Servo servo; //define multiple servos
void setup()
{
servo.attach(servoPin); //link the servo object to the control pin of our servo:
}
void loop()
{
int reading = analogRead(potPin);
int angle = map(reading, 0, 1023, 0, 180);
servo.write(angle); // update the servo’s position to the angle selected by the
potentiometer.
}

You might also like