How to interface Servo Motor with Arduino IDE

About This Tutorial
This tutorial discusses what are servo motors, how to control them, and how to interface them with Arduino IDE using motor control units in evive with the help of an Arduino IDE sketch.
Tutorial Info
Programming Platform:
Difficulty:
Estimated Time (hrs):
2

Components Required

ImageComponentQuantityAvailable in Kit
evive1
Micro Servo Motor with Accessories1
USB A-B Cable1

Introduction

A servo motor is a rotary actuator that rotates with angular precision.There are different types of servos available namely: positional rotation, continuous rotation, and linear. Here you will be using positional rotation servo. It is used to achieve proper angular positions for objects connected to it.  Servo motors are used widely in projects related to robotics.  

 If pull apart a servo motor, you find the following inside it:

  • A DC Motor
  • A Potentiometer
  • A gear train, i.e. a series of gears that are connected such that their teeth are engaged/interconnected. (A gear can be visualised as wheel with teeth, not the regular teeth though; sometimes more and sometimes less than 32!)
  • A control circuit: This circuit is the actual brain behind the precise working of the servo. It controls how much the servo should move or rotate depending upon the input it receives.

evive has two dedicated servo motor outputs pins, as shown below:

evive servo output channel

 

How to control the Servo Angle

A positional servo mainly consists of three pins: Gnd,Vcc and Signal pin. Its shaft rotates from 0 to 180 degree, 0° being its neutral position.The signal pin on servo should  be given a pulse in every 20ms (milliseconds) to move it to specific angular degree from its neutral position. The width of pulse applied decides the amount of angular rotation servo performs. This pulse is given from PWM pins of the controller.

Signal pin of servo 1 is connected to digital pin 44 and servo 2 is connected to digital pin 45 in evive. Slots S1 and S2 shown in above images are for servo 1 and servo 2 respectively.

Connecting servo to evive

For interfacing the servo motor with Arduino IDE, you must first connect the motor to one of evive’s servo channels as shown in the figure below:

 
evive Alert
While connecting the servo to evive’s servo channel, make sure that brown wire goes to the left-most pin.

Controlling servo using servo library

There is a servo library which can be used to control the servo motor. The available functions are given in the table below:

FunctionReturn data typeComment
attach(int pin);unit8_tAttach the given pin to the next free channel, sets pinMode, returns channel number or 0 if failure
attach(int pin, int min, int max);unit8_tAs above but also sets min and max values for writes
detach();void
write(int value);voidIf value is
writeMicroseconds(int value);voidWrite pulse width in microseconds
read();IntegerReturns current pulse width as an angle between 0 and 180 degrees
readMicroseconds();IntegerReturns current pulse width in microseconds for this servo (was read_us() in first release)
attached();boolReturn true if this servo is attached, otherwise false

Example

Example 1: Servo is rotated from 0° to 180° and from 180° to 0°.

Example 2: You will control the servo motor using evive’s potentiometer.

This Helped
This didn't help
Share this Tutorial
Facebook
Twitter
Google+
Pinterest
Reddit
Print
Related Tutorials
Featured Projects

Leave a Reply

Close Menu
×

Cart