0% found this document useful (0 votes)
83 views1 page

Include Servo

The document contains an Arduino sketch that controls a servo motor using the Servo library. It initializes the servo on pin 9, sweeps it from 0 to 180 degrees and back, and also moves it to 90 degrees before returning to 0 degrees. The code includes delays to allow the servo to reach each position smoothly.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
83 views1 page

Include Servo

The document contains an Arduino sketch that controls a servo motor using the Servo library. It initializes the servo on pin 9, sweeps it from 0 to 180 degrees and back, and also moves it to 90 degrees before returning to 0 degrees. The code includes delays to allow the servo to reach each position smoothly.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

#include <Servo.

h>

Servo myservo; // Create a servo object

void setup() {
myservo.attach(9, 500, 2500); // Attach the servo to pin 9 with optional pulse
width limits
myservo.write(0); // Start at 0 degrees
delay(1000); // Wait for a second
}

void loop() {
// Sweep the servo from 0 to 180 degrees
for (int pos = 0; pos <= 180; pos++) {
myservo.write(pos); // Move to position
delay(15); // Wait for 15 milliseconds
}

// Sweep the servo back from 180 to 0 degrees


for (int pos = 180; pos >= 0; pos--) {
myservo.write(pos); // Move to position
delay(15); // Wait for 15 milliseconds
}

// Move servo between 0 and 90 degrees


myservo.write(90); // Go to 90 degrees
delay(1000); // Wait for a second

myservo.write(0); // Back to 0 degrees


delay(1000); // Wait for a second
}

You might also like