this looks like a regular servo but this is actually continuous servo or sometimes they
call it 360 servo what it means is that as you saw with the servo which was going 180
degrees going back and forth this can run continuously either in clockwise direction
or in counterclockwise direction and controlling this there was no code available to controllers
so I have written this code experimented make sure it works with some discrepancy that it has and I’m
going to show you how you can control the servo motors with this three button so when you press
the clockwise or the right one it will start rotating clockwise when you press
stop it stops when you press counter clockwise the servo rotates in counterclockwise direction
you can directly press that clockwise so you can rotate
to clockwise or clock counterclockwise or stop it at any moment due to internal circuitry
so the stop command sometimes might not be perfect and as a result you will see that this is slowly
rotating but it could be due to the quality of the specific servo or maybe as the time
goes by the internal component gets warmer and this will behave like that but you can adjust it
and find the right value so you can it can always be stopped but it will not be fully stopped so
make sure to consider this as you can see it's now vibrating it's just at the edge of rotating slowly
this servo looks exactly like a regular servo but here they have some ds04 nfc
this is just a mark for a brand but usually they look the same all of them it has internally this
is this has metal gear it comes with all of these hardware different type of attachment
these four will go on the shaft and depending on your application whatever you want to control
these can be included and also these screws and these bumper rubbers and all of this
and here is the wiring which I have drawn using first thing this is a free open source software
you can download it with some modification I have done it this is the servo motor as my previous
lectures pen 9 have been connected to the input signal the middle wire or red one is connected
to 5 volts and ground have been connected to the ground and on this side we have three push buttons
the push buttons have left and right side the left side all of them have connect them to ground
the left of this have been connected with a wire jumper wire up to this point so this
is also connected to the to this point all of them are connected using this wire to the ground
and the right pin of each have been connected to different pen so that four clockwise have been
connected to pin two for this top the right pen have been connected with the gray to pen three
and the right pin of this counter clockwise have been connected to pin four
and here for this servo motor I must still we have darker color for the ground the middle color
is for the positive and the right lighter color on this one was orange and this one this is white
so ground have been connected to ground here the middle one is red I’ve put another red here
connected to five volts and then the left one is the signal input from Arduino which have
been connected to pen nine and here for the push buttons I use the same
color that I’ve used in the wire wiring diagram the black on this side have been connected
to the ground of Arduino and if I remove these wires you will see that I’ve connected
one wire here the left side of this switch is connected to the left side of this and from here I
have another wire to the left of this and all of them have been connected using this wire
to the ground and then the three wires that we have will be connected to the right of this button
the right of this button and the right of this button so three of them have been connected to pen
depends two three and four in here
let me explain the code we start by including the servo.h the header file with this line
which I’ve explained it before you have to include this otherwise it will not work and then using the
same class we create an instance of it we call it my servo and then we define pin nine as a servo
pen to connect the servo and these three pins are used pin two three and four will be used for
clockwise counterclockwise and stop and I call them stop pen cw pen ccw pen
these are constant and they will not change this pen must be pulsed with modulation pen
one of those possible modulation pens that has this tilde beside the name
but these are just digital pens and after that we are defining the values the three values this is
an integer array of cs servo command and I have three values with a comma separated this is 106
is for counter clockwise 52 is for stop and 0 is for clockwise I put them in order below this we
have string servo command text and these are the text that will be displayed on the serial monitor
and then status text this will remember the current status and this is the text
that will be displayed currently it's stopped and it is displayed
these three variables uh clockwise button status counter clockwise button status and stop button
status will be used internally inside the loop which we will see soon inside the setup we use a
serial monitor to initialize a serial monitor with 9600 baht and then using pen mode stop pen clock
counter clockwise pin and clockwise pin we set them as input with a pull up so we can
use push button without a resistor which I have explained it in my previous lectures after that we
attach the servo using my servo dot attach servo pen this will be pen 9 in our case to the servo
and then my servo.write is the command that sends command to the server to either stop or move it
and cs1 is the stop command cs servo command if you pay attention here this is a clockwise and
this is a stop we want at the beginning the server to be stopped so we send this command
to stop the comma the servo and also we send the text number one to show stop on the screen
text 0 text 1 text 2 so this will send that text to us after that inside the loop we read the three
push button pens ccw pin using digital read and also the same thing for stop and cw pen
and we read the status of the pen which is either high or low and high will be one
low will be zero the result will be sto stored in this variable which we defined above
and for the stop and also will be stored in the stop button status and clockwise button status
respectively then we check if counter clockwise button start is equal low which means if it has
been pushed then we send this command servo command 0 and this is a function which I’m
going to explain next it's in the lines below and then else f stop button status if that is
equal low which means if the stop button has been pushed then we send command number one
and which will send the value of number one from the array above and then if this clockwise
button status low then we send number two and then we print this text continuously
and to show the current status using this number this number will pick up the value from the array
the appropriate text that I just mentioned this text stop at the moment it is stopped
because status is one and if you send one to this array let me delete it so you can
understand if I put here 1 c is text 0 1 1 means stop c is text so it will print this text for us
and then we wait for 50 milliseconds and the loop continues like that
now let's check this servo command servo command is a function that I’ve written below
when we pass that 0 1 and 2 it will come here and become and becomes n integer
a variable and then we immediately in this line we set the status text either whatever it is it
will be 0 1 2 and the text will be picked up as clockwise counterclockwise will stop
for our to be displayed and then we use the same in to pick up the command the number and send the
servo to that to that direction then we print this text also we print the text telling us the
direction at the moment that is the button is pushed and also we will display the value that
is sent to the servo and this is open parenthesis and closing transits to display the value
and here is the demonstration I’m opening the serial monitor
and let's see also these values I’m pressing the clockwise if I push it
you see I’m sending zero you see here ccw zero this zero is sent and it is rotating
clockwise and that text is also changed telling us that this is rotating clockwise if I press stop
now this is stopped and if I press and hold it you will see the value of 58 stop inside the
plant is 58 that is a value that's coming from here and if I press clockwise you will see I’m
holding it shows 106 but I release it still it shows counter clockwise and that is the value
and the text that we are seeing all these texts that are displayed in here
so I just press stop clockwise if I hold it you will see the value I did that so you can
debug and fine-tune your servo otherwise it's not necessary to be the slit
and using these values you can change the speed of the servo motor for example if I set this to 70
and upload it whenever you press the counter clockwise command this will
go slower now let's see because that is the angle value currently is stopped so if I go
this now you see it's rotating very slowly and if I hold it you'll see the value is 70.
and stop right 0 is that the maximum speed and let's see if I set this to 170 what happens
this is the angle I’m uploading the code now and we will wait
so initially it's supposed to be stopped
with a little rotation because 58 now if I want to first let's fix this
so now let's reduce this to 50 4
and as the code is uploaded fully you will see that this will either stop or rotate
to the right so 54 is almost stopping it so I can fully stop it by maybe making it
51 three more numbers or maybe 52. from 54 I reduce it reduce that to 52 and let's see
now it's fully stopped but still it will change now let's press this with 170 and see what happens
that is the maximum speed and it will not increase the speed so for us the value
was for around 100 and let me see what was the value 106 and this value also the same way
will not affect significantly but it will make difference and that's the maximum
speed that you can get first introduction to the continuous or 360 servo thank you for watching