Integration With Actuators
Integration With Actuators
Integration With Actuators
So, we will now in this lecture we will now move on to integration of a motor based
actuator.
So, over here I have got a small servo motor. So, this one particularly is use for
controlling the wings and tail adders of remote control planes or RC planes see. So, this
is just a there is a geared mechanism inside. I do not know whether it is visible or not.
So, there is a motor and you when you send pulses of various widths, the motor rotates to
just that bit. So, there are various gears inside ok.
So in this lecture we will learn how to integrate this motors and make it perform
according to our requirements. So, here we are going to cover the following topics,
introduction to actuators, servo motors and interfacing of this servo motor with arduino.
So, will first deal with hardware interface and then the actual sketch we are going to
which you are going to upload on the hardware.
So, actuators are basically mechanical or electro mechanical devices. They convert
energy or signals into motion. And mainly use to provide controlled motion to other
components of various mechanical structures or devices.
So, basic working principle is, in the servo motor you have various mechanical structures
like gears and screws and ball bearings, which are interfaced with a small motor over
here, and this produces very control motion, but is able to perform much more efficiently
then this motor alone would have been able to. So, like generally for servers the top
requirements are high as compared to normal dc motors. So, this is what is known as
micro servo in the market. So, while purchasing you look for micro servo motors there
are servo motors of various ranges and sizes. So, this one is this can be directly
integrated with our arduino board without much interfacing or external circuitry.
So we have various types of motor based actuators. Actually servo motor is just one of
them. You have servo motors, stepper motors, hydraulic motors, solenoid relays AC
motors. One point to note here is solenoid and relays are not actually motor based
actuators, but sometimes solenoid may be used to drive motors and relays may be used to
integrate various multiple motors with any kind of programmable circuit. So, relay is
something like a electro mechanical switch, where as solenoid works on the principle of
magnetism. Whenever you pass there is a coil there is a coil surrounding an iron coal
whenever you pass current through the coil the whole set of magnetizes, you can use it as
a magnet.
So, various uses of solenoid and solenoid walls for controlling water in pipes electronic
locks and so on. So, we will focus only on the servo motor part. So, it is a high precision
motor and it is able to provide a rotary motion between 0 and 180 degrees. And as you
have seen it has got 3 wires one black, one red and one yellow. So, many a times you
may have you may see that the black wire may be replace with brown ones also. So, the
motor I have got does not have a black wire, but it has got a brown wire, but nothing to
worry about this darkest wire is actually kept for browned. Then red one is for the power
supply I am actually going to provide 5 volt power supply from the arduino board and
the yellow one is the signal pin which is going to provide the signal for control motion to
the motor, not from the motor to the device it is going to provide signals from the board
to the motor.
So, yet again we have to install a special library. So, following the process we follow
during the DHT library installation. Just have to update a library.
If not already updated to include the servo library. And within the sketch we have to
create instance called servo, Servo myservo for enabling this use of this particular servo.
So, before moving any further let us just take a look in the library. Will just search for
servo over in the library manager as you can see there are many options for servos, but I
have just choosing the adafruit PWM servo driver library. So, it is already installed.
So, nothing else to worry about and one more thing, when you install a new library you
can see whatever examples you had package with the normal ID when you first
downloaded it. So, whatever library is you install you get some sample demo programs.
So, for this adafruit PWM servo driver library. We have something called a PWM test
and we are something called servo. So, we click on it a new sketch will appear. So, this
is a what we called company provided sketch, just you check whether your code is
working whether your hardware is working fine or not whether there is any problem with
your board or whether there is any problem with your motor or other such things.
So it is a pretty big code. We actually will be doing something very simple not this
complicated, so will take a look at the code. Now again we include the servo.h library
function library file. So, once this has been included here we are choosing a servo pin as
the pin number 12 on the at mega board. Then instance of a we create a instance of the
servo as servo demo then within the setup we write servodemo.attach. These are some of
the functions associated with servodemo. So, within attach it would expect the pin
number to which the servo is being attached, the pin number of the processor board your
using, or the arduino board you are using.
So once this setup is done we move on to the looping function. So, you have servodemo
the instance of the servo servodemo.write if we write 0 it will move 0 degrees it
reposition itself to 0 degrees then we put a delay for thousand milliseconds or one second
then we again write value as 90 to move the servo 90 degrees again a delay of 1 second
again after this we try to move the servo to 180 degrees. So, if you recall in the previous
slides I have said the servo, the servo is able to move between 0 and 180 degree. So, this
is the code out line.
So, we have already covered these what will go through it. Create an instance of the
servo the instance should be attached to the pin before it can be used in the code then;
that means, within setup you write that Servoinstance.attach and the pin number. If you
just call that Servoinstance.write it will not function you have to actually attach the servo
with the coding part. Then the write function takes the degree values and rotates the
motor accordingly.
A connection is pretty simple, connect the ground of the servo that is the dark wire to the
ground on the arduino board we connect the power supply wire that is generally the red
wire to the 5 volt pin on the board and signal wire to anyone of the pins we may used pin
8 or pin 12 or any kind of digital input output pins.
Now, try to using the board we connect the board to the PC we set the port number and
the board type we verify and then upload the code.
So, the code we just discuss few slides back it will give you an output of first will turn 0
degree. It will a line itself to 0 degree then it will wait for 1 second then will go to 90
degrees, then wait for one second and finally, it will go to 180 degrees and this thing will
keep on looping over and over again.
So, we will see a few variations of this code. So, there are lot more functions with the
servo library we have we have a knob function, we have a sweep function write
microseconds read attached detach and so on.
So, now, focusing back to the IDE. So, the code we discuss just now is already open. So,
we have set the servo pin as pin 8. Or may be any one of the pins we can set let us say,
we set it to pin 12 or pin 10, right. Now before we do anything will connect the servo.
So, we connect the ground wire brown or black wire to the ground pin on the board.
Then we connect the Vcc to the power supply pin on the board. And finally, will use a
wire of another color yes. So, finally, we attach the signal the yellow wire. So, we are
about to set it to pin 10, so will attach it to pin number 10. So, that is it, so this is the
connection of the servo. We attached the board to the PC.
Now we check, our processor is at mega 2560, always verify. We have various variations
of at mega board as you can see on the board over here. This is arduino mega 2560 if is
zoom in on this region. This is at mega 2560 it is always better to be careful.
So, you see there are 2 variations at mega 2560 and at mega 1280. So, we are selected
2560 the port has been selected we verify our code. So, this seems to be no error in the
code now we upload our code. Now if you focus on the motor I will reset it will first
align itself to 0 then 90 then 180. Now we can try different variations of this code just
take out the output signal pin. So, suppose the ID instead of 90 and 180 we give 45, 45
and 45.