in this tutorial I’m going to show you how you can control
two or more servo motors using two potentiometers with Arduino you will have
independent servo controller for let's say for servo one or servo two together or one of them
you can get the code for this by clicking at the link below the video in the description
which will take you to robojax.com learn Arduino let's get started with
this
I’ve seen comments under the video asking to control
more than one servo motors so here I’m going to show you how to control
two or up to six servo motors with Arduino uno of course with Arduino mega you can do more so
this is just simple example and you can apply the same principle that I will show you in this video
you can control as much as the analog input of your Arduino will allow you will be able to do it
to quickly explain the servo motor servo motor is a type of motor that does not do 360 rotation
in this case this can go up to 180 degrees and
and it is sold to a different kind of this attachment that you can control airplane wing and
many other applications that you want to move something you can do it
with servo motor and the silver motor has three wire this is always the case
that the darker color is something you will see it black will be the ground and then the positive
is at the middle because uh in many applications and flight controller and stuff you will insert it
and this middle is always positive so even if you make mistake the your servo will be
protected in the lighter color this is orange and some applications you will see this will be white
this is the signal and this so so these two are the power and the orange is a signal to
control this and the signal that it receives to control this is pulses modulation signal
and duty cycle of that signal will make this go either 180 degrees or zero
let me explain now the wiring because I need multiple five volts I have to
use the breadboard and for ground as well from ground I’ve taken one wire I’ve connected here
this blue is now my ground available I have multiple grounds here and from five volts
also I’ve taken this orange wire connected in this side which is red with a plus sign
so these are all my five volts this will be connected to ground in here
anywhere on this and the middle one is five volts I will connect it to five volts here
and then this is a signal this will go to this pin three pin three is password
modulation enable pin you see that tilde and five is also puzzle modulation six
you cannot connect it to any other pens now for the potentiometer for this because we want
on the right side to be the maximum on the left to be the minimum 0 and this is 180 degrees because
the right is maximum put this to the positive so this is my five volts I’m connecting it somewhere
in five volts and the left side I will connect it to the ground somewhere here at the ground
on this ground and the middle pin must not be connected to 0 or 5 volts it must not be otherwise
you will make short circuit when you rotate it and this is connected to analog 0.
servo 1 is done same way for servo two I have three wires the dark one is connected to ground
somewhere here the red is five volts I will connect it to 5 volts and the orange
goes to the next positive modulation which is pin 5 and I have defined it in code also
in pin 5 i can put it in any other pence with the pulses modulation enabled symbol
this is potentiometer for the servo 2 the positive the right one is connected to 5 volts
the left one is connected to the ground and the middle pin will be connected to analog one
at this point
let me explain the code this is the code that I have opened it by clicking at file examples
servo and then knob after that I’ve updated it I’ve left the original credit to the creator
I’ve just updated it I’ve modified it so it can work with this purpose and the servo.h is part of
Arduino ide you don't need to download or include anything this line include means the servo header
or servo class will be included and this portion is for server one we're getting the servo
class and we create an instance of it and we call it server one and then we assign a pin
as a constant integer we call it servo one part pin or potentiometer pin this is analog zero
and then another constant which cannot be changed is integer servo pin this is the pin that sends
signal the servo pin will be perfect modulation enable pin like pin 3 5 9 and other pens which I
just shown you otherwise it will not work and then the servo one value is
the value that when you rotate the knob the value will be assigned later on in the code
so this was for servo one and we do the same exact thing here with
this time we create an instance of the server we call it server 2 and then I just change the 1 to
2 here and assign another pin this was analog 0 this this is analog one again servo pin 2
servo two pin is pin five it's also possible modulation enable pin and then the value
one has been changed to two inside the setup we initialize or attach a pin to servo one using
servo one dot attach servo one pin and then servo two there is also two so if you want to create
three four or as long as you have analog input then just copy and paste it and change this
one to two and for example for three just change this three three three and assign
for example analog two and another pin here and also in here the same way servo two attach
servo two pin and then if you have three just copy and paste it and change it to three and three
and so forth this portion is to control the servo one first we use analog read we read the analog
servo one potentiometer pin the value which is from zero to 1023 will be stored here and this
variable we call it server servo one value which you have defined above and then using the map
because this is from 0 to 1023 we get this value here we map it which means we convert or change it
the value for this which is from 0 to 1023 we convert it to angle between 0 and 1001
because the servo our servo can go from 0 to 180 and when the potentiometer value is 0 the angle
will be 0 and if it's 1023 it will be 180 degrees and the other values are in between these two
so this is doing the calculation in terms of angle something between 0 to 180 will be stored here
now we get we use servo1 dot write and then we pass the servo one value here
and the value will go to the servo one and servo will move to that angle which we have set using
potentiometer and the same code is copied here for server two if you pay attention all
the values are two and if you have three just copy and paste it and make one more line here
for three this 15 millisecond is the time that allows the server to move to the desired location
if it is too slow you can increase the speed by reducing this value or
you can increase it to reduce the speed of movement of servo and the loop will continuously
read the potentiometer and move the servo to the new location now let me demonstrate it when
you initially start the Arduino the position of this depends on where you set your potentiometer
and they move very smoothly sometimes when you move this you will see some vibration
here but this will not move I don't know if you notice a little more movement will be
seen and that is due to fluctuation in the power supply or internally from Arduino but
the same way this one will affect very minor
but it will not move it just shakes and goes back to the location
and if you change this to 5 from 15 let's see what happens now it has been updated to 5
now the vibration has stopped
other than that it perfectly responds that's now responding perfectly and for that
if you need server number three or four or five just add more potentiometer and your service where
you can connect up to six servers here because we have six inputs six pulses modulation enabled
pens
thank you for watching this was how to control two or more servo motors using Arduino if you like
this video and learn something please thumb up as this will help my video in the search algorithm
of YouTube if you have comment or question post it at the comment section below I try
to answer and reply if you want to get updates of my upcoming videos make sure to subscribe