Simultaneously Controlling Stepper Motors with Arduino
Ғылым және технология
This is an example that demonstrates how to simultaneously control two stepper motors with an Arduino Nano.
👉Subscribe for more robotics and engineering tips:
/ @theboredrobotllc
Share this video with a friend:
• Simultaneously Control...
Parts needed for this example:
Arduino Nano: amzn.to/3DgG3LO
USB Cable: amzn.to/3uBAwf5
Sparkfun Stepper Motor Drivers: amzn.to/3dNQv30
Screw Terminal Blocks: amzn.to/322Klqi
PCB Board with Header Pins: amzn.to/39YvKQW
Jumper Wires: amzn.to/3s4gKXS
8x AA Battery Holder: amzn.to/31XfsU6
AA Batteries: amzn.to/3d268V5
Breadboard: amzn.to/3uE28QU
Soldering iron: amzn.to/3d7zYrp
Stepper Motors: amzn.to/3YWZmWD
Disclaimer: This video contains affiliate links, meaning that if you make a purchase from one of the product links, I'll receive a small commission.
Пікірлер: 75
This was so helpful. Thank you so much. I'm building a multi axis camera slider with arduino, and now i'm able to use both axis at the same time. I hope you will get more attention in the future.
@TheBoredRobotLLC
2 жыл бұрын
Thank you! I'm glad it helped.
@BTMECMAYANKRAJ
10 ай бұрын
can we connect, i am making xy 2 axis movement for some image processing
This is one of the first videos I have been able to find that will run two stepper motors at exactly the same speed, great video
@TheBoredRobotLLC
8 ай бұрын
I'm glad you liked it! I also did another version with a library. Check it out here: kzread.info/dash/bejne/g4Z32KVuqMuwc9o.html
I am trying to control two stepper motors using arduino uno and tb6600 motor drivers and control them using Radio controller . However when i run my code only one stepper motor work while the other doesn't receiver input signals from transmitter
@TheBoredRobotLLC
Ай бұрын
It's hard to say without knowing more. My first step would be to check the wiring and make sure that each of the motors runs individually first.
How Do We Stop This Motor After FEW Rotation Also One Motor Should start BIT later can u help on this
@TheBoredRobotLLC
3 жыл бұрын
For the rotation question, keep a counter of how many steps the motor has taken. If you know the number of steps per rotation, you can stop the motor after a certain count has been reached. Otherwise you'll need an encoder. To start one motor a little later, the simplest way is to have a "while" or "for" loop inside of the setup() that only runs one motor for a certain number of steps. Then run the same simultaneous code in the loop(). There are a number of other ways to do this efficiently as well.
Hi I want to control 14-15 motors I that possible? Thanks
@TheBoredRobotLLC
4 ай бұрын
If you want to control all of them independently, you certainly can't get away with an Arduino Uno. You would have to look into more professional options, possibly a mega, or multiple boards.
Hi - thanks for this! Interesting - with a standard CNC shield with DRV8825 driver and 3 Nema 17 steppers, I actually changed from millis() to micros() which actually gave me full range of speed control . (Couldn't get it to run under millis()) So - able to run the three simultaneously at different speeds - perfect! On the board you set MO/1/2 via jumpers so no control there after set up.
@TheBoredRobotLLC
2 жыл бұрын
Thanks for the insight! It makes sense that your get more control with microseconds vs milliseconds.
@fernandopalacio4026
Жыл бұрын
Podrías compartir el codigo con todos?? yo tb necesito mover 3 ejes simultaneos. mil gracias!!
How do I program the Microstepping on the CNC shield / Arduino Uno. I see the pins on the shield but dont know which pin it is connected on the Arduino and how to program ?
@TheBoredRobotLLC
5 ай бұрын
Do you have any sort of documentation for the shield? Often times it'll tell you in the datasheet.
Hi, could you set this up using RC pwm control input that sets a high and low position for the stepper motor? Thanks
@TheBoredRobotLLC
10 ай бұрын
Yes, the code would be similar. You can read the signal in the same way, but just but a limit on what would be considered HIGH and LOW.
i want to ask, could we use just one driver A3967 for dual motor stepper nema 17? and why you don't use a driver L298N for this video?
@TheBoredRobotLLC
6 ай бұрын
That driver should work for stepper motors. You just have to confirm that the current of the motor doesn't exceed the limit of the driver. I used this driver, because it just happened to be the drivers that I had laying around when I decided to make the video.
mai 2 motor JK42. and 1 motor JK57. Model ka CNC shield aur DRV 8825 ke dwara chala raha hu to usme poblem ye hai ki JK57 sahi chalta hai but JK42 Sahi nahi chalta our unki DRVbhi jyada heat ho jati hai jabki JK57 KI DRV heat nahi hoti
@TheBoredRobotLLC
2 жыл бұрын
My apologies, I'm not able to understand the question.
hi can you help me please ? i have 2 stepper motor nema 17 i have a code run them in deffrent speed and deffrent rotation revolotion but i can make them run together do you get what i mean ? thank you best regard Ali
@TheBoredRobotLLC
2 жыл бұрын
If I understand your issue, you're having trouble running two stepper motors at the same speed. I believe the code posted in this video should help you out. If you need more details, feel free to contact me here: www.theboredrobot.com/contact
The female header pins for connecting could you further explain???
@TheBoredRobotLLC
2 жыл бұрын
I needed a way to connect the stepper motor driver, which has male pins, to screw terminals. So, I get female header pins and solder them to a perforated prototyping board. Then I solder a direct connection on the board to the screw terminal blocks. I have a more in depth description here: www.theboredrobot.com/post/simultaneously-controlling-stepper-motors-with-arduino
I can now see how I could run the path of a cirle on a flat bed machine using 2 motors, but I'm wanting to take it a stage further and run the path of an oval, I guess you would need to vary the speed of each motor to elongate to an oval using trig functions, do you have any clues or ideas as to how this might be achievable ?
@TheBoredRobotLLC
2 жыл бұрын
That seems like a challenging problem. My first approach would be to explore the parametric equations for an ellipse.
Hi again - I'm getting through the functions now and it's working great so far. I was wondering if you had any plans to create a function have simultaneous move of 3 axes to the endpoint - sort of thing for a polar-coordinate based robot movement?
@TheBoredRobotLLC
2 жыл бұрын
I didn't have any immediate plans for a 3 axes system, but that's certainly something that I would consider in the future.
@ardespmaker
2 жыл бұрын
@@TheBoredRobotLLC I have followed your original structure and have got it working fine with 3 axes. Didn't seem to slow the system down any and they run together at different speeds seemingly without interference. Thanks again for your library! Cheers
@fernandopalacio4026
Жыл бұрын
@@ardespmaker
@ardespmaker
Жыл бұрын
@@fernandopalacio4026 Hi Fernando - moving of 2 axes is already in the library. What I did was to expand that (copied the routine) and added code to take account of a third axis. Basically as you go from one step to the next you see which axis has furthest to travel. This axis stays at the normal speed. The other 2 axes then have their speeds reduced by the ratio of their distance to that of the longest distance. In the same routine I also move 3 servo motors. So from a file with the robot going from step to step I have the full position moves for each motor line by line. The total move sequence is set into an array and the relative calculations made. Sorry, but I don't know how to send the code.
@fernandopalacio4026
Жыл бұрын
@@ardespmaker Hi steve, perhaps sendint it to my email?
Can we handle it from the control panel, because in my project first one is running and stopping, then the other is running and stopping, can we make a control panel for these round numbers kontrol panelinden halledebilirmiyiz , çünkü benim projede önce biri çalışıyor ve duruyor , sonra diğeri çalışıyor ve duruyor , bu tur sayıları için kontrol paneli yapabilirmiyiz
@gokhanozden2347
2 жыл бұрын
first one makes 3 laps to the left, waits for 15-20 seconds, while waiting, the other makes 4 laps, then the first running engine makes 3 laps to the right, a project like this önce biri sola 3 tur atıyor 15-20 saniye bekliyor , beklerken diğeri 4 tur atıyor , sonra ilk çalışan motor sağa 3 tur atıyor , bu şekilde bi proje
@TheBoredRobotLLC
2 жыл бұрын
I would have to know what type of control panel you're talking about, but it's certainly possible to control stepper motors with something outside the Arduino IDE.
@TheBoredRobotLLC
2 жыл бұрын
For behavior you described, you wouldn't even need to use the method described in the video. You could get away with counting steps and using delays, since the motors aren't running at the same time.
Great channel!!
@TheBoredRobotLLC
3 жыл бұрын
Thank you!
Does we can drive as slow as 1 rpm with the smoothest and most stable torque by use steper motor ?
@TheBoredRobotLLC
2 жыл бұрын
Yes, you should be able to get as slow as 1 rpm with a stable torque. You might need an encoder to verify the speed.
great but how?, the pulses are not delayed!, it immediately goes LOW
@TheBoredRobotLLC
2 жыл бұрын
Thanks for the question. The point of this example was to show how to avoid using a delay, as it will delay the entire program and you won't be able to run the motors at different speeds. What I'm actually doing is keeping track of how much time has passed and saving it to a variable. If a defined amount of time has passed, I send "HIGH," and reset this variable. This is done independently for each motor.
For the Arduino nano link, you have a link to this video, not where to purchase it
@TheBoredRobotLLC
2 жыл бұрын
Thanks for catching that! I've fixed the link.
Very Powerful , very thanks
@TheBoredRobotLLC
2 жыл бұрын
Thank you!
can different stepper motor driver be used like a4988 or drv8825
@TheBoredRobotLLC
2 жыл бұрын
I've used the A4988 driver with similar code and it works fine. I don't have any reason to believe that the DRV8825 model wouldn't work with this code as well.
Hi. Nice video. Thanks I have two profiles of rpm vs time. I want two steeper motors to work together, each on a separate profile. How do I do this? Thanks, Paul
@TheBoredRobotLLC
Жыл бұрын
In order to change the speed of the motors over time, you might want have another set of timer variables to keep track of the absolute time. Then you would adjust the motor speeds depending on how much time has passed. I would not use delays in this case.
@paulmanhart4481
Жыл бұрын
@@TheBoredRobotLLC Ok. Thanks. Are stepper motors right for this? It’s a roll roll gimbal, with one axis rotating through several revolutions and the other axis going from about -80 to +80 degrees. I have a mental design for the gimbal, but am unfamiliar with motors or controls. I have equations that represent the rotation speed of each axis as they work together. Can I put the equations in to the software so it can evaluate the speeds real time? Or maybe the derivative for the relative changes in speed. .
Hi, great video. I'm very new to arduino and having a bit of trouble understanding the basic language used in arduino. Im used to programing cnc machines but cant grasp this. I'm trying to get a motor on each end of a shaft, and then rotate it at 120 degree intervals, can I get the 2 motors to rotate in different directions but by the same amount using arduino? Have you got a text document for the programing anywhere that I could use to understand this (I've watched video but not clear enough to copy). Many thanks
@TheBoredRobotLLC
2 жыл бұрын
I wrote a blog entry to go along with this video: www.theboredrobot.com/post/simultaneously-controlling-stepper-motors-with-arduino For your problem, are you trying to have two motors spin the same shaft? If so, you use the same step signal to initiate the movement for both motors. For the direction, the "DIR" pin on the controller should be sent a HIGH value for one of the motors and a LOW value for the other motor. I don't know the application, but perhaps an alternate solution would be a single motor on one end and a stable bearing on the other end of the shaft.
@kiranshashiny
5 ай бұрын
I got a 404 Page not found ! message. So please upload sketch and give the link.@@TheBoredRobotLLC
Thank you for sharing :)
@TheBoredRobotLLC
2 жыл бұрын
My pleasure!
hi Is there a way with the millis() for the stepper motor tourn only one revolution?
@TheBoredRobotLLC
Жыл бұрын
To turn one revolution, you'll have to keep track of the steps. Your motor datasheet should tell you how many steps there are for one revolution. The millis() function is related to the motor speed.
@benbenameur8429
Жыл бұрын
@@TheBoredRobotLLC you mean i can ?
@TheBoredRobotLLC
Жыл бұрын
@@benbenameur8429 It is possible to turn one revolution, but the millis() function doesn't really have anything to do with how much it turns. In this particular code, it has to do with the time between steps.
Hi SR. I need to control 4 motor to clock wise position and 4 anti clock wise at the same speed 5 RPM. Is it possible with an arduino nano?
@TheBoredRobotLLC
2 жыл бұрын
It depends on how you want to wire it up. With that many actuators, you would probably run out of pins. But since they are all going at the same speed, you may get away with sharing pins for multiple motors. I recommend planning it out with a circuit diagram first.
Do you have a circuit for connecting using A4988 Drivers instead?
@TheBoredRobotLLC
2 жыл бұрын
I don't specifically have a post on the A4988 drivers, but the wiring is nearly the same. You're welcome to message me here if you have any specific questions: www.theboredrobot.com/contact
how can i reverse motor rotation?
@TheBoredRobotLLC
2 жыл бұрын
You can reverse the direction by changing the signal being sent to the "DIR" pin on the motor driver. If it's "HIGH," send a "LOW," or vice versa.
How many volts do I need to control these two motors
@TheBoredRobotLLC
3 жыл бұрын
I used 12 volts to get these motors running in this example.
@ntsanjeewadesilva5392
3 жыл бұрын
@@TheBoredRobotLLC hi can u tell me how do I stop this moth motor after few rotation also I need one to start BIT later than other one
Can I give me some sample pls I m really new to this
@TheBoredRobotLLC
3 жыл бұрын
You can contact me here: www.theboredrobot.com/contact
can communicate with you outside Facebook , because i haven't account on it
@TheBoredRobotLLC
2 жыл бұрын
You can contact me here: www.theboredrobot.com/contact