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:
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:
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:
|Function||Return data type||Comment|
|attach(int pin);||unit8_t||Attach 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_t||As above but also sets min and max values for writes|
|write(int value);||void||If value is|
|writeMicroseconds(int value);||void||Write pulse width in microseconds|
|read();||Integer||Returns current pulse width as an angle between 0 and 180 degrees|
|readMicroseconds();||Integer||Returns current pulse width in microseconds for this servo (was read_us() in first release)|
|attached();||bool||Return true if this servo is attached, otherwise false|
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.