Servo Motor Interfacing With Arduino Board
Servo motor interfacing is used frequently because it is an electromechanical device that produces torque and velocity based on the supplied current and voltage. In the market several types of servo motors are available but in this interfacing, we will use TowerPro SG90 Servo Motor which works on 5v and rotate 0 to 180 degree. All other specifications of the motor will discuss further in this article.
Components Required:
- One TowerPro SG90 Servo Motor
- An Arduino UNO board
- Jumper wires
Circuit Diagram:
Steps To Connect Servo Motor To Arduino:
- The servo motor has a female connector with three pins. The darkest or even black one is usually the ground. Connect this to the Arduino GND.
- Connect the power cable that in all standards should be red to 5V on the Arduino.
- Connect the remaining line on the servo connector to a digital pin on the Arduino.
S.NO | FEATURES | VALUES |
---|---|---|
1 | Operating Voltage | +5V |
2 | Rotation | 0 to 180 degree |
3 | Torque | 2.5kg/cm |
4 | Gear Type | Plastic |
5 | Operating speed | 0.1s/60° |
6 | Weight | 9gm |
Steps To Follow:
- Open Arduino IDE.
- Click on File.
- Go to New. – A new File will open
- Remove the Pre-Written code.
- Paste the code given below
- Check whether your UNO has been detected by the ID by going to Tools.
- Click on Port – Select the COM-Port on which Arduino UNO is detected.
Code
#include <Servo.h> int servoPin = 9; Servo servo; int angle = 0; // servo position in degrees void setup() { servo.attach(servoPin); } void loop() { // scan from 0 to 180 degrees for(angle = 0; angle < 180; angle++) { servo.write(angle); delay(15); } // now scan back from 180 to 0 degrees for(angle = 180; angle > 0; angle--) { servo.write(angle); delay(15); } }