Experiment
Experiment
Servo Motor
A servo motor is a device that can rotate to a specific angle using a feedback system. It consists of a
motor, a control circuit, and a feedback mechanism . The motor moves to the required position when
given a signal, and the feedback system makes sure it stays there accurately.
Working Principle
When a control signal tells the servo to move to a certain angle, the motor turns. The feedback
mechanism checks the angle and tells the control circuit if there’s any error. The circuit then corrects
the position if needed, ensuring precise movement. This process is called closed-loop control.
Servomechanism
Applications
Aim
To control the position, speed, and direction of a servo motor using an Arduino microcontroller.
Apparatus Required
i. Arduino board
ii. Servo motor
iii. Connecting wires
iv. USB cable
v. Computer with Arduino IDE installed
Experimental Procedure
i. Connect the red wire of the servo motor to the 5V pin on the Arduino to supply power.
ii. Connect the ground wire of the servo motor to the GND pin on the Arduino to complete the
circuit.
iii. Connect the servo motor's control wire (signal) to pin 9 on the Arduino for signal transmission.
iv. In the Arduino IDE, include the Servo library by using #include <Servo.h> to facilitate servo
motor control.
v. Declare and attach the servo object to pin 9 to establish communication between the servo and
Arduino.
vi. Program Position Control: Write code to move the servo from 0 degrees to 180 degrees,
specifying precise positions for accurate control.
vii. Control Speed: Use delays between position increments in the code to adjust the speed of the
servo movement. A longer delay slows the movement, while a shorter delay speeds it up.
viii. Direction Control: Define the sequence in which the servo moves. Start from 0 degrees and
incrementally move to 180 degrees, then reverse the direction back to 0 degrees.
ix. Compile the program and upload it to the Arduino board using the Arduino IDE.
Result
The position, speed, and direction control of a servo motor using an Arduino microcontroller.
Code
#include <Servo.h>
Servo myservo; // create servo object to control a servo
int pos = 0; // variable to store the servo position
void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
void loop()
{
for (pos = 0; pos <= 180; pos += 1) // goes from 0 degrees to 180 degrees in steps of 1 degree
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for (pos = 180; pos >= 0; pos − = 1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}
Servo Motor – Position, Speed and Direction Control