
Potentiometer pin 2 – Analog In (A0) pin Arduino.Potentiometer pin 3 - Ground pin Arduino.Hardware RequiredĬonnect the circuit as show in the figure below: The Arduino will read the voltage on the middle pin of the potentiometer and adjust the position of the servo motor shaft. This experiment is essentially the same as Experiment 1, except that we have added a potentiometer for position control. Servo_test.write(angle) //command to rotate the servo to the specified angle Servo_test.attach(9) // attach the signal pin of servo to pin9 of arduinoįor(angle = 0 angle =1 angle-=5) // command to move from 180 degrees to 0 degrees Servo servo_test //initialize a servo object for the connected servo

When the motor has rotated 180 degrees, it will begin to rotate in the other direction until it returns to the home position. When the program starts running, the servo motor will rotate slowly from 0 degrees to 180 degrees, one degree at a time. Connect to the motor to the Arduino as shown in the table below:Ĭaution: Do not try to rotate the servo motor by hand, as you may damage the motor. The best thing about a servo motor is that it can be connected directly to an Arduino. The PWM input will be connected to one of the Arduino's digital output pins. In this experiment, we will connect the power and ground pins directly to the Arduino 5V and GND pins. Most servo motors have the following three connections: Servo motors are small in size, and because they have built-in circuitry to control their movement, they can be connected directly to an Arduino. As a result, servo motors are used to control the position of objects, rotate objects, move legs, arms or hands of robots, move sensors etc.

You can connect small servo motors directly to an Arduino to control the shaft position very precisely.īecause servo motors use feedback to determine the position of the shaft, you can control that position very precisely.
