Control a Stepper Motor using an Arduino, a Joystick - Tutorial
HTML-код
- Опубликовано: 15 апр 2019
- Hi Guys in this video shows how to control stepper motor speed and direction of rotation using Arduino UNO board and PS2 joystick. The stepper motor used in this example is 28BYJ-48 (unipolar stepper motor) which usually comes with its driver board.
Thus there is no need of any easy step driver. We are just using ULN2003 Darlington pair motor driver IC.
Follow Me on my Social Media
Instagram:
/ waqas_farooq124
Twitter
/ waqasfarooq01
Facebook page: / waqasandusama - Наука
// include Arduino stepper motor library
#include
// define number of steps per revolution
#define STEPS 32
// define stepper motor control pins
#define IN1 11
#define IN2 10
#define IN3 9
#define IN4 8
// initialize stepper library
Stepper stepper(STEPS, IN4, IN2, IN3, IN1);
// joystick pot output is connected to Arduino A0
#define joystick A0
void setup()
{
}
void loop()
{
// read analog value from the potentiometer
int val = analogRead(joystick);
// if the joystic is in the middle ===> stop the motor
if( (val > 500) && (val < 523) )
{
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4, LOW);
}
else
{
// move the motor in the first direction
while (val >= 523)
{
// map the speed between 5 and 500 rpm
int speed_ = map(val, 523, 1023, 5, 500);
// set motor speed
stepper.setSpeed(speed_);
// move the motor (1 step)
stepper.step(1);
val = analogRead(joystick);
}
// move the motor in the other direction
while (val
@Jae Leidall I am glad it worked for you
@@WaqasFarooq oke mercii beaucoup sa fonctionne
I have a question if I wanted to create a 2 speed stepper motor what could I change?
@@kassemjebbari2242 you need to copy same lines of instructions for 2nd motor but with different Pin and alsoy axis oin of joystick to control that motor
@@WaqasFarooq oke oke thank you I just finished my program I send it to you.
would you tell me if it is good?
Nice tutorial! I found it useful but I think some beginners wouldn't find it so, the verbal explanation is a must in this sort of tutorials where code from specialized libraries is used.
Glad it was helpful!.
I agree with you. In the future i will add my voice over as well so everyone can understand
I love it !!! no blabla, very clear vid.
I am glad that you loved this video and thank you for watching and subscribing my channel
Thank you. This is exactly what I was looking for. I read on the forums that is dangerous to power the motor directly with arduino. You should use an external power supply with shared grounding. Is it right?
I am glad you like it. 28byj-48 motor only needs 5 volts you can provide it from Arduino and also use external power supply
I like how he include the debugging
i am glad you liked it ,consider subscribing my channel
Merci tuto clair et nickel.
i am glad you liked it and thank you for subscribing my channel
Nice..I want to connect one stepper motor (5v), 3 servos, 1 display where the button performs a cycle while the lock button repeats the cycle. the display adds up the number of cycles. do you want to help me? :(
Got it all working, any advice on which line(s) of code to modify if I wanted to make the motor turn faster? Thanks :)! Great video by the way!
28byj-48 stepper motor has its own limitation and running on its max speed but if you need higher speed then you have to use NEMA 17 stepper motor which is also bigger in size, futher you can search about NEMA stepper motors and its standards along with its data sheet
Thank you for watching and subscribing my channel
reales gracias tu aporte es un gran trabajo
Thank You , I am glad you like and thank you for subscribing
how to make the motor back to original position when joystick is released
can you help me please?
How can I limit the directions of rotation 90 degrees to the left and 90 degrees to the right?
you can use limit switches or you may can use servo motor instead
i cant find the stepper motor and the ULN2003
Hello, I have a question, what is the function of line of code 2
"define STEPS 32"
step count for stepper motor
Thank you the video was so helpful but i just wonder what is the name the program that you used in the beginning?
for circuit diagram i have used Fritzing software you can download it by going to this link fritzing.org/
@@WaqasFarooq thank you so much
@@j83telbatalv you are welcome and thank you for subscribing my channel
I have an error. it says: expected initalizer before 'void'. I don't know what the problem is. can someone help me?
kindly check your libraries or try to reinstall arduino software
Very good work. It works good. Program is not really academic, but it works good. Little problem: when I move the joystick, and release it, the stepper is still turning slowly, and of course, the LEDs on the stepper card are blinking. If I disconnect the arduino and reconnect it, the stepper stands still and stays like that if I do not touch je joystick. As soon as I touch the joystick, it works, if I releasing the joystick, I have the same result, the stepper is moving slowly.
If you have a little time to see that...... Anyway, thank you for releasing your program.
there is little delay in code you can reduce the code delay
@@WaqasFarooq i have the same problem. what do i have to do to stop the engine and stop turning
@@DSmediaFotoFilm no when you will release the joystick it will automatically stop
@@WaqasFarooq Can you limit the number of steps?
I want to do a follow focus for my DSLR camera
@@DSmediaFotoFilm yes it is possible if you want smooth movement and for you camera slider its better to use NEMA 17 Stepper motor
How to use rtc instead joystick.
To on stepper motor specific time.
well that's pretty cool idea i think i will make it. its will be a very cool project for time-laps camera slider for video content
Merhaba, 90 derece sağa ve 90 derece sola kısıtlama nasıl yapılır?
Thank you so much!!!!!!
you are welcome and thank you for watching and subscribing my channel
my stepper motor wont stop spinning, i can let the motor to spin left or right but not let it stop.
kindly check your joystick connection it maybe happening due to loss connection
how can i add a ramp up and down. to start easy and stop smooth?
yes in this tutorial you can see that how much you push the joystick. it depend on how much further you push the joystick knob
maybe you want to vary the speed of start and stop with poteniometer
A suggestion is not to draw power from the Arduino, it has not so much amperage to drive motors.
Put the stepper driver to an own power source that can give the amperage that the motor wants and put the Arduino and driver on common ground.
@Pelle Chamliden thank you for your suggestion , i have faced this problem when i was working with Nema 17 Stepper motor, so i provided power to motor driver from external source and common the ground wires of arduino and external source, but actually stepper motor driver also need a ground from arduino, you can check out my other videos, thanks again
@@armwrestling_nerd this 5v stepper doesn't draw that much current that needs an external vcc ...
Its exactly what i need . i have a question. How to increase or decrease the stepper motor speed ?
basically joystick has variables inside it speed depends on how much further you push the joystick up or down
I got a big problem, I connected everything and verified the code and when I complied it, It happens nothing with the joystick and the motor
code is working fine check your joystick connection mostly it happens due to lost connection check the stepper motor connection as well and select the right board in the option
Bro I could not find that green motherboard in thinkercad. That connects motor and arduno. Please tell bro how to add that thing
you can download the fritzing file from fritzing.org of stepper motor by just google it and you will .fzz file extension file import into you software then you will be able make a circuit diagram
and thank you for watching
what is this software that you are using?
I am using Fritzing for make this schematic here the link fritzing.org/
Thank you for commenting and subscribing
Can I use Arduino nano will it work
Hi; i wand to add one more stepper, what i have to do? thanks
you want to control two stepper motors with one joystick .
i will make a video and share it with you.
@@WaqasFarooq i want to control an Motirized camera gimbal, driven by 2 nema 17 Steppers and 2 L298n as Stepper drivers. So one Stepper has to drive the Horizontal Movement and the other the Vertical. can you help me with the Scatch? An option is to get an Home position if i klick the joystick button and it find his Home positions with 2 inductive Proximity Sensor Switches.
@@michaelkroon409 you want to make gimble with two stepper motors right. i will make tutorial soon
What would I have to do to make it so that it runs 2 stepper motors. I would like to know for a project
here is the link to 2nd video ruclips.net/video/C0rLXQxHg5w/видео.html
thank you for watching and subscribing my channel
@@WaqasFarooq Thank you very much for the tutorial. I'll probably use your channel for more Arduino projects.
@@zachhoffman8514 thank you so much I really appreciate this and hopefully I will upload more useful tutorials
When I verify the code, exit status 1 ' IN4' was not declared in this scope ... What is missing?
its because you did not declared the IN4 Pin actually. Try to copy the code from my pinned comment, it works,
Thank you for subscribing
@@WaqasFarooq I copied the codes and checked it again, but same error message, IN4 was not declared, I update also the libraries! Any advice much appreciated thanks
@@glennbelga3151 try to reinstall your Arduino IDE sometimes it happens ,because i compiled this code again its compiles successfully
Bro this software fritzing is paid. And when downloaded mod version I cannot find 28byj 48 with module. Can you tell me how to find it in normal version. I want that setup
it used to be free software.
What is the name of the simulator program at the beginning?
Fritzing and also tinkercad you can use both
The program you are working with ????
Tinkercad ???
this one is fritzing to draw circuit diagram
perfect
thank you
Can u please say me the software which you used for designing. I have subscribed your channel.
I have use Fritzing software for designing here is the link to the website
fritzing.org/
Thank you so much for watching and subscribing to my channel i really appreciate it
Thanks for saying the software name. 😁
@@galax4210 you are welcome
is it a free software or payfull one
???@@WaqasFarooq
mine just spins and spins when I run it, I cant control it at all, but it spins. any ideas?
i think your joystick connection is loose if the connection is not secure well then stepper motor starts spinning and won't stop
Waqas Farooq yea I just realized the connection I did was wrong
@@ddb4 I am glad to help you please do subscribe my channel
same problem with me
when i uploaded the program motor starts rotating even i didnt connected the joystick
any suggestion??
OH that's perfect 👌thanks
If you don't have problem give me the code please i waiting you .😊
i have pin the code in comment section you can copy it. Thank you for watching and subscribing my channel
hello, i love your video btw, but i have a problem. my joystick is different from your joystick
my joystick is:
grnd
+5V
Vrx
Vry
SW
I am really appreciating you like my videos and +5 will connnect wit +ve and GND goes to -ve and Vrx Means Up and Down and Vry mean left and right
merhaba kodu yazdım fakat çalışmıyor motor sıkışıyor (mıknatıslaşıyor)
#include
#define STEPS 32
#define IN1 11
#define IN2 10
#define IN3 9
#define IN4 8
Stepper stepper(STEPS ,IN4,IN2,IN3,IN1);
#define joystick A0
void setup() {
}
void loop() {
int val = analogRead(joystick);
if((val> 500) && (val < 523))
{
digitalWrite(IN1,LOW);
digitalWrite(IN2,LOW);
digitalWrite(IN3,LOW);
digitalWrite(IN4,LOW);
}
else
{
while (val >= 523)
{
int speed_=map(val,523,1023,5,500);
stepper.setSpeed(speed_);
stepper.step(1);
val =analogRead(joystick);
}
while (val
try this code
@@WaqasFarooq hata veriyor
kod için teşekkür ederim
exit status 1
stray '\357' in program
open arduino IDE and go to => Tools => then click on Fix Encoding & Reload . after that look into the code and check if you see and characters which are show at the line where you getting this error
@@WaqasFarooq merhaba dediğinizi yaptım
şu an 5 voltluk motor ilk tek tarafa dönüyor lakin joystick ile sağ yavaş sol hızlı dönüyor 12 voltluk motor ise hiç çalışmıyor
i have an error it says speed_ is not declared in this scope
// include Arduino stepper motor library
#include
// define number of steps per revolution
#define STEPS 32
// define stepper motor control pins
#define IN1 11
#define IN2 10
#define IN3 9
#define IN4 8
// initialize stepper library
Stepper stepper(STEPS, IN4, IN2, IN3, IN1);
// joystick pot output is connected to Arduino A0
#define joystick A0
void setup()
{
}
void loop()
{
// read analog value from the potentiometer
int val = analogRead(joystick);
// if the joystic is in the middle ===> stop the motor
if( (val > 500) && (val < 523) )
{
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4, LOW);
}
else
{
// move the motor in the first direction
while (val >= 523)
{
// map the speed between 5 and 500 rpm
int speed_ = map(val, 523, 1023, 5, 500);
// set motor speed
stepper.setSpeed(speed_);
// move the motor (1 step)
stepper.step(1);
val = analogRead(joystick);
}
// move the motor in the other direction
while (val
Copy this code and also install the libraries for it,
how can I control the speed of the ateppers
in this video the speed of stepper motor depends on how much you push up and down joystick knob
@@WaqasFarooq - i need a heiger maximum speed
@@done7309 28BJY-48 stepper motor speed is not slow not as NEMA 17 stepper motor .
on top of that this stepper motor running on 5volts if you apply 12 to this small stepper motor you maybe result in burning it up
what program are you using ?
fritzing .thank you for watching and subscribing
Which Software is this?
Fritzing is the name of software you can download it easily by going to fritzing.org
library pleaseeeeee
github.com/Stan-Reifel/TinyStepper_28BYJ_48
download it from this link
can you give me the full code
// include Arduino stepper motor library
#include
// define number of steps per revolution
#define STEPS 32
// define stepper motor control pins
#define IN1 11
#define IN2 10
#define IN3 9
#define IN4 8
// initialize stepper library
Stepper stepper(STEPS, IN4, IN2, IN3, IN1);
// joystick pot output is connected to Arduino A0
#define joystick A0
void setup()
{
}
void loop()
{
// read analog value from the potentiometer
int val = analogRead(joystick);
// if the joystic is in the middle ===> stop the motor
if( (val > 500) && (val < 523) )
{
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4, LOW);
}
else
{
// move the motor in the first direction
while (val >= 523)
{
// map the speed between 5 and 500 rpm
int speed_ = map(val, 523, 1023, 5, 500);
// set motor speed
stepper.setSpeed(speed_);
// move the motor (1 step)
stepper.step(1);
val = analogRead(joystick);
}
// move the motor in the other direction
while (val
also subscribe and share
Thank you.
@@enayathabibi3100 you are welcome, Subscribe for more video
SVP LE CODE
check my pinned comment
WebSite please ???
www.fritzing.org
speed_ was not declared in this scope
okay you should download some libraries and then try to compile the code it will work
@@WaqasFarooq Hello, nice work here, thank-you. I too am getting" speed was not declared in this scope" error. I have at top of code. What other library do I need to get this to run?
@@terrybomerscheim8165 you need to download this library as well "stepper. H " this is also a library
@@WaqasFarooq Well Sir , thank-you, I get this bugger to work. There sure wasn't a library, (you were playing with me there), but the "speed" declaration was fixed by dropping the (_) underscores after the word " speed " in the code. And didn't need any C++ OOP Black Magic F*ckery.
@@terrybomerscheim8165 I am glad it worked for you. thank you for pointing out this mistake
Simulator?? Plz
you can do the simulation on tinkercad and proteus this software is fritzing you can only make diagram
Can you tell me a simulator name that i can found all component i need like joystick stepper motor and others
@@_The_Unreal_ you can use proteous because you can make joystick into it, tinkercad does not have joystick
Thanks
@@_The_Unreal_ thank you for watching and subscribing my channel
Lose the damn music and TALK DAMMIT!!
Thanks for your concern i will put voice over on the future videos and thanks for commenting , I really appreciate your sugesstion
@@WaqasFarooq its a pretty song tho
@Trebuchet thank you i really appreciate that😊
@@trebuchet8587 It is nice music, I'll admit that.
j'ai une erreur au void setup je ne sais pas pourquoi le message dis "Arduino: 1.8.13 (Windows 7), Board: "Arduino Mega or Mega 2560, ATmega2560 (Mega 2560)"
Analog_Joystick_step_motor_kassem:12:1: error: expected ',' or ';' before 'void'
void setup()'{'
^~~~
C:\Users\admin\Documents\Analog_Joystick_step_motor_kassem\Analog_Joystick_step_motor_kassem.ino: In function 'void loop()':
Analog_Joystick_step_motor_kassem:40:3: error: expected ';' before '}' token
}
^
Analog_Joystick_step_motor_kassem:40:3: error: expected '}' at end of input
Analog_Joystick_step_motor_kassem:40:3: error: expected '}' at end of input
exit status 1
expected ',' or ';' before 'void'
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
you need to select the correct port and Arduino board
what software are you using?
the software I am using in this video is Fritzing
@@WaqasFarooq thanks a lot
Are there other similar free programs like Fritzing?
@@hanscarlosirch8044 you can use tinkercad.com website
@@WaqasFarooq thanks