A Servo (Wokwi Compatible) is a type of rotary actuator that enables precise control over angular position. It integrates a motor with a position feedback sensor, typically through a gear system. This component is essential in various applications such as robotics, remote-controlled vehicles, and automated systems where precise movement and positioning are required.
Pin Number | Name | Description |
---|---|---|
1 | GND | Ground connection |
2 | VCC | Power supply (4.8V to 6V) |
3 | SIG | Control signal input (PWM) |
#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°
delay(1000); // Wait for 1 second
myservo.write(0); // Sets the servo position to 0°
delay(1000); // Wait for 1 second
}
Q: Can I control the servo with a constant voltage? A: No, servos require a PWM signal to set the position.
Q: What is the maximum angle my servo can rotate? A: Most servos have a range of 180 degrees, but it can vary by model. Check the datasheet for your specific servo.
Q: How can I reverse the direction of the servo? A: You can reverse the direction by swapping the pulse width values for the desired positions in your code.
Remember to always refer to the specific datasheet of the servo model you are using for the most accurate and detailed information.