Arduino Servo Motor control
Servo motor is an electric motor which is used for many applications. It has three wires, a motor and some gears for increasing the torque. Normally, a servo motor will rotate from 0 degree to 180 degree. A stopper inside the servo motor stops its movement from rotating 360 degree. Anyway if anybody want the servo motor to run servo motor for 360 degree and so on he/she can mod the servo motor by removing the stopper and connecting the motor directly into the DC supply without connecting it to any microcontroller or IC(integrated circuit).
PIN Configuration of a servo motor:
A servo motor comes with three wires red,brown or black and yellow or white. Servo motor are of two types micro and macro here I am using micro servo. If you are using macro servo motor then you need a high voltage supply higher than the 5V (recommended 9V or 12V).
The macro servo motor have higher torque and acceleration when compared to the lower one.
Red - 5V supply
Black or Brown - GND
Yellow or White - Signal (Any digital pins of the microcontrollers)
Usage:
Micro servo:
- in real time applications
-smaller switching
-mini projects
-smaller thermacol projects etc
Macro servo:
-also in real time applications
-in door opening and closing
-and also in many mechanical applications
-school and college projects etc
Here I just make the servo motor to turn 180 degree and back to 0 degree with a delay connected to the arduino microcontroller. If you want to buy the servo motor link is here.
The circuit diagram:
The program code for this project is given below :
Program Code
#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);
}
Hope you guys enjoyed this tutorial make this one at your home and have fun!!!
0 Comments