hi welcome turn our doing a tutorial from Robojax. My name is Ahmad Shamshiri.
in this tutorial I'm going to show you how we can use Arduino to control this
tiny stepper motor 28BYJ-48 with push-button. For example this is assigned to 90 degrees
clockwise when I press it it goes to 90 degrees clockwise and stops and this
goes to 200 270 degrees in counter clockwise and stops for each you can
assign, angle ,speed and direction. but this one goes 365 degrees and 3 times
slower you can get the code for this by clicking at the link below the video in
the description which will take you to www.robojax.com/learn/arduino
let's get started with this
this is STPB-5 or 5th video in the series of push buttons with stepper motor I've
seen need for controlling super motor in different ways and perhaps there are
thousands or maybe millions of way that this stepper motor can be used and I spent
quite a lot of time on writing code and experimenting and providing different
solutions for different projects that people have and in this one we have one
stop push button and then multiple push buttons doesn't matter two three four as
much as the pins allow you to connect you can have and assign different angle
and different speed and different direction.
I have introduction video to this motor and the link for that is below the video
how this motor works how this board is functioning and all the explanation I'm
not going to explain those make sure to watch that video separately as this
video will be very long. but a lot of other videos that you can control this
stepper motor with push buttons with one push button to push buttons stop with
the potentiometer and many other types the links for those videos or below the
video in the description. also I have video how to control it using your
mobile ddevice with ESP 32 or node MCU and D1 mini. you can watch this
video by clicking the link below the video in the description.
Wiring explained
Now let me explain the wiring here. I've kept the board in the same order so you
don't make mistake. blue purple gray white, blue purple gray white. pin 8
9, 10, 11 in the same order. this pin because this motor is very
small and if you don't have enough load then we can connect it to Arduino. if the
motor is heavy and you're controlling some kind of load then connect external
five volts but in my case it is enough. and here I have this jumper connector is
connected already so if you remove it it or not work. it should be connected
here. the red will be connected to five volts and here the red if the red is
connected to five volts the brown is connected to ground to this point. and
for the motor for this connection you don't need to worry about it because you
cannot insert it and correctly. for this push button we have four push buttons
here but use this long type long pin push button you can get them from Amazon
eBay or Aliexpress and I have inverted them one pin in between so one is empty
in between and this is here and here so this is now the ground pin now if I
remove this you will understand better this is ground then I have a wire to a
point that I will call it ground pin for the next one and then from here I have
another wire that's ground for the next one and that's ground for the next one.
and then because I have four push buttons
we need five wires and this one is connected to ground so this ground will
go to ground of Arduino then these four will go to the right pins of each push
buttons in here.
so all of these are connected to the right side of the push button not on the
other side on this side. and the push buttons are in the same order. and here
they have been connected from here in the same order to pin 2, 3, 4 and 5
and if you have more wires and if you have space just connect them. if you
need the wiring diagram for this it is available as part of my Arduino course
at udemy.com. if you want to learn Arduino I have a best seller course on
udemy where you can learn Arduino from ground up with hundreds of projects
all course material library codes wiring diagram everything available in one
place the link for my Arduino course is below this video in the description.
Code settings explained
now let me explain the code. we are defining clockwise direction with number
one do not change it. counterclockwise as 2 and stop as 3 throughout the code we
will be using this CW, CCW and STOP so we can understand it better. and we are
defining pin 8 9 10 and 11 for IN1, IN2, IN3 and IN4 of the controller board. that is
connected to the motor. and it stops which we are defining pin 2 that is the
first switch that stops everything. and then stop type 2 means stop and hold and
this will consume energy and some application you need it otherwise set it
to 1 and 1 means just normal. speed factor is just a value that is not used
here I'm going to delete it later. and these are the four important arrays you
see the square bracket here it means it is array and it has multiple value and
this has only one value so that's a difference. and I have separate video on
erase if you want to have a look at it introduction a crash course on Arduino
the link is below. so we have this 3 angle for 3 because I'm using 3 push
buttons or 3 angles have defined 360 270 or you can go even 7655 degrees up to
you whatever angle you want these are the pins, pin 3 4 5 I'm put I'm putting
them side-by-side accordingly. and for each push button this is the angle this
is the direction and you can have as many push buttons as many angles as you
want but make sure that when you put the angle also assign the pin for it and
also assign the direction and assign the speed for example if you add here one
more let's say you want that push button to have 300 degrees then also you have
to define a pin for example 6 you have to define
the direction CCW. for example and the speed factor fastest would be 1 so
this way you have to define it. if these arrays are not in the same length
for example this has four elements as for if one is less or more you will get
error. if you wanted see CW CW CW if you wanted your CW put CW capital because we
define them above and here. and then speed factors for each if you want the
fastest just put one and if you want the slower just put two threes and higher but
you cannot put zero. and if you need full explanation it is available as part of
my Arduino course at udemy.com the link of my course is below the video in the
description.
Demonstration
and here is a demonstration at the moment this is set to 90
degrees clockwise and when I press it when I press it at this location it goes
to 90 degrees and stops the speed is 1 which is maximum
now it goes 360 degrees in 4 seconds and it will be it will be 2 it will be four
times slower so forth. and this push button now if I press it again I can
stop at any moments. so and then we have two types of stop one is just stop and
the other is hold. this is a type of because this has gears it will hold it
anyways but I have made that option available in some application you need
to hold something in a certain position not just turn it off but consume energy
and hold it. and that option is available and this one is going 270 degrees. and
now if you look at this from here that 180 270 will be somewhere here. sorry the
other way. and this one is now speed of 3 times slower but 365 degrees and as you
can see you can see even the blanks so it's much slower but you can also slow
it down further if you want for example this is going 90 degrees and clockwise
direction let's this let's make this 6 and in that 4 that 90 degrees it goes 6
times 4 24 times slower one means that one revolution is 4 seconds and 2 means
and when you set it to it will be twice slower. so this is now 6 times slower
I couldn't upload it let me press this you see that 90 degrees is taking that
much time. and if I press it again from that point it goes. now if you want to
put it in a certain position before sending it to another angle you can for
example this is fast I'm pressing it you can stop it and press this and make sure
it reaches to a specific location that you want and then stop it. now all the
switches will be waiting to send this motor to that exact angle exact angle
from this position which we call home.
and if you stop it this will be your home and pressing any of this push
button will cause it to go in that direction. if you want to change the
direction we just change this to C W or CCW but you cannot have zero if you put
zero here the motor will not move at all. the smallest value which means the
fastest will be one and you can increase it and of course if you increase it like
very crazy for example this is 270 degrees already its long angle and if I
put this 10 and if I put here 10 so the middle push button now it will be 10
times slower
you
first push-button and clockwise with a normal speed for 360 degrees code is
uploaded now it should go 360 degree it will come back to the same location so
that is 360 degrees with a regular speed. now if I set this to 2 this is just for
the demonstration to and upload it it will be twice as much slower. now I'm pressing
this and showing you the counter so you can see an address understand that it is
taking twice as long. and now let's make this five
now again it will take five times for 20 seconds before that reaches back
now I made it 10 let's change the direction to counterclockwise
now it'll be 40 seconds now let's see how long it takes I change the direction
so it should come back
Subtitle corrected and typed by Ahmad Shamshiri on Jun 12, 2020
I would like to thank my Patrons from Patreon.com
I did my part to help you learn. Now it is your turn.
You can subscribe to my channel and thumb up 👍 the video and type something in comments section.
The link to my Paypal account is bellow the video if you want to send cash donations. Thank you.
thanks for watching this was how to control a stepper motor with multiple
push buttons and sending it to different angles if you learned something and
found this useful please thumb up 👍 as this will help my video in the search
algorithm of YouTube. if you have comment or question posted a comment section
below I try to answer and reply. if you want to get updates of my upcoming
videos make sure to subscribe.
let me now explain the wiring the motor is already connected so you don't do the
wiring from here we have four wires pay attention blue is on this side white
is on this side and then here blue is on this side in this case so it is coming
from pan eight nine ten and eleven these are accordingly if you look here
to this if I flip it like that