Learn interfacing servo motor with Arduino

Learn interfacing servo motor with Arduino. Servo motors have a great feature as they can turn to the desired position. Usually servo motor can turn to 180 degrees, but using Arduino they can be rotated to the desired position. They are generally used in the steering wheel for RC car. Here we are going to see the basic working of the servo motor. So, let’s start.

Step 1: Required Components

Servo motor x 1
Arduino UNO x 1
Jumper Wires

Step 2: Circuit Time

Servo motors have three pins, power(+5), ground, and a signal pin. Connect power pin of the servo motor to +5v pin of Arduino. Now, connect ground pin to GND of Arduino. Then, connect signal pin of the servo with digital pin 8 of Arduino. Servo motors consume a considerable amount of power, so while connecting multiple servos uses enough power.

Step 3: Code Time

This is code for interfacing servo motor with Arduino. Main elements of code for servo motors are, attach(), write() and map(). First, we have created an object of Servo and initialize the position of the servo to 0. In setup, we have used attach() to connect servo pin to digital pin 8 of Arduino. The servo can move to the desired degree by using write() method. You can use a servo.write(x), where x is specified degree.

Step 4: Upload the code to Arduino

Upload the above-given code to Arduino to rotate servo motor. Our code will rotate the servo motor to 90 degrees.

For information about uploading code to Arduino UNO Click Here.

Leave a Reply