park-jiyungledel
Created May 8, 2018

Driving a Servo Motor

Long time no see!

BeginnerShowcase (no instructions)30 minutes89
Driving a Servo Motor

Things used in this project

Hardware components

Breadboard (generic)
Breadboard (generic)
×1
Arduino 101
Arduino 101
×1
Servos (Tower Pro MG996R)
×1
Jumper wires (generic)
Jumper wires (generic)
×3

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Driving a Servo Motor

Code

Driving a Servo Motor

Arduino
void loop()
{
//create a local variable to store the servos position.
int position;
// To control a servo, you give it the angle you'd like it
// to turn to. Servos cannot turn a full 360 degrees, but you
// can tell it to move anywhere between 0 and 180 degrees.
// Change position at full speed:
// Tell servo to go to 90 degrees
servo1.write(90);
// Pause to get it time to move
delay(1000);
// Tell servo to go to 180 degrees
servo1.write(180);
// Pause to get it time to move
delay(1000);
// Tell servo to go to 0 degrees
servo1.write(0);
// Pause to get it time to move
delay(1000);
// Tell servo to go to 180 degrees, stepping by two degrees
for (position = 0; position < 180; position += 2)
Experiment 10: Driving a Servo Motor
108
{
// Move to next position
servo1.write(position);
// Short pause to allow it to move
delay(20);
}
// Tell servo to go to 0 degrees, stepping by one degree
for (position = 180; position >= 0; position -= 1)
{
// Move to next position
servo1.write(position);
// Short pause to allow it to move
delay(20);
}
}

Credits

park-jiyun
4 projects • 2 followers
I am a high school student studying hard.
Contact
gledel
100 projects • 116 followers
Looking back on my childhood, I was happy when I was making something and I was proud of myself. "Making is instinct!"
Contact

Comments

Please log in or sign up to comment.