Friday, 8 September 2017

Servo motor interface with arduino

                                             
                                Servo motors have been around for a long time and are utilized in many applications. They are small in size but pack a big punch and are very energy-efficient. These features allow them to be used to operate remote-controlled or radio-controlled toy cars, robots and airplanes. Servo motors are also used in industrial applications, robotics

                The servo circuitry is built right inside the motor unit and has a positionable shaft, which usually is fitted with a gear (as shown in fig). The motor is controlled with an electric signal which determines the amount of movement of the shaft. 

            Inside there is a pretty simple set-up: a small DC motor, potentio meter, and a control circuit. The motor is attached by gears to the control wheel. As the motor rotates, the potentio meter's resistance changes, so the control circuit can precisely regulate how much movement there is and in which direction. 

                When the shaft of the motor is at the desired position, power supplied to the motor is stopped. If not, the motor is turned in the appropriate direction. The desired position is sent via electrical pulses through the signal wire. The motor's direction is proportional to the difference between its actual position and desired position. 

           Servos are controlled by sending an electrical pulse of variable width, or pulse width modulation (PWM), through the control wire. There is a minimum pulse, a maximum pulse, and a repetition rate. A servo motor can usually only turn 90° in either direction for a total of 180° movement. The motor's neutral position is defined as the position where the servo has the same amount of potential rotation in the both the clockwise or counter-clockwise direction. The PWM sent to the motor determines position of the shaft, and based on the duration of the pulse sent via the control wire; the rotor will turn to the desired position. The servo motor expects to see a pulse every 20 milliseconds (ms) and the length of the pulse will determine how far the motor turns. For example, a 1.5ms pulse will make the motor turn to the 90° position. Shorter than 1.5ms moves it in the counter clockwise direction toward the 0° position, and any longer than 1.5ms will turn the servo in a clockwise direction toward the 180° position. 

Interfacing Servo with Arduino


Program

PROGRAMME
//                   http://electronicshobbycorner.blogspot.in
//                   Rajeev TR
//                   rajeev.emb402@gmail.com
// PROGRAM TO INTERFACE SERVO MOTOR WITH ARDUINO  


#include <Servo.h>
Servo myservo;                          // create servo object to control a servo

int potpin = 0;                        // analog pin used to connect the potentiometer  A0
int val;                               // variable to read the value from the analog pin

void setup() {
  myservo.attach(9);                   // attaches the servo on pin 9 to the servo object
}

void loop() 
{
  val = analogRead(potpin);            // reads the value of the potentiometer (value between 0 and 1023)
  val = map(val, 0, 1023, 0, 180);     // scale it to use it with the servo (value between 0 and 180)
  myservo.write(val);                  // sets the servo position according to the scaled value
  delay(15);                           // waits for the servo to get there
}
Click here to download code

No comments:

Post a Comment