Project showcase

# Driving a Servo Motor

Long time no see!

• 14 views
• 0 respects

## Components and supplies

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

## Apps and online services

 Arduino IDE

Today I will look at the Driving a Servo Motor.

Introduction

This experiment is your introduction to the servo motor, which is a smart motor that you cantell to rotate to a specific angular location. You will program it to rotate to a series oflocations, then sweep across its full range of motion, and then repeat.

### HOW

First, prepare the servo. Then find the wires and connect them to the appropriate places.

Let's turn on the servo.

Did you succeed? Do you see the servo turn?

### Review

The sound of the motor buzzing was really good and my challenge was successful today. I would like to apply this in the future.

## Code

##### Driving a Servo MotorArduino
```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);
}
}
```