Control of servo motor using arduino
Aim:
To control the servo motor using the arduino.
Components Required:
v 1×DC Servo motor
v 1×Arduino UNO
v 3×Jump wires-(3 Nos)
Theory:
Servo Motor:
Servo motor is the combination of DC motor, potentiometer and gears. It consists three pins red colour wire pin is used for supplying voltage, black or brown wire pin is used to connect ground and white or yellow wire pin used to control of shaft postion.
Here by varying the PWM signals, We can precisely control the shaft postion. If you want to much more details about the servo motor working refer to Wikipedia.
How to give the connections:
Step1:
Keep the arduino UNO along the cable and servo motor on the table.
Step2:
Ø Connect +5v pin to the red colour wire pin of the servo motor.
Ø Connect Gnd pin to the black or brown colour wire pin of the servo motor.
Ø Connect Digital pin 9( Or any PWM Pin) of the arduino to the white or brown wire pin of servo motor.
Step3:
Run the program which is written below.
Program:
#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);
}
}
What does the program say:
v Initialize the servo motor library function with <servo.h>
v Name the servo as myservo.
v Initialize the position as zero.
v In setup function, it says that the servo is attached at 9th digital pin.
v In loop function, the for loop gives control over the servo motor to rotate the shaft to 0 to 180 and 180 to 0.
Here when the program executed, the servo motor rotate to 180 degree and servo motor return to 0 degree.
If you have any doubt,please free to contact me at marirenu141@gmail.com
No comments:
Post a Comment