28BYJ-48 stepper motor and ULN2003 Arduino (Quick tutorial for beginners)
HTML-код
- Опубликовано: 4 окт 2024
- In this quick Arduino tutorial, I will show you how to use 28BYJ-48 stepper motor with ULN2003 driver. Because this is a quick Arduino tutorial we will focus on the most important things you need to know to get it working in 5 minutes. Enjoy!
28BYJ-48 with driver: amzn.to/3gAN2qH
Arduino: amzn.to/46EsjKx
Code: github.com/Nik...
Support my projects on Patreon → / nikodembartnik
My gear:
Camera: amzn.to/3VdbfGH
Lens: amzn.to/44nY2z0
Better lens: amzn.to/424iuCX
Tripod: amzn.to/3Nh2Cca
3D printer: amzn.to/3QzHhfc
Label printer: amzn.to/3oW55yn
Headphones: amzn.to/3LDTXz6
Speakers: amzn.to/3nl34eJ
Oscilloscope: amzn.to/3HmGMjN
Lab bench power supply: amzn.to/3HpotdD
Soldering station: amzn.to/3Vd39xH
This is the second video of my Arduino tutorials about basic sensors and output devices that you can use with Arduino. I want to keep all of them under 5 minutes to make them short so that if you want to use something in your project you can quickly go through the tutorial and start making your own project.
Instagram: goo.gl/JLFLtf
Does the job perfectly. I'm going to use it to feed my cat with an endless screw
a true legend
Great Tutorial. I could not initially get the project to change from the anticlockwise loop to the clockwise loop. The motor would pause then move again in the same direction. I changed the delay to 3ms on just one loop and it corrected the issue. I was originally powering the motor directly from the arduino and wondered if this was the issue. I introduced a 12VDC power supply to power the stepper motor direct, altered the delay back down to 2ms and the motor now changes direction as desired.
Jestem stary chłop i w sumie to zaczynam się bawić w mikrokontrolery. Dzięki za ten film i proste wytłumaczenie.
I cant wait. Just bought a beginner arduino kit. I have almost completed an internal security lock for a van on my 3d printer with wireless control. I work doing car keys and mechanics plus auto electrics. Im so excited to be able to make electro mechanical things. Solar panel raiser for sunshine passing. Remember that word sunshine 🌞
I discovered a HUGE increase (maybe 10 times) in torque when I changed the delay from 2 to 5 on my clone Nano (even 3 made a huge difference). If the power output seems low, try delaying it a bit more. Perhaps the clock speed is different or something on the clones, or perhaps it's just a Nano thing.
I'm making a grappling hook thingy, and I sure hope what you said will work cuz I need a high enough torque to overcome a rubber band
Edit: Alright dude, I tried it already, and it WORKED PERFECTLY THANKS SO MUCH
@@cucumber1389 Awesome :)
@@cucumber1389 Send a link to what you make, I'd love to see it. I think this is the first time I've helped someone with Arduino. I used to blog at 120thingsin20years.blogspot.com where I tried to learn a new thing every 2 months for twenty years. I didn't quite make it, but I always tried to contribute at least one thing to all the amazing things people educated me about. Anyway, I'd love to see your grappling hook. It sounds like the kind of thing I would have liked to invent myself :).
@@craigkirby9202 uhh, how do I put this, sorry to dissapoint you, but I failed... So basically at first, the stepper did manage to draw back my linear gear fast enough and strong enough to over come the rubber band, but when I realised that it needed a slightly larger force to fire the hook, I changed the rubber band, which made it impossible for the stepper to pull back the gear. I would still send it to you, if you'd like. I know that what I'm about to send you shows quite a bit of design flaws but I tried to use recycled materials. Anyways I'll show you now
Edit: How do I send stuff to you via your blog, sorry Ive never actually used a blog before
Edit 2: I'll just put the link to a post I made about it a few days ago instagram.com/p/CC8mW7_HeL8/?igshid=1jffo6ln5q6n8
@@cucumber1389 I dont have an instagram account. I try to limit such things. I have a gmail account kirby.craig@gmail.com that has over 10,400 unread emails that I keep for such stuff as this :) . I normally dont check it, but if you send something to that email address, then make a comment here, I can go back to the right time and date and find it.Just add something in the subject to help me find it. Almost all that mail in my inbox is junk, because every time you post an email address you get an insane amount of spam. But send to that address, then post here that you have sent me something, so i know to look. I'm happy to help in any way I can, but understand, I'm pretty new to this stuff.
Thank you so much it works without interrupting the other functions. love it from Philippines.
The reason why it seems to have 2048 steps and it's so slow is that it has a speed reduction gearbox to increase the torque and the number of steps. It's 1:64, IIRC, which means that for each 64 revolutions of the actual motor, there is one revolution of the shaft. The actual motor actually has only 32 steps!
That's right
@@nikodembartnik Hey can I get to know the changes to make to run the motor for 4 rotations & then make it stop....
First time using 28BYJ-48 stepper motor with ULN2003 driver board. Worked first time. Would recommend using external 5VDC power supply though instead of loading down the Arduino power supply. Thank You.
wow dude good video, you explained the important stuff better than any other place, specially the simple math and how the steps work
If you want to get really down to the nitty gritty, you can hook this up to a decade counter which is triggered with a 555 timer.
Nicely explained.
I would recommend:
-clarify for people that connecting any motor to the arduino directly, for power, could kill the arduino.
-ULN2003 requires some specific connection between common, ground, and the driving signal.
These 2 notes would help newbies to not damage their arduinos (note 1) and to get their experiment working (note 2)
I'm sorry, brother, could you help me connect 5 of those engines that are in the video, but in the correct ports, esque just connect 1 but 5 do not know how
I'm using an arduino mega r3
I would really appreciate it
Why is it bad to directly connect?
What do you mean that connecting it directly for power could kill the arduino. Are you saying that the vcc shouldn't be connected to de 5v in the arduino board?
@@BlackBirdJacobo too much current. Arduino boards output only about 40mA - 60mA per pin, which is an absolute fraction of what is required for any small motor like this.
@@paulraymond1804 You not driving the stepper directly from the Arduino pins, but via the uln2003. The 5 volt supply is taken from the Arduino supply and not from one of data pins. Furthermore there a Vin point which basically comes directly from input voltage supply even before the arduino 5 volt regulator.
A lot more information then what is in the datasheet. Thank you.
I increased the amps of my power supply and changed it to 3ms and it increased the torque so much.
Thanks man. Made it easy to get started. Ur making the world smarter!
Works great and video + code were easy to follow and understand. Thanks a bunch !
if anyone wants a more compact code:
int INS[] = {9, 10, 11, 12};
void setup() {
for (int i = 0; i < 4; i++) {
pinMode(INS[i], OUTPUT);
digitalWrite(INS[i], LOW);
}
}
int i = 0;
void loop() {
digitalWrite(INS[i], HIGH);
delay(2);
digitalWrite(INS[i], LOW);
i = (i+1)%4;
//you can change it a bit so it goes in the opposite dirrection
}
I do think your English has improved in the newest videos. Thanks for this video
thanks for this , now im ready for the step motor project
thx bro... well explained and solved my problem
I am happy that you like it!
@@nikodembartnik JESUS IS THE KING OF THE KINGS
exactly what i knew the instructions would be missing
the function to move the motor with the high and low digital writes can be more simple if you do this:
void rotMotor(int ar[],int h){
for(int i = 0 ; i < 4 ; i++){
digitalWrite(ar[i],LOW);
if(i == h){
digitalWrite(ar[i],HIGH);
delay(2);
digitalWrite(ar[i],LOW);
}
}
}
You are right, but that way it will rotate slower tho
@@3dmixer552 actually i tried it and it rotates at same speed
@@DaniiTheFox I didn't try it but because of the for loop it should be a bit slower. Not much tho so probably not noticeable
@@3dmixer552 you can always use while instead of for XD
Thanks! is there any way to make the motor controlled by a button?
I wanted to know the same thing. Or be controlled by a motion control curcuit
Yes
Pretty simple. Pretty good.
thanks man!!!!
Well bless your heart for such a clear and good presentation. Very helpful; Thank you.
Thank you very much !!! helped me a lot in my project.
From DataSheet: Stride Angle 5.625° /64
in this stepper motor yields 64 steps per rev?
Am I wrong?
Informative, Short But it explains enough. Great Tutorial 👌
Please make a video on Circuit diagram of transister based controller used in printer.
.
This was a great help, thank you
Thanks, your code also works with 24BYJ48 stepper motor
Thanks for the clear tutorial! How slow can this stepper motor be programmed to turn a full revolution? Using it to move a model railroad turntable to a precise position (either in F/R direction).
If you have the digitalWrite in a while loop with a counter you might get lucky but you should use a sensor to turn until triggered, that way a power outage won't mess up position.
perfect. Exactly what I need. Thanks a lot
Thanks for the simple explanation, could you help with an idea?
I would like to replace the stepper driver and motor with an arduion to read the signals then give forward or backward power to a dc motor, variable speed would be nice but just fwd/off/bwd would help me start.
can we use the 28byj-48 stepper motor in replace for a dc motor? when I saw in the vid it looks impossible.
@Nikodem Bartnik Its urgent question
Please could you tell me how to drive the motor with other Stepperdriver moulds like TMC2130 for example 🙁 I,ll be happy for answering my question as fast as it possible
Hi I came here since I had a problem in my code, turned out I thought of something, and so thought I had already typed it but I hadn't typed it yet. found it after discovering it wasn't my custom hardware's fault by running your code. I found that it might be helpful for some if I publish my code here since my code is much more compact(less memory), and especially is a lot less compute intensive. it also has half stepping which in this case allows for a higher speed of around 20 to 25% based on the max speeds(I use 0.8ms per step using the same stepper motor, and it is stable under load while the other code here could work at 2ms per step but would stop or become unstable under slight load.
it currently uses pin 8,9,10,11. however it can use other pins as well by changing the register or by changing values in the byte array vals where the most right bit is pin 8, the one left to that 9, etc. this goes on until you are at the 6th bit(bit5, or pin 13), the 2 left of that are not connected to a pin in PORTB
CODE:
unsigned long TimeOfLastStep=0;
unsigned long TimeNow=0;
int step=0;
int delayPerHalfStep=800;//for me min delay(max speed) is between 700 and 800 for 5v(custom driver with less loss)
byte vals[8]={0b00000001,0b00000011,0b00000010,0b00000110,0b00000100,0b00001100,0b00001000,0b00001001};
void setup() {
DDRB=DDRB | 0b00001111;//only set 8,9,10, 11 as output do not change rest of pins.
PORTB=0b00000000;//simplified from only turning of 8,9,10,11 to turning of all of portb
TimeOfLastStep=micros();
}
//1 microseconde =0.001 miliseconde. 1 milliseconde= 1000 microseconde
void loop()
{
TimeNow=micros();
if(TimeNow-TimeOfLastStep>=delayPerHalfStep) //altijd TimeNow-TimeOfLastStep >= interval. dit is de enige van de 4 basis versies die niet kapot gaat uiteindelijk.
{
TimeOfLastStep=TimeNow;
PORTB=vals[step];//PORTB is the location of port 8, 9, 10,11,12,13. by doing this I directly update all of them at the same time, this is a lot faster than digitalwrite and allows you to easily set which bits/pins to enable in what state in a array. originally I did this using cyclic bitshifitng, but this would probably be hard to understand for many people.
step++;
if(step>7){step=0; }//resets state
}
}
:END OF CODE
This code is not perfect by far, I simplified it a lot to keep stuff that looks complicated out, it could be done with faster code, less memory, etc. and especially it could be done a lot safer, since this code overrides all of the bits in portB which means that the unused pins of portB become practically unusable. it is easily fixable by using PORTB=(PORTB&0b11110000)|vals[step]; instead of PORTB=vals[step]; this fixed version would only reset pin 8,9,10,11 before writing the new values to them. but that code would be a lot harder to understand for many I estimate, since it does multiple things in one line. also I didn't add a bool for the direction since it was just meant to test stepper motors and their behaviour under my custom driver which is a part of a more complex universal driver I am working on, however by changing step++; to step--; and if(step>7){step=0;} to if(step
Thank you for the great tutorial! Could you explain how to adapt this set-up for two stepper motors?
sketch_sep29a\sketch_sep29a.ino:1:27: fatal error: PIDController.h: No such file or directory that appears to me what is the solution please
I don't think you are supposed to drive this motor at 12V. This motor comes in two versions, one 5V and another 12V. So the 12V option on the driver is probably for the 12V version. I also tried to raise the voltage to above 5V on the 5V motor and it did overheat.
Are you sure about connections?
You bought the kit "Quad Store Super Starter Kit"............Am I right.
I have the same kit with me.
No need to have a separate power supply for the board and the driver? Thank you. I just started learning arduino. Your video is a great help :)
since it's low on the voltage requirement, you can just use the 5v from the arduino. Would be better on a protoboard so you can understand what's going on.
You will possibly burn your arduino power supply. Use external one for good measure
The lights of the ULN2003 are not turned on like they are in the video, what could this be? Lights on Arduino Uno board are on and the light for pin13 is blinking.... Just started with Arduino so I know nothing :P
working perfectly thanks
Lovely and concise tutorial. Thanks.
Well written code. Makes it easy to modify :)
How to control it more precisely, so it just doesn’t spin but stays and moves as I order it?
Okay, please hear me out and help me. So I can get the Motor to vibrate. But it doesn't do anything else just vibrates. Idk if it is because I have a different driver board with no in1-6 pins. It just has the letters DCBA in that order. What to do?
Well explained, thanks !
the code don't work with me, can you help?
Thanx that really helped me, a great tutorial.
Hi can you please explain the conditions you wrote for the for loop in the void loop function, please reply urgently if possible
Thanks for your demonstration. I also try this. And how to stop the motor? I need to unplug the cable, or?
Good vídeo, you can reduce wires using the CI L297
Yes, but with dedicated driver it is easier to use for beginners.
sorry noob question as I’m just starting to play with arduino.
Once you’ve programmed it with the arduino, you can disconnect the arduino and the stepper motor will be a standalone circuit ?
Great Tutorial this is the first one I could follow with success, other videos by many channels I could not follow with success.
One question as well if you could kindly answer.
Is it possible to stop the motor for 5 second at the end of clockwise rotation. And then stop for 5 seconds after anticlockwise rotation?
Sorry, I have no idea about the programming, I just bought the kit to do something new.
Thanks, man I was trying many codes but none of them worked
Here you can buy this motor with a driver: amzn.to/3gAN2qH
Support my projects on Patreon : www.patreon.com/nikodembartnik
hey is this the fastest it can go ??? cuz it is pretty slow
Once it is moving, is there a method to interrupt making it stop?
Nice bro. Now my project can rotate now. Yessssssss :)
Thanks! That's great :)
thx, my bridge is possible now
i use this code but i dont know why my stepper motor can't rotate , it just vibrate
Please increase the delay.. to 50 or 100 then check
@@ahmadraja5589 alright 👌 I'll try it soon
I solved this by increasing delay.
so, how would i make this work with a button
How do you control 2 stepper motor I saw the datasheet there's a cw and acw on rd2 how about the other wheel if not the wheel will lock at one location I'm using mplab for pic18f4550 instead of arduino
How do we change the speed in the code? thank you in advance.
well. Doesn't think he appreciated that thank you, ahah. But for real, I need the same answer so someone help!
I found out how. Just change the delay. But minimum is (2) which I found more than enough
I am actually doing this in C#, it works perfect with the case switch, but I wonder if there is any way to set the speed
What software are you using?
I’m on a Apple Mac & I’ve found pololu tic but can’t find driver in usb so says not connected
Wella explain, but you should use and external power supply to that motor, you could fried the Arduino
Why you don't use the library ?
does it work for arduino mega 2560 or just uno?
I can't get your code to work
If you have two different types of stepper motor with different Steps can you use it in single project together like in cnc or 3d printer ?
Thanks for the Info. Nice job on the code an the tutorial. Keep up the good work.
Is it necessary to connect it to a driver? Why not connect it to the arduino directly?
Hello great work, can you put two buttons to command the movement, instead of doing it in loop?
Thanks to you!
How many years has passed, but may I ask you one question?
This is what I really wanted
I want to slow down a bit.
But I don't know Arduino well and don't know how to fix it ...
Can you tell me how to slow down?
can you help me please? i only changed the void loop part to this:
void loop() {
n = analogRead(ldr);
n2 = analogRead(ldr2);
if (n > 500){
OneStep(false);
}
else if(n2 > 500){
OneStep(true);
}
delay(2);
return;
}
my goal was to make the motor move back and forth depending on which photoresistor (n value) that got the light.
whole code is verified but there is no progress.
Beautiful. Thank you so much
will the stepper motor only work if we connect the driver pins to 9, 10, 11, 12 on the arduino? Or can we use other arduino pins?
edit 4 years later: yes we can.
can somebody explain to me, why 2ms is minimum and why when you have 4*0.002s*64=0,512sec , but the motor needs 4sec?
hey thanks for the video but i got a problem it gives me an error that says; "OneStep was not declared in this scope". what do i do? I checked the code 5 time to see if i did any mistake but no.
how to control steps movements, like lets say we have 400 circular points to move one by one and i need to move pointer in following example sequence starting from 0->10->240->45->28-> .......... -> 400 . How can we automate this ..
hi, how much weight (kilos) can this motor lift?
Very useful !!! Thanks !
I have the same stepper motor. I connected it and wrote the code, but it only vibrates. No rotation.
same here. Would be great if anyone has a fix
is the speed limited by the motor or the controller?
The 2ms delay/step is too slow for me.
Clear explanation. Thanks.
what is 28BY J-48
Well explained. Thanks.
Thank you!
Hello, I followed your schematic, and as soon as I plug in the USB cable, my Arduino UNO or MEGA fades out after 3 seconds. What am I doing wrong? Not even the ULN2003 lits up.
what you describe sounds exactly like what arduino does when you short-circuit its gnd and 5v connections. I would recommend you to check your wiring
@@cafemm Thank you for your answer, it really was the cause! I have no idea why the heck I swapped them here.
works great!!
but only rotates in one direction..
it is same with me, what can be the reason? Did you find it?
thanks for the vid!
help
when i program it to turn 180 degrees it displays this error
exit status 1
initializer in range-based 'for' loop
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
while(1)
{
// body of the loop...
} // this can loop any code just put the code inside.
Quick and effective...
Thanks!
I'm pretty sure you're not supposed to power the motor directly from your arduino
Strange behavior on mines...
Using half-stepping.
I use PORTB instead of the awfull digitalWrite...
Delay of 2 ms motor is turning ok.
Delay of 4 ms motor stays still ??? same for delayMicroseconds(4000).
Delay of 8 ms motor is turning ok again...
Can you run the motor without a PC and directly powered from a DC source like a mobile power-bank?
can you post the code for moving clockwise/anticlockwise, please!?
Can you make humidity sensor with LCD display via arduino? It's popular but they are using nano arduino though.
Love ur accent