Arduino Uno Quick Start Manual page 243

Hide thumbs Also See for Arduino Uno:
Table of Contents

Advertisement

Here s a picture of a servo motor connected to an Arduino using wires. You
can also use pin headers, but wires give you more flexibility.
Controlling servo motors is convenient, because you can set the motor s shaft
to an angle between 0 and 180. With the following sketch, you can send a
degree value via the serial port and move the servo motor accordingly:
Motors/SerialServo/SerialServo.ino
#include <Servo.h>
Line 1
-
const unsigned int
-
const unsigned int
-
const unsigned int
5
const unsigned int
-
-
Servo servo;
-
-
void
setup() {
10
Serial.begin(BAUD_RATE);
-
servo.attach(MOTOR_PIN);
-
delay(MOTOR_DELAY);
-
servo.write(1);
-
delay(MOTOR_DELAY);
15
}
-
-
Chapter 13. Controlling Motors with Arduino
MOTOR_PIN = 9;
MOTOR_DELAY = 15;
SERIAL_DELAY = 5;
BAUD_RATE = 9600;
www.it-ebooks.info
228
report erratum
discuss

Hide quick links:

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the Arduino Uno and is the answer not in the manual?

Subscribe to Our Youtube Channel

Table of Contents