A very valuable tutorial. Thank you. Also, is there a way to ramp up the speed of the motor to a high Potentiometer setting? I turn on a stepper with a switch and the speed is set by the Pot. If the Post is set for a high speed when the switch is turned on, the motor stalls. Thanks
this is the best routine I have found to manage the movement of a stepper in proportion to the movement of a potentiometer. simple and effective at the same time. I'm using it to move a linear actuator through the signals of an RC receiver. just make a MAP of the received servo signal and convert it to the value of a potentiometer. CONV = map ( S4_SOLLEVAMENTO_In, 1500, 2000, 0, 1023); // S4_SOLLEVAMENTO_In = servo signal in microsec >>>>> to pot value val = CONV; Serial.print(" CONV = "); Serial.println(CONV); //val = analogRead(A4); // Read Potentiometer current value if ((val > previous+6) || (val < previous-6)) { // Check that a move of the pot is at least > or < than 6 newval = map(val, 0, 1023, 0, 444000); // Map value trimpot to total step needed of slide movement // (i use a astepper motor "200 step tourn" connected a gear reductor 40:1 - M20 screw 185 mm long / 74 screw threads / 6000 steps per screw revolution) total 444000 step ) Serial.print(" STEPS TO PERFORM/ NEWVAL = "); Serial.println(newval); stepper2.runToNewPosition(newval); // Move stepper to new position previous = val; // save current value into variable previous Serial.print(" STEPS REACHED = "); Serial.println(previous); delay (2000);
I don't have a tutorial using a potentiometer but you can check out this one: www.brainy-bits.com/dual-axis-camera-slider-using-joystick-in-and-out/ hope that helps and thanks for watching!
Hi I have been trying to get it to work with my tmc2208 and a4988 and it kind of works but keeps stopping after a certain distance also will only travel so far it does travel further if you increase the map value "1600" upwards. I have tried adjusting all the other values with various results but it still keeps stopping and starting and is not that responsive. If you could help me to solve this or even provide the code for a tmc2208 and a4988 instead of the easy driver I would be very grateful. Thanks
I like the code got a couple of questions: Can the rotation of the pot increase as it rotates speed in both directions and how would I put that in the code? Second, can you use a motor driver MA860H? I am creating something for my class and I need to drive three motors. Last, is there a way to create a program that reads joystick input into Microsoft HID Human interface device to send to Arduino?
Thanks for the video! I tried the same setup (except with an a4988 controller) it does work, however it seems as though the turning of the potentiometer is only registered in intervals. Even with the recommended speeds when I turn the pot with the same speed the motor reacts as if I turned it in three smaller parts/steps rather than one smooth turn of the knob. Even microstepping does not alleviate this... Any idea what could cause this?
ı wanna try to find step number of according to the distance. I'll calculate this step number of every 10 mm motion. Your code will help me a lot but how can i see the step number while I turn the potentiometer.
Hi, what if I'd like to use the potentiometer to adjust a number of steps per second? I guess it's just different programming? How fast can these stepper motor (steps per second) go?
thanks Ivan, nice video, Can you please show us some lazer made stuff. I find your lazer cuts pretty fine quality, it must be a co2 module or I maybe wrong. A 2W lazer module wouldn't get these fine edges.
+Hobby at home Hi. You are correct, I use a 50W CO2 laser to make those parts. Can't afford an Epilog or those other brand names ones :) so it's one from china. After making good alignment and changing the Lens that came with it, it's actually pretty good! I'll try to make a video showing off the creation of a new part from start to finish in the future. Thanks for the suggestion and watching btw :)
I would like to be able to do exactly what you are doing here.... but I have an A4988 stepper motor driver. and it doesn't work with this code. I tried and it does nothing. I tested out my driver and motor with a sample code specifically for the A4988 worked perfectly. Any help would be appreciated.
Simple and effective tutorial. I have a doubt to be clarified !! Can we control the speed of the stepper while going the other way around ? For example The motor completes one clockwise rotation in 2 sec when we turn the potentiometer . And while we bring back the potentiometer back can we control the anti clockwise rotation to take 3 or 4 sec to complete the rotation ?
the accelstepper library have some functions that increase or slower the max stepper freq or acceleration - you simple divide the routine in loop in to 2 separate routine -one for val > previous and one for val < previous val = analogRead(A4); // Read Potentiometer current value if (val > previous+6) { // Check that a move of the pot is > than 6 newval = map(val, 0, 1023, 0, 1600); // Map value (1600 = 1 stepper shaft rotation) stepper.runToNewPosition(newval); // Move stepper to new position previous = val; // save current value into variable previous if (val < previous+6) { // Check that a move of the pot is < than 6 newval = map(val, 0, 1023, 0, 1600); // Map value (1600 = 1 stepper shaft rotation) /* then use this function of accelstepper for increase o slower values void setMaxSpeed (float speed) float maxSpeed () void setAcceleration (float acceleration) void setSpeed (float speed) remember to do the same in the first 'if' to bring the speed back to that originally set */ stepper.runToNewPosition(newval); // Move stepper to new position previous = val; // save current value into variable previous
I've done this with two different motors and no matter what I get a little shakiness from the motor. I've done the brainy bits rotary encoder and it's just not smooth for my application... what would be the best way to have smooth control (bidirectional) using a pot-like control.
Check out this other video I did using a Potentiometer to control a stepper: th-cam.com/video/nLkT_SrFung/w-d-xo.html hope it helps, thanks for watching!
Isn't that the same one as this one? I've tried it with the rotary AND the potentiometer and it has some shakiness. I'm creating a wireless follow focus for my cameras since the products out there are outrageously expensive-- $800 What can I do?
it depends on what is causing the shakiness. It could be noise in the system which is what the code is designed to handle. You may need to use a number larger than the 6 that he used. Or it could be that the gain of the control circuit is too high and that caused the system to essentially try too hard. Look at tutorials and read about the AccelStepper library
this code was gud with accelstepper library, but when i m using l293d driver ic how can i change it. i tryed to do but motor stay where it is. here is the code: #include "AccelStepper.h" AccelStepper stepper( 9,11,10,12); int val = 0; int previous = 0; int long newval = 0; void setup() { stepper.setMaxSpeed(4800); stepper.setAcceleration(4800); } void loop() { val = analogRead(A0); if ((val > previous+6) || (val < previous-6)) { newval = map(val, 0, 1023, 0, 1600); stepper.runToNewPosition(newval); previous = val; } } the hardware set up works fine with this code ( for your reference) #include
#define STEPS 200 Stepper stepper(STEPS, 9,11,10,12); int Pval = 0; int potVal = 0;
finally i fond to make it respond, now its turning in both the direction but only a few steps, with lot of small shivering , i change this Stepper stepper(STEPS, 9,11,10,12); to this Stepper stepper(STEPS, 4,9,11,10,12);
Hi thanks for this code, Its the first actually working. However I need to have the code to move to different positioned in the clocks and anti-clocks positions. Would you mind sharing that mod?
Hi thanks for this. This is also the first code actually working. However I need to have different stepper targets in the clocks and anti-clocks directions, would you mind to share it?,
How to Control a DC Motor with an Arduino using the mini shlider L293D and bleutooth hc06 - plllz i reallly neeed it help me please anny way thank you for the videos but please i really need help thank you
+oumaima oumaima Would love to help but don't have or experimented with the L293D, but there's an Instructable available on it here: www.instructables.com/id/Control-your-motors-with-L293D-and-Arduino/ For the bluetooth, I did do a video on using an Arduino with Bluetooth here: th-cam.com/video/XzYllMFjsvQ/w-d-xo.html Hope that helps you get going on your project! Thanks for watching btw :)
you said we should send questions, so here it is; HOW do you go about connecting and controlling the stepper motors that only have TWO wires coming from them.....?
#include "AccelStepper.h" // Library created by Mike McCauley at www.airspayce.com/mikem/arduino/AccelStepper/ // AccelStepper Setup AccelStepper stepper; // Variables to store current, previous and move position int val = 0; int previous = 0; int long newval = 0; int total=0; void setup() { stepper.setMaxSpeed(4800); // Set speed fast enough to follow pot rotation stepper.setAcceleration(4800); // High Acceleration to follow pot rotation Serial.begin(9600); } void loop() { for(int i=0;i previous+8) || (total < previous-8)) { // Check that a move of the pot is at least > or < than 6 newval = map(total, 0, 1023, 0, 1000); // Map value (1600 = 1 stepper shaft rotation) stepper.runToNewPosition(newval); // Move stepper to new position previous = total; // save current value into variable previous } } total=0; }
The tutorial page is now available on our website here: brainy-bits.com/tutorials/control-a-stepper-motor-using-a-potentiometer/ Thanks for watching!
Hi Ivan,the tutorial is not available..
Thank you so much for making this Tutorial. This is the only code that even works for me without jitter drift
A very valuable tutorial. Thank you. Also, is there a way to ramp up the speed of the motor to a high Potentiometer setting? I turn on a stepper with a switch and the speed is set by the Pot. If the Post is set for a high speed when the switch is turned on, the motor stalls. Thanks
you are the arduino brain ,fantastic tutorials !!!
+Serdar xxx Thanks for watching and your comment :)
Thanks so much , you provided a solution to a project to move a router.
this is the best routine I have found to manage the movement of a stepper in proportion to the movement of a potentiometer. simple and effective at the same time. I'm using it to move a linear actuator through the signals of an RC receiver. just make a MAP of the received servo signal and convert it to the value of a potentiometer.
CONV = map ( S4_SOLLEVAMENTO_In, 1500, 2000, 0, 1023); // S4_SOLLEVAMENTO_In = servo signal in microsec >>>>> to pot value
val = CONV;
Serial.print(" CONV = "); Serial.println(CONV);
//val = analogRead(A4); // Read Potentiometer current value
if ((val > previous+6) || (val < previous-6)) { // Check that a move of the pot is at least > or < than 6
newval = map(val, 0, 1023, 0, 444000); // Map value trimpot to total step needed of slide movement
// (i use a astepper motor "200 step tourn" connected a gear reductor 40:1 - M20 screw 185 mm long / 74 screw threads / 6000 steps per screw revolution) total 444000 step )
Serial.print(" STEPS TO PERFORM/ NEWVAL = ");
Serial.println(newval);
stepper2.runToNewPosition(newval); // Move stepper to new position
previous = val; // save current value into variable previous
Serial.print(" STEPS REACHED = ");
Serial.println(previous);
delay (2000);
This gives me the idea to make a huge Etch-a-Sketch!
Good tutorial thank you !! Would it be hard to add a digital display to display a value for the motor speed ?
Make video using a PID with stepper motor, both position , and one with speed. Thanks I like the way you explain things
hey brainy bits -gr8 video..could we also control two stepper motors with one potentiometer so that they both move at same time?
I don't have a tutorial using a potentiometer but you can check out this one: www.brainy-bits.com/dual-axis-camera-slider-using-joystick-in-and-out/ hope that helps and thanks for watching!
Hi I have been trying to get it to work with my tmc2208 and a4988 and it kind of works but keeps stopping after a certain distance also will only travel so far it does travel further if you increase the map value "1600" upwards. I have tried adjusting all the other values with various results but it still keeps stopping and starting and is not that responsive. If you could help me to solve this or even provide the code for a tmc2208 and a4988 instead of the easy driver I would be very grateful. Thanks
Hi can the motor run in the other direction? Instate of same with the potentiometer turn? by using your code?
I like the code got a couple of questions: Can the rotation of the pot increase as it rotates speed in both directions and how would I put that in the code? Second, can you use a motor driver MA860H? I am creating something for my class and I need to drive three motors. Last, is there a way to create a program that reads joystick input into Microsoft HID Human interface device to send to Arduino?
Thanks for the video! I tried the same setup (except with an a4988 controller) it does work, however it seems as though the turning of the potentiometer is only registered in intervals. Even with the recommended speeds when I turn the pot with the same speed the motor reacts as if I turned it in three smaller parts/steps rather than one smooth turn of the knob. Even microstepping does not alleviate this... Any idea what could cause this?
I love your videos. Keep up the good work.
+Pedro Tomas Roa Cuevas Thanks for the comment and for watching!
ı wanna try to find step number of according to the distance. I'll calculate this step number of every 10 mm motion. Your code will help me a lot but how can i see the step number while I turn the potentiometer.
Just what I wanted. Can I use a bigger moor for this, say 100N force?
keep going to educate people. but there are special library for averaging the potentiometer can be used. thank u a lot.
Thank for watching. If you can please share a link to one of those libraries you are referring to. Cheers!
Hi, what if I'd like to use the potentiometer to adjust a number of steps per second? I guess it's just different programming? How fast can these stepper motor (steps per second) go?
good for you....pls where can i get arduino stuff???
Hello, Nice work! I need some help to program that in C on PIC microcontroller. Has anybody seen some source ??
thanks Ivan, nice video, Can you please show us some lazer made stuff. I find your lazer cuts pretty fine quality, it must be a co2 module or I maybe wrong. A 2W lazer module wouldn't get these fine edges.
+Hobby at home Hi. You are correct, I use a 50W CO2 laser to make those parts. Can't afford an Epilog or those other brand names ones :) so it's one from china. After making good alignment and changing the Lens that came with it, it's actually pretty good! I'll try to make a video showing off the creation of a new part from start to finish in the future. Thanks for the suggestion and watching btw :)
I would like to be able to do exactly what you are doing here.... but I have an A4988 stepper motor driver. and it doesn't work with this code. I tried and it does nothing.
I tested out my driver and motor with a sample code specifically for the A4988 worked perfectly.
Any help would be appreciated.
Hi, did you find out how to do that with A4988?👀
How use optical encoder in this project. For DIY dtg printer
Thanks this is a simple effective way to control.
I got a vibrate stepper when a turn potentiometer. Could anyone help?
Simple and effective tutorial. I have a doubt to be clarified !! Can we control the speed of the stepper while going the other way around ?
For example
The motor completes one clockwise rotation in 2 sec when we turn the potentiometer . And while we bring back the potentiometer back can we control the anti clockwise rotation to take 3 or 4 sec to complete the rotation ?
the accelstepper library have some functions that increase or slower the max stepper freq or acceleration - you simple divide the routine in loop in to 2 separate routine -one for val > previous and one for val < previous
val = analogRead(A4); // Read Potentiometer current value
if (val > previous+6) { // Check that a move of the pot is > than 6
newval = map(val, 0, 1023, 0, 1600); // Map value (1600 = 1 stepper shaft rotation)
stepper.runToNewPosition(newval); // Move stepper to new position
previous = val; // save current value into variable previous
if (val < previous+6) { // Check that a move of the pot is < than 6
newval = map(val, 0, 1023, 0, 1600); // Map value (1600 = 1 stepper shaft rotation)
/* then use this function of accelstepper for increase o slower values
void setMaxSpeed (float speed)
float maxSpeed ()
void setAcceleration (float acceleration)
void setSpeed (float speed)
remember to do the same in the first 'if' to bring the speed back to that originally set
*/
stepper.runToNewPosition(newval); // Move stepper to new position
previous = val; // save current value into variable previous
Can you please help me with the code to do the same using PIC16f877a controller?
Do you have the diagram and code for using an Uno?
how can i do that without microcontroller?. with shift registers, mux-demux, analog to digital converter and HC-sr4 sensor. somebody could help me
thank you so much💓
+ابتكر عالمك | almk2 You're welcome :) thanks for watching!
how do you do this without an easy driver? DIR +/- and PUL +/-??
I've done this with two different motors and no matter what I get a little shakiness from the motor.
I've done the brainy bits rotary encoder and it's just not smooth for my application...
what would be the best way to have smooth control (bidirectional) using a pot-like control.
Check out this other video I did using a Potentiometer to control a stepper: th-cam.com/video/nLkT_SrFung/w-d-xo.html hope it helps, thanks for watching!
Isn't that the same one as this one?
I've tried it with the rotary AND the potentiometer and it has some shakiness.
I'm creating a wireless follow focus for my cameras since the products out there are outrageously expensive-- $800
What can I do?
it depends on what is causing the shakiness. It could be noise in the system which is what the code is designed to handle. You may need to use a number larger than the 6 that he used. Or it could be that the gain of the control circuit is too high and that caused the system to essentially try too hard. Look at tutorials and read about the AccelStepper library
Have you put common GND?
Hi I am doing The same thing as you And having The same provlem with The shakes And Steps skipping did you manage to fix IT ?
error compiling with arduino nano exit status 1 NEED HELP ASAP!
i have a arduino uno and i just cant get this code to work i cant find this code dont know where i just wrote it down from yours does not work
cool stuff. now I want to make a stepper etch a sketch.
+brent19731 Good idea! It would actually feel the same as the original. Thanks for watching!
+Brainy-Bits keep the videos coming. nice explanation of the code on your vids.
good job 👌
+Eng.Ahmed al.salhi Glad it was interesting! Thanks for watching!
thank you very much you helps me many
Always great to hear that! Thanks for watching!
this code was gud with accelstepper library, but when i m using l293d driver ic how can i change it. i tryed to do but motor stay where it is.
here is the code:
#include "AccelStepper.h"
AccelStepper stepper( 9,11,10,12);
int val = 0;
int previous = 0;
int long newval = 0;
void setup() {
stepper.setMaxSpeed(4800);
stepper.setAcceleration(4800);
}
void loop() {
val = analogRead(A0);
if ((val > previous+6) || (val < previous-6)) {
newval = map(val, 0, 1023, 0, 1600);
stepper.runToNewPosition(newval);
previous = val;
}
}
the hardware set up works fine with this code ( for your reference)
#include
#define STEPS 200
Stepper stepper(STEPS, 9,11,10,12);
int Pval = 0;
int potVal = 0;
void setup()
{
Serial.begin(9600);
stepper.setSpeed(60);
}
void loop()
{
if (Serial.available())
{
int steps = Serial.parseInt();
stepper.step(steps);
}
}
plz do needfull
finally i fond to make it respond, now its turning in both the direction but only a few steps, with lot of small shivering ,
i change this Stepper stepper(STEPS, 9,11,10,12);
to this Stepper stepper(STEPS, 4,9,11,10,12);
GOOOOd stuff!
Hi thanks for this code, Its the first actually working. However I need to have the code to move to different positioned in the clocks and anti-clocks positions. Would you mind sharing that mod?
Hi thanks for this. This is also the first code actually working. However I need to have different stepper targets in the clocks and anti-clocks directions, would you mind to share it?,
How to Control a DC Motor with an Arduino using the mini shlider L293D and bleutooth hc06 - plllz i reallly neeed it help me please anny way thank you for the videos but please i really need help thank you
+oumaima oumaima Would love to help but don't have or experimented with the L293D, but there's an Instructable available on it here: www.instructables.com/id/Control-your-motors-with-L293D-and-Arduino/
For the bluetooth, I did do a video on using an Arduino with Bluetooth here: th-cam.com/video/XzYllMFjsvQ/w-d-xo.html
Hope that helps you get going on your project! Thanks for watching btw :)
you said we should send questions, so here it is; HOW do you go about connecting and controlling the stepper motors that only have TWO wires coming from them.....?
want it so badly
best thx and like
#include "AccelStepper.h"
// Library created by Mike McCauley at www.airspayce.com/mikem/arduino/AccelStepper/
// AccelStepper Setup
AccelStepper stepper;
// Variables to store current, previous and move position
int val = 0;
int previous = 0;
int long newval = 0;
int total=0;
void setup() {
stepper.setMaxSpeed(4800); // Set speed fast enough to follow pot rotation
stepper.setAcceleration(4800); // High Acceleration to follow pot rotation
Serial.begin(9600);
}
void loop() {
for(int i=0;i previous+8) || (total < previous-8)) { // Check that a move of the pot is at least > or < than 6
newval = map(total, 0, 1023, 0, 1000); // Map value (1600 = 1 stepper shaft rotation)
stepper.runToNewPosition(newval); // Move stepper to new position
previous = total; // save current value into variable previous
}
}
total=0;
}