# Lesson 6: Servo Motors

### Introduction

There are two types of servo motors:

1. Servo motors that rotate from 0 to 180 degrees
2. Continuous rotation servo motors

Regular servo motors will take an input and translate it to an angular position of the output shaft. That angular position will be between 0 and 180 degrees.

A continuous rotation servo is just a regular servo, but rotates continuously over the full 360 degree range. It is ideal as a direct drive motor for a small rover.

Regular servos have a midpoint of 90 degrees, with a 180 degree total sweep range.
This means that a regular servo can rotate clockwise and counter-clockwise by 90 degrees each way from its midpoint

A continuous rotation servo is simply a servo that will continuously rotate across the full 360 degrees. A “midpoint” value of 90 degrees is used to stop the rotation.

Each continuous rotation servo must be calibrated to that 90 degree midpoint. A small calibration potentiometer on the continuous rotation servo can be rotated to adjust for the “drift” of the 90 degree midpoint value.

### The Code

`#include <Servo.h>  // Define the servo motors for the rover Servo rightServo; Servo leftServo;  void setup() {   // Attach each servo to the pins we are using on the Arduino   rightServo.attach(3);  // pin 3 for the right servo   leftServo.attach(4);   // pin 4 for the left servo }  void loop() {   rightServo.write(90);   leftServo.write(90); }`

Note that if you have two servos, right & left, one servo will be turning clockwise, the other will be turning counter-clockwise to obtain forward driven motion.

A value of 90 is stop. A value above 90 will turn clockwise. A value below 90 will turn counter-clockwise. The maximum value depends on the servo, but it is typically +/- 8 from the 90 midpoint. You will just need to experiment with your servo.

Brown cable is Ground (GND)

Red cable is +5V

Orange cable is Signal

Black cable is Ground (GND)

Red cable is +5V

White cable is Signal