Simple Servo Program for Arduino

Submitted by CAAadmin on Sun, 09/25/2016 - 12:26
Forums

Servo.h comes with Arduino as default. Just create an object (here servo1) and use it fr your servo.

Simple Servo Program for Arduino


#include <Servo.h>
// 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);
    Servo1.write(0);
   delay(1000);
}

 

example programs for Arduino

Servo control using arduino uno and arduino mega