Servo is a special type of motor which converts electric signals in to shaft positions.
Servos can be broadly classified as Industrial servos and Hobby grade servos.
Industrial servos are generally heavy duty high power AC or DC servos widely used for precise robotic arms.
Hobby grade servos are widely used in RC Hobbies like RC Plane, Cars Helicopters, Multirotors, Boats, hover craft, etc.
They are mostly used to control the control surfaces (RC Planes) or for thrust vectoring mechanisms (hovercraft, boats, multirotors) or for steering mechanisms (RC Cars).
Hobby grade servos are further classified as micro, standard, giant based on the torque they can provide, however their working principal is just the same.Based on speed of operation they are classified as Analog or Digital servos, Digital servos provide greater speed but consume more power.
Speed of a servo motor is defined as time taken for shaft to move from 00 to 600 after the application of signal.
In this article we will be using an ARDUINO clone board viz. FREEDUINO.
The freeduino board used is based on arduino duemilanove board and uses atmega 328PA Microcontroller IC.
Most salient feature of an arduino platform is its ease of use, since arduino was designed for artists instead of engineers it becomes more interesting and fun to learn arduino programming and make projects based on it.
Freeduino Board:
Description
Description:
Servo is most widely used actuator in project like robotic arms, RC plane, self balancer, etc.
It uses a negative feedback mechanism to maintain its shaft position with minimum error.
The servo motor has three wires unlike normal PMDC motors which have two wires.
Among those 3 wires, 2 wires provide power supply to the motor and one is used to send signals to the motor for required shaft positions.
These signals are PWM signal of varying duty cycle and frequency of 40-50HZ (analog servos) or 400-500Hz (digital servos).
Analog servos are cheaper and consume less power and Digital servos provide relatively high torque and speed and are normally used as Helicopter Tail servo.
Shaft is rotated by an angle depending on the ON-Time of the pulse.
1ms = 00
1.5ms= 900
2ms= 1800
Input (ADC):
Arduino has a inbuilt 10-bit Analog to Digital converter(ADC), hence it can provide Digital values from 0-1023.(since 2^10=1024)
We can also set the ADC reference voltage in arduino, but here we’ll let it use default value.
Variable resistor (preset or potentiometer) has three pins; outer two pins are connected to ground and Vcc.
This forms a potential divider and we get the voltage (Vout) corresponding to the knob of resistor.
As we rotate the knob of variable resistor the voltage at middle pin goes from 0-5V and ADC of arduino converts it into 1024 values i.e. 0-1023 digital values.
Now we will be using these 1024 values to control our servo motor.
Output (PWM):
To drive a servo we need to get a PWM signal from the board, this is usually accomplished using timer function of the microcontroller but arduino makes it very easy.
Arduino provides a servo library in which we have to only assign servo angle and the servo rotates by that angle, all the PWM calculations are handled by the servo library and we get a neat PWM signal according to the desired angle.
Arduino has a 8-bit PWM generator, so we can get up to 256 distinct PWM signal
We need 0-180 degrees of servo rotation.
Now since we are getting 1024 values from ADC which we have to use to rotate servo shaft by 0-180 degrees, we will use a function called mapping to map these 1024 distinct values to 180 values.
Map function has a syntax: map(mapping_values,(range of values),(range in to which it has to be mapped)
Example: In our case the map function will look like angle=map(pot_value,0,1023,0,180);
if you want to change the direction of servo angle with respect to potentiometer knob, change the wiring or write mapping function as, angle=map(pot_values,0,1023,180,0);
Now, as we change the variable resistor the voltage at ADC input will go from 0 to 5V(analog), 0-1023(digital) and then it’ll be mapped to 0-180(servo angle).
Potentiometer is a simplest device to understand analog device functioning, after getting well acquainted with it we can use other analog devices like LDR, infrared distance sensors, temperature sensors, accelerometers as our input device and make other cool projects like self balancing robot, line follower, obstacle avoider, solar tracker, etc.
Components and Circuit
Components:
Freeduino board (Atmega 328)
Features:
Microcontroller |
ATmega328 |
Operating Voltage |
5V |
Input Voltage (recommended) |
7-12V |
Input Voltage (limits) |
6-20V |
Digital I/O Pins |
14 (of which 6 provide PWM output) |
Analog Input Pins |
6 |
DC Current per I/O Pin |
40 mA |
DC Current for 3.3V Pin |
50 mA |
Flash Memory |
32 KB (ATmega328) of which 0.5 KB used by bootloader |
SRAM |
2 KB (ATmega328) |
EEPROM |
1 KB (ATmega328) |
Clock Speed |
16 MHz |
Servo: Tower pro 9G Micro-servo.
Potentiometer: 10K variable resistor (preset or pot)
CIRCUIT
Images
IMAGES:
Breadboard with variable resistor
Breadboard and servo motor
Arduino based Circuit
Video
You may also like:
Project Source Code
###
#include
//include servo library to control servos
Servo sajidservo; //define your servo
int pot=0; //potentiometer connected at pin no 0 of ADC
void setup()
{
sajidservo.attach(9); //attach your servo to a PWM pin(here pin no.9)
Serial.begin(9600); //exclude this if you don't want to see ADC values on serial monitor
}
void loop()
{
int val=analogRead(pot); // Read values from ADC and save it in variable val
int pos=map(val,0,1023,0,180); // map the range of ADC with pwm
sajidservo.write(pos); // write to the servo
Serial.println(val); //exclude if don't want to see ADC values
}
###
Filed Under: Electronic Projects
Questions related to this article?
👉Ask and discuss on EDAboard.com and Electro-Tech-Online.com forums.
Tell Us What You Think!!
You must be logged in to post a comment.