A servo motor is a rotary actuator or linear actuator that allows for precise control of angular or linear position, velocity, and acceleration. It consists of a suitable motor coupled to a sensor for position feedback. Servo motors are widely used in robotics, radio-controlled cars, airplanes, and boats, as well as in industrial applications, such as controlling the motion of robotic arms. The control signal is a digital PWM (Pulse Width Modulation) signal, which determines the position of the shaft of the servo motor.
Pin Name | Description |
---|---|
VCC | Power supply (4.8V to 6V) |
GND | Ground connection |
SIGNAL | PWM control signal input |
#include <Servo.h>
Servo myservo; // create servo object to control a servo
void setup() {
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
void loop() {
myservo.write(90); // sets the servo position to 90 degrees
delay(1000); // waits for the servo to reach the position
myservo.write(0); // sets the servo position to 0 degrees
delay(1000); // waits for the servo to reach the position
}
Q: Can I control a servo with a 3.3V microcontroller like an Arduino Due? A: Yes, but ensure that the servo can handle the 3.3V control signal. Some servos require a 5V signal.
Q: How can I control a servo with a higher voltage or current rating? A: Use an external power supply that matches the servo's requirements, and connect the ground of the power supply to the ground of the microcontroller.
Q: Can I control more than one servo with an Arduino? A: Yes, you can control multiple servos by using multiple PWM-capable pins and creating a Servo object for each one in your code.