Hi, welcome to ESP32 tutorial from Robojax. in this tutorial we are going to
learn how we can send the stepper motor from the interface of your phone or
mobile device or a browser to any predetermined angles by simple touch it
will be controlled over Wi-Fi and you will have unlimited number of push
buttons. each will have their own angle direction and speed. 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.
my name is Ahamd Shamshiri. I am presenting this tutorial from Canada.
stepper motor is widely used in many applications and mechatronics automation
and other industrial applications and I've spent quite some time working with
stepper motors DC motor Arduino and other means to control it. including
direct connection or over Wi-Fi and Bluetooth. and I've written this code for
this motor so you can control and send the stepper motor to any desired angle.
you just press a push button and the motor will go to that angle. if you're
using Arduino I have separate video for this where you can set the angle where
you can set the direction and you can set the speed for each push-button
and there are no limits as long as your device will allow you to have more push
buttons you can have and you can send it to that angle. now in this - really you
will be able to control the stepper motor with unlimited number of push
buttons over the Wi-Fi either from your phone or your computer or tablet browser.
so you will have different push buttons each have separate angle, direction and
speed. just touch it and the motor will go to that angle and with that speed and
direction.also you can have custom angle with different direction and speed you
can type it directly on the screen and just send and the motor will go to that
direction. and this is available for ESP 32 and esp8266 d1 mini and NodeMCU
Wiring Explained
now let me explain the wiring. I've connected five volts external 5 volts to
this module make sure that we have this jumper it is connected. and now the 5
volt is coming in here the red on this side is connected to positive this is
connected to the negative. for the motors you cannot make mistake so they are
connected in here for the module I've connected like this IN1, IN2,IN3 and IN4
I've connected some extension male-to-female cable it is coming so and
in here this IN1 is connected to pin 13 , IN2 is connected to pin 12 there is
one empty between because this is ground and then IN3 is connected to pin 14 and
IN4 is connected to 27 so they are all in order with the exception that there is a
ground GND. and these pins are labeled exactly as they are here as you can see
here G 13 ground G 12 G 14 g27 on this module exactly the same g13 ground G 12
14 27 you can change it to any other digital pin as you wish. 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 more do a new courses below this video in the description.
Code explained
the original code that I've started it from this example if you click on file
examples and then scroll down until you see this area is for ESP 32 and this
line the divider webServer and then advanced webServer. I've taken it and
heavily modified it. because of some of the inclusion and some functions so I
did not change it at the making is very easy but I've heavily changed the code.
now let me explain the code. for the code you need to set the pins here. Pin 1 & 2
& 3 & 4 these are for the pins that we have in here for these input pins. so I've
set pin 13 12 14 and 27. and then because we want our four push buttons we have to
have four angles this is for 1 2 3 & 4 so these are these values that you see here
to 360 and then the next line we have the direction
and in the next slide we have the direction CW, CW is for 360s CCW is
for 270 CW is for 90 and CCW is for 20 .and the next one is a speed factor this is 10 for
for the 360, 1 is for 270 so there are according be aligned. and if you want to
have more just add here comma and if you want for example 287 degrees you can put
it clockwise capital CW do not put small CW you'll get error. and then a
speed factor let's say 2 and then the last one here this is a value that when
you click it sends the motor and that is just text. " motor sent to" and also for the
for the last one also put a comma and inside double quotation the reason I put
all this because sometimes the location refers to something and for example this
location something moves and you call it 5 degrees and here you call it turning
on or turning off I don't know whatever so in order to allow you to customize it
fully I prepare that. these are the rest the degree that you see here is this one
in this "in" is here and then a speed factor is this text I prepare them and
allow them to customize it because people are using different languages for
many other languages or sorry other purpose you should be able to change it
and this this angle is this text and then direction have not used it here
comma speed is this text and then send is this text. so all of these texts that
you see here are customizable and here including this stop this stop is in here
so anything that you see with the word title you can customize it. SSID and your
Wi-Fi password the this is a route that I'm using for
tutorial I will turn it off. I don't worry if you know the password. if you
need full explanation of the code it is available as part of my Arduino course
at udemy.com. The link to my course at Udemy is below this video.
Demonstration: Desktop
here is the ministration. the first thing that you need to know if because inside
the code this is connected to my Wi-Fi router for this tutorial
it's called Robojax. so your computer must be connected to the same as you can
see here it is connected to the Robojax otherwise it will not work. so that's the
first condition. after that when you upload the code click on the serial
monitor this now opens and press this reset push button here as that reset
push button once you press it it will print the IP address for you so you can
get this IP address but in majority of networks you can directly type this
http://roobjaxESP32 so I'm just copying this now by pressing control + C and I'm gonna
show you that one as well that IP address. so I'm gonna open a new
tab and then control V. and press Enter. so this is coming now from this module
the because the module is now acting as a webserver. and these have been defined
so the same way on your phone first try this
http://robojaxESP32 if it doesn't work then use this IP address. this IP will vary from network
to network so whatever your ESP 32 shows here this will be your address. and let
me also show you that one that it will work. let me open a new tab plus paste
and enter. and here through the IP address we are getting it and through
the robojaxESP32 also we can get this. and now here is the demonstration.
currently the motor is stopped and these are the available values the four angles
with a direction that is set. the speed I do not want to show the speed here but
once you click it for example for 270
so it goes when I press it the motor starts rotating and it shows you the
angle it shows you the direction it shows you the speed factor that you
set in the code and also it shows you the time that it will take to complete.
with that speed this angle. for example if I go for 90 so this will go clockwise
90 degrees somewhere. in here but because the speed factor is 4 it will take 4
seconds to complete that portion. and this 20 degrees counterclockwise from
here perhaps to here and it took 2 seconds because a speed factor was 10.
and now let's check 360 so this will come back to the same location and it
will take 40 seconds because the speed factor is set to 10 for 360 if you set
it to 1 it will take 4 seconds and 2 3 4 and because it is 10, 10x4=40
40 so this will take 40 seconds to complete and I am showing you also the
counter here at the top. so you can see it.
and and when this is running at any moment you can just click and stop it. so
the stop is available all the time let's go for 360 and it is running now very
slow but you can stop it at any moment. doesn't matter. so this way you can move
this to any location that you want and stop it and from that stop all these
angles are valid for example this 90 means from this point now it goes to 90
and clockwise direction it goes here. so it will go 90 degrees in that direction
and now from here to 90 is in here and all these angles are with respect to the
last known location. so this way you can move it and stop it anywhere you want.
Demonstration with custom values
also I've worked a lot on this section as well and it was very time-consuming
so you can set your angle for example you can set it 450 degrees clockwise and
speed factor of 1. now it goes 450 so 360 plus some extra
angle in goose 450 and I put her see in front of it so it means custom it was
450 the angle was the factor was 1 it will take 5 seconds so completed that
angle in 5 seconds. and if I do that with 2 that will be 10 seconds the same angle
now it's much slower and it shows her that timing.
Demonstration on mobile phone
and here I have my phone is now connected to the same Wi-Fi Robo jack
and here I'm typing the IP address that I've just shown you
192.168.1.100
192.168.1.1 right now here is a demonstration with a mobile device let's
send that to counterclockwise 270 degrees so it shows exactly the same as
a larger display. 90 degrees and stop it at any moment. 20 degrees and you can go
also in here and let me insert here 289 degrees clockwise and go. the push button
is not showing the text properly here. I have to see why. and now if I go with 360
I have set it that the speed factor of 10 so it would take 40 seconds for this to
complete let's go for it. now it shows that it is going for 40 seconds
and in here also the same way you can set off with a speed speed factor the
one means fastest speed and as you increase the number the speed will slow
down for example if I set this to 2 and I go 360 clockwise or maybe
counterclockwise this will take 8 seconds because one means four seconds
and two means eight seconds it will complete. and the
calculation also show there
Subtitle typed and corrected by Ahmad Shamshiri on Jun 19, 2020 in Ajax, Ontario, Canada
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. Thumb up the video 👍 and say simple "thank you" in the comment section.
My PayPal account link is below this video if you want to send cash donations. Thak you.
thank you for watching the forth how to control the tiny stepper motor with
ESP32 over Wi-Fi either your mobile device or a browser. if you learn 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