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 the RC car. Here we are going to see the basic working of the servo motor. So, let’s start.
Step 1: Required Components
Step 2: Circuit Time
Servo motors have three pins, power(+5), ground, and a signal pin. Connect the power pin of the servo motor to the +5v pin of Arduino. Now, connect the ground pin to the GND of Arduino. Then, connect the 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 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 the write() method. You can use a servo.write(x), where x is the specified degree.
Step 4: Upload the code to Arduino
Upload the above-given code to Arduino to rotate the servo motor. Our code will rotate the servo motor to 90 degrees.
Learn information about uploading code to Arduino Uno Board.