As you familiar with normal DC motor, when you give the power to motor they can move in 1 direction and when you change the terminal such as give positive wire in negative terminal and negative wire in positive terminal, motor can move in opposite direction. Servo motor is a small dc motor but it can contain gears that make them more powerful. Servo motor can move from 0-180 degrees. In this lecture, we use a basic small servo but it also available in large size that is more powerful.
Components :
- Arduino Uno
- Jumper Wires
- SG-90 Servo motor
Pinout of Servo :
Brown –> GND
Red –> Vcc
Orange –> D9
Circuit Diagram :
Code :
#include<Servo.h>
Servo myservo; // Create servo object to control a servo
int pos = 0;
void setup() {
myservo.attach(9); // attach the servo pin 9 to the servo object
}
void loop() {
for (pos = 0; pos<= 180; pos += 1){ // goes form 0 degree to 180 degrees
// in step of 1 degree
myservo.write(pos); // tell servo to go to position in varible 'pos'
// Change the delay to set the speed
delay(15); // waits 15ms for the servo to reach the position
}
for (pos = 180; pos>= 0; pos -= 1){ // goes form 180 degrees to 0 degrees
// in step of 1 degree
myservo.write(pos); // tell servo to go to position in varible 'pos'
// Change the delay to set the speed
delay(15); // waits 15ms for the servo to reach the position
}
}
If you want to change the position you have to change the value of pos in loop.
Good day! I just want to offer you a big thumbs up for your excellent information you have got here on this post. Ill be coming back to your blog for more soon.