How to Connect Servo Motor with Arduino?

Servo motor is basically used for robotics, toys, RC helicopters, hobby projects, etc. for the rotation of angles up to 180 degrees, It works with operating voltage of 4.8v to 6v DC supply.

Interfacing Servo 9G with Arduino Uno R3

Interfacing Servo 9g with Arduino uno, for connecting we need below components

  1. Servo 9g Motor *1
  2. Arduino Uno R3 Microcontroller board *1
  3. Programming Cable *1
  4. Jumper wires Male to Female *3

Servo Motor 9g have 3 colors of wires on which

  1. Red Color of Wire is Vcc(Positive) Connected to 5v Pin of Arduino Uno R3
  2. Brown color of Wire is Gnd(Ground) Connected to Gnd pin of Arduino Uno R3
  3. Orange color of wire is Pwm Connected to 9th Pwm pin of Arduino Uno R3 (We can connect any Pwm pins in Arduino 11,10,09,06 & 05)
#made_with_Tinkercad

Example Code:

*/

#include <Servo.h>

int pos = 0;

Servo servo_9;

void setup()
{
  servo_9.attach(9, 500, 2500);

}

void loop()
{
  // sweep the servo from 0 to 180 degrees in steps
  // of 1 degrees
  for (pos = 0; pos <= 180; pos += 1) {
    // tell servo to go to position in variable 'pos'
    servo_9.write(pos);
    // wait 15 ms for servo to reach the position
    delay(15); // Wait for 15 millisecond(s)
  }
  for (pos = 180; pos >= 0; pos -= 1) {
    // tell servo to go to position in variable 'pos'
    servo_9.write(pos);
    // wait 15 ms for servo to reach the position
    delay(15); // Wait for 15 millisecond(s)
  }
}

Leave a Reply

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