Servo Sg90 with Arduino :

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.

SG-90

Components :

  • Arduino Uno
  • Jumper Wires
  • SG-90 Servo motor

Pinout of Servo :

Brown –> GND

Red –> Vcc

Orange –> D9

SG-90 Pinout

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.

1 Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

Facebook
YouTube
× Contact us