My name is Ahmad Shamshiri and I am presenting this tutorial from Canada.
Hi welcome to another video from Robojax. In this video I'm going to explain
What a servo is and how you can use a servo and Arduino for robotics purposes.
So as you can see here, we have a small server. There are different type of servo the servo has
Three wires needs power as you can see here. The middle one is red
And then this is a darker one brown or sometimes you will see this black. This is the negative
this is the 5 volts the red one and
this orange is the signal. These two sends a voltage to give them power and
Through this one you are sending a pulse width modulation PWM
to control the
Angle of a servo or what a servo is
It has a motor inside
It the servo motor and this rotates about 180 degrees
So it rotates 180 degrees by
controlling the motion of this you can open-close something or move or
Arm of a robot or something
It's usually the servos will come with different arms that can be attached to it. For example
You can attach some
if you need to control to part of something you can connect a
String or a rod here through these holes or here and or maybe I'll just add different values
Different lengths from the center. So this is called the radius
And this will be attached
And then this can be installed somewhere
As you can see, I'm moving it with hands if you just remember this point now
It just goes 180 degrees. so it can come back but it doesn't go full rotation or
If you just need half of it
If you just need if you don't need the other side you can just
Use this one, but the servo is very useful for a lot of application in robotics
Let's get started and run it practically
Control Servo with potentiometer (variable resistor)
In the third world the default server project which is with India
so click on file ->examples and then
Depending on your application. So if somewhere at the bottom, you should see servo and servo has two built-in knob and sweep
So we wish we go through both. Let's go to the knob
And
Here this is a project and quick explanation it needs a
Servo library. Header that's included you don't worry about it because all Arduoino application comes with it
And this is called the object
of the type servo is created and then pin zero or you can type a
A0 that is also referring to the pin
0 of your Arduino's analog pin.
so this is connected to the potentiometer
So what we do is we will rotate the potentiometer
And then we control the servo. Servo will rotate as
as we rotate the potentiometer
I've connected the 5 volts to this 5 volt of
Breadboard, so I have 5 volts everywhere and then I have connected a ground GND to the ground
So the 5 volts and ground are available here
So this has done the first force and then the servo
The server has 3 pin. So the brown one on this side is connected to the negative
This side is a negative and then the middle one, which is I connected to the red to the 5 volts
so the server is getting
This 5 volts this is done now but the server will not function until it receives
the pulse width modulation PWM signal here and
The pulse width modulation signal is coming from pin 9 and the pin 9 is here. It says on the
Application if you see it here this is if the 9
Which is coming to the servo and then here this reads the pin out
Which is pin 9 so it reads analog the value
The value of from 0 to 1023
so that's the value of this function is called map , which maps the value of 0 to
1023 of the value will be mapped between 0 to 180 and
Then we have a new value and the new value will be written to the servo.
The new value and we have 15 millisecond delay here. Let me upload the
Sketch to my board as you can see now, this is blinking
It was original blank now TX Rx is running so the code has been uploaded but the server is not
Doing anything and this side is connected 1 is to 5 volt
the other one is to 0 so here the gray is 5 volts and the black on this side is
At the 0 and the middle one. I've connected it to analog 0 or A0
that is connected
Let me connect the servo here
Now this is the servo and now I'm rotating it
See when I rotate this
the servo also rotate this was just a testing of how the servo works, or maybe if you have some
Steering wheel or something that you can connect or something that you can control with
potentiometers. Now let me just run as I rotate this to the left and right and controlling it with a
180 degrees, okay
If this is zero
then you have your 180 would be here and now I'm rotating it to the left as you can see it goes to
And here this is not 180 because this potentiometer is not going at full zero or full maximum value
If you want to get that angle and do something for a specific angle
for some
Specific reading or calculation you want to move it to a specific angle. You can do this as well
So, let me just remove this from potentiometer and let's just put the servo for the values
I'm removing this now
Just comment this
We can directly send here a value without a potentiometer. So I'm removing the potentiometer now and
Let's say we want to put it at zero
So zero, let's upload it. So that is the zero now, let me just hold this and
Make it 180
And run the code so it should come on this side
So that is 180 but if I make it 90 degrees, it should be somewhere here
That is how you control this one based on different
For example, you can have a sensor you can have ultrasonic sensors. You can have temperature meter or something in a combustion chamber
Chamber that you can control the flow of air or chemical
So this can be used pretty good with controlling the servo to open or close or move some
Arm or something
Controlling Servo with values
This project is called sweep. So you go file->examples and scroll down
Servo and then you will get a sweep. open the Sweep.
I've already opened. That is a Sweep
but the servo is now connected the same way as before to the pin 9 here and this is a for loop which goes
between the position initially which is from 0 to
180 degrees and this is increasing this plus you can see here
So it goes remember 0 was here it goes to 0 to 180 degree. Ok, so this is going for 1
One step (one degree) at a time. And then this one goes from position 0
but it starts at
180 and this is being
subtracted so once it moves here
then it goes from
180 slowly one degree down and every time it goes
For 15 millisecond delay, so let me upload it
So start from zero to 180 and from 180 to zero
This is very precise because we are going one degree here. if you if you pay attention this is
one degree
And also this is one degree. So this increases one degree. Let me just change that
let's say you want to make a 10 degrees and
10 degrees decrease, let me upload it again
Now we will see it'll jump
To make it a little interesting let me have
100 millisecond 100 millisecond means one tenth of a second so let's upload the code
Let's make it 30 degrees
By making it 300 milliseconds
So you can hear it go fully 180 degrees I
Put the pen you will see
Okay, this was the brief introduction for using the servo with arduino.
if you like this this video, please thumb up 👍 and also all the codes for this project and all other projects are available at
www.robojax.com/learn/arduino or click on the link
which is in the description of this video. Thank you