hi welcome to another unit tutorial from Robojax. in this video we are
going to see how we can control a servo motor using a remote control on Arduino
I'm pressing the button to move the servo to the right or maybe move it to the left
or just press the center's you can get the code for this project by clicking
at the neck of the description below which will take you to robojax.com/learn/arduino
at the end I'm gonna show you to use your home remote to control the servo
video we're going to use these two commonly sold remote control with Arduino and this
receiver and also we are going to use this this module but this is the same one is with
the PCB the other ways without PCB to control the servo have separate video explaining these
remotes and the receiver and how to decode using Arduino so you have to watch that video and make
sure that you can get the value and display on the screen with your remote after that come to
this video because if I explain everything here the video would be very long going to
control the servo either with this white remote with a black limit or with a module with a PCB
or without the PCB there's a bear module and also at the end I'm going to show you to use
your home remote to control the servo that you can use this servo or larger server this micro
servo doesn't matter you can control all of them except with this one with a larger one if the
winner is unable to provide enough power for it so you have to connect it with the external power
let me explain the wiring the servo has three wires these are the three wires the dark one is
the ground the middle one is always the five volts or a power so you cannot make mistake
even if you flip it it will be always at the middle and then the lighter colors usually is
the signal and this is connected to the ground as you can see here and the light the red one
which is here the white connected to five volts and then the orange I've extended with
this wire this is a gray this is connected to pin 8 and I'll do you know but this module we
have three wires here we have ground which is connected to the ground we have the VCC
connected to five volts and then we have the signal connected to plane 11 as explained in
my original video now this module has been explained there that has negative on this
side this goes to the ground the middle one goes to to the five volts and s a signal which goes
to pin 11 if you use this module this is VCC this is ground and that's the signal and I will
connect it to this wire I've been the pencil for this so it can receive the signal easily
let me explain the code I'm not gonna go through line by line explaining this code because it
has been explained and required video that have provided you the link this is part of the library
which will be included this is the same as a main original video I'm not gonna talk about those and
from here to here this is for the servo this is the library for servo which is part of the Wiener
you don't have to download anything and here we create an instance of the servo or J servo the
Robo jack servo is initiated and we are connecting our servo to pin nine so we create a constant here
and the angle the initial angle whatever you want to set for some cars for some equipment you need
to put a certain angle if you don't have a fixed value just put 90 because the servo moves between
because the servo moves between 0 and 180 so 90 will be at the middle which is appropriate value
and then angle step this is the resolution or how fast the servo should move every time you press
it this goes 10 at the moment but if you want to make it 5 so change that so you have to present
multiple time in order to make it move you cannot press this continuously because the detector will
detect ffff and I do not work here the angle Center so you can set another angle when you
press let's say with the seagull right and left and right and with okay we bring it to Center
that Center is this value so when you press the button to reset I should have called this reset so
this is the reset angle and then this is for the remote I've used in this example this is a right
key this is the arrow which is part of the code that I have explained and this is for the left so
when you want to move the servo to the right this button is pressed and we have to put it inside the
quotation very important and for the left we put it there and for the center or reset okay this is
o and K capital inside the double quote so this must be exactly the same and if you're using this
remote let's say you want to use this channel plus for the right and channel - for the left
and CH for the middle you have to put exact the other days and I forgot to mention here if you use
this remote we type here capital W inside single code and she use this remote we type B as a black
and if you're using this module we set PCB equal one if you're using this module we set PCB equal
zero after this line had this you would not change this this is a white remote PC week codes this is
a white remove without PCB and these are the key for this white remote all the values are here so
that's why this must match with that above setting that I mentioned so you can control the servo and
this is for the black remote with TCB and so forth the important part that has changes this one so we
attach a servo pen which is pin number it to the servo so we must type or g a servo dot attached
so this is extra with comparing to the code that you watched and then inside the loop nothing has
changed this is exactly the same as before and we have 50 millisecond delay here this is like this
is the same as original code that I've created and after that Robo jacks validate code has not
changed except we put here sell for action in my previous video it was really action and some other
stuff so the job of this one is validate code to validate the code for us and take some action here
we put servo action and we pass the value that is received to this function and this is for the
white which is not PCB and held this is for white PCB same thing exact same line and then for black
PCB we are the same line and otherwise which is pcvue black wood non PCB and here is a servo
action that I mentioned the servo action receive the value of the string and here which check the
value if the value is equal right the right is the value that we define here right left and center
the three keys so we say if it's equal right we check if the angle at the beginning let's say
it's ninety or zero if it's bigger than zero and smaller than 180 because when you increment the
angle it usually goes above 180 so we have to make sure that we don't allow that or maybe if you go
for the left side if you go to zero again you will reach to minus below zero so this is preventing
that and adjusting and fixing and here is a point that sends the signal to the servo the angle
that you push and this is just a text here will display on the serial monitor and then here we set
the value to dot dot is something that I picked because it's not in this remote not in this remote
so that was unusual point so when once you release the remote that's just such a 2 dot dot so it will
not take action under with hundred millisecond and continuous if you press a button it will do
it and for the left we do the same thing and if we are Center or reset when you press I say okay
then we set angle equal center angle and then we pass it that's why the servo goes to the middle
now let me demonstrate controlling the servo I've opened the sketch the first thing that we do is
I'm using the black remote so for that I have to put here d4 black and because this is the PCB and
not this module I said this equal one after that here because I'm gonna control going right with
this one so that is the arrow that is printed and fortunately they printed black on dark blue
so you cannot see it properly but on the left for the left and for the center press okay so
this will reset and bring the servo back to normal the serial monitor now if I send a signal properly
it will respond I'm pressing it to the right you can see it sure it shows now it it was 90 now it
become 80 70 and if you pay attention here I have said that the steps and got a step 10 degrees for
that reason we are doing 10 so you see 40 degrees if I press ok Center it goes back to the center
which is 90 degrees now if I press left same way it goes to the left row I've set this now to
white I'm using the white remote and PCBs equal 1 because it's PCB and I'm using this one with a CH
plus to the right CH - to the left and CH back to the center or reset now the serial monitor is open
you see sometimes you get unknown because the switches
are not properly contacting or sending the wrong code
reset works I'm pressing it back so 180 that's a mark zero and after 180 you see when I press
it the command goes but the program prevents it and then press Center it goes to the center I've
set PCB equals zero because I removed the PCB and I put this tiny module with wire and it's white w
same way it works and CH will bring it back to normal
now I'm going to capture the code for this remote and control the servo instead of these remote so
let's use here the black remote when it says black remote because this is black I'm just
using the world black remote and then let's check this and set it to be us as black remote and this
is not a PCB so be black and TCP is equal zero now I've said this display could equal true so
when I press the keys here it will display also the code I'm planning to use this arrows right
left and entering the right arrow will move this to the right and placing the left will
move it to the left and pressing enter will reset this so that's my plan first I have to capture it
and see I'm pressing the right if I press the right here it says unknown which means none
of the key matched so that is good now without what I can't remove that I'm using with a black
now I'm pressing left left also doesn't match you see unknown unknown but you are getting the code
and also let's try enter so all of them marched but it's possible that some of the key that you
present it says CHS pressed or something this is a black remote I'm gonna use this
right and then left replace these code and for okay I'm gonna put entered this is just common
for myself so I'm gonna capture that the left one which is this one first let me open a new monitor
so left the filter code double-click control-c come here this is for the left
I'm putting it here you see six five nine and then let's go for the right
six be nine so multiple times is good if you get consistent value that's good double-click
highlight and then ctrl C copy and I'm gonna place it in here and for the enter sexy nine
consistent that's good control C come here and put it now this key and this key is within that
text but enter is not there so I'm going to go for the black remote key and put this label and
set off in time okay which I have to this will block with tcv you see here black remote key
this is top left right and then this is okay I'm gonna change it to inter that is done now we set
our values here for the right for the left and then for the center in touch so in this match
is the list that we had there then it will work now let's upload it just let's try it
so as you can see a good 10 degrees to the right and it reached 0 degrees now if I if I want to go
to the left that will work the same way and if I want to reset it I'll proceed let's go fully
to the left and enter we'll bring it back to Center as you can see it's rotating and then
we'll bring it to the center thanks for watching this was the video explaining how to use a remote
control with Arduino or with your home remote control to control a servo motor please thumb
up the video if you liked it and also follow us on Facebook and subscribe I appreciate it
you