connect servo to arduino
// Include the Servo library #include// Declare the Servo pin int servoPin = 3; // Create a servo object Servo Servo1; void setup() { // We need to attach the servo to the used pin number Servo1.attach(servoPin); } void loop(){ // Make servo go to 0 degrees Servo1.write(0); delay(1000); // Make servo go to 90 degrees Servo1.write(90); delay(1000); // Make servo go to 180 degrees Servo1.write(180); delay(1000); }
Here is what the above code is Doing:
1. We include the Servo library.
2. We declare the servo pin.
3. We create a servo object.
4. We attach the servo to the used pin number.
5. We make the servo go to 0 degrees.
6. We make the servo go to 90 degrees.
7. We make the servo go to 180 degrees.