Simple Servo
This code example sets the servomotor to one of three positions. Servo can be attached to any digital pin.
Power and ground pins on servo should be connected to breadboard power/ground bus. Light-colored wire is the signal line.
Servo Library
This library allows an Arduino board to control RC (hobby) servo motors. Servos have integrated gears and a shaft that can be precisely controlled. Standard servos allow the shaft to be positioned at various angles, usually between 0 and 180 degrees. Continuous rotation servos allow the rotation of the shaft to be set to various speeds.
The Servo library supports up to 12 motors on most Arduino boards and 48 on the Arduino Mega. On boards other than the Mega, use of the library disables analogWrite() (PWM) functionality on pins 9 and 10, whether or not there is a Servo on those pins.
See https://www.arduino.cc/en/reference/servo for more information.
Power and ground pins on servo should be connected to breadboard power/ground bus. Light-colored wire is the signal line.
Servo Library
This library allows an Arduino board to control RC (hobby) servo motors. Servos have integrated gears and a shaft that can be precisely controlled. Standard servos allow the shaft to be positioned at various angles, usually between 0 and 180 degrees. Continuous rotation servos allow the rotation of the shaft to be set to various speeds.
The Servo library supports up to 12 motors on most Arduino boards and 48 on the Arduino Mega. On boards other than the Mega, use of the library disables analogWrite() (PWM) functionality on pins 9 and 10, whether or not there is a Servo on those pins.
See https://www.arduino.cc/en/reference/servo for more information.
#include <Servo.h>
Servo myservo; // create servo object to control a servo
void setup() {
myservo.attach(4); // attaches the servo on pin 4 to the servo object
}
void loop() {
myservo.write(0); // sets the servo position to 0
delay(500); // waits for the servo to get there
myservo.write(90); // sets the servo position to middle
delay(500); // waits for the servo to get there
myservo.write(180); // sets the servo position to end
delay(500); // waits for the servo to get there
}
Servo myservo; // create servo object to control a servo
void setup() {
myservo.attach(4); // attaches the servo on pin 4 to the servo object
}
void loop() {
myservo.write(0); // sets the servo position to 0
delay(500); // waits for the servo to get there
myservo.write(90); // sets the servo position to middle
delay(500); // waits for the servo to get there
myservo.write(180); // sets the servo position to end
delay(500); // waits for the servo to get there
}