Control Stepper Motor with Arduino - Tutorial

preview_player
Показать описание
today i will guide you how to control a stepper motor with an arduino and a4988 stepper driver,
we will see how to control its rotation speed with a potentiometer, and change its direction of rotation with a push button.
components we will need;

a stepper motor,
an a4988 stepper motor driver,
an arduino board,
a 100k potentiometer
push button
100mf capacitor
breadboard and connecting wires.

i have also written a code to run the motor on various speeds using a potentiometer to adjust the motor speed.

you will find all the diagrams and arduino files here:

NOTE: arduino code is in folders above schematics :)

buy stepper motors for cheap here:

buy links for parts:

(Global):

India:

the A4988 stepper driver module has total 16 pins

the vmot and ground pins are for the external power for the motor,
you cannot power the motor from the arduino as it requires a minimum of 8-35 volts
i use a 12 volts 2 amp external power supply. make sure you use a decoupling capacitor to avoid any unnecessary noise.
the next 4 pins are of the stepper motor.
you have to connect the pins with the right polarity, otherwise your motor wont work and make loud noises.
you can determine the polarity of the motor using your multi-meter
Each pair of same phase should have no resistance when measured with a multi-meter, so you have to check the pairs which have zero resistance
and connect positive and negative of phase A to 1a and 1b, and accordingly for phase b

it is better to check the polarity in the manufacturer information for your motor to avoid this hassle.
you can also connect multiple stepper motors for similar actions in parallel until you do not exceed the current limit

next you have to connect the reset and sleep pin to activate the driver.
the a4988 uses 3.5-5 volts power so you can power it from the arduino 5v output
connect the digital4 pin of the ardiuno to the direction pin and d3 pin to step pin of the driver.
the ms1,2,3 pins are for enabling microstepping.
you can connect 5 volt input to the pins to enable microstepping. there are 5 different modes for micro-stepping as shown in the table.
it is also important to limit the current to the motor.
you can do so by setting the potentiometer on the driver to around 30 degrees clockwise for 0.5 amps

first we will run a simple code to run a full rotation and pause for 1 second.
upload the code and you see the motor running.
if not,make sure you have connected all pins correctly. and followed all the procedures

i have also written a code to run the motor on various speeds using a potentiometer to adjust the motor speed.
you have to connect the potentiometer wiper pin to a0 pin of the arduino, and connect 5v input in the first, and ground the third pin
i have another code in which you can toggle the direction of the motor using a push button.

hope you enjoyed the video, please do like share and subscribe, and thanks for watching!

check out my other projects:

#steppermotor #steppermotorcontrol #steppermotortutorial #howtocontrolsteppermotor
Рекомендации по теме
Комментарии
Автор

Again, a great How-To!

After some double, triple and quadruple checking of the provided Nema17 to driver cables, I got everything setup, loaded your sketch and successfully tested all eight Nema17 steppers and all eight A4988 driver boards. All good to go for a future project!

Thx, this was much simpler than testing with the CNC Shield. Now if something isn't working, I'll know it is the CNC Shield or the coding and not the Nema17s or A4988s.

KWHCoaster
Автор

Great! I ordered eight Nema17 steppers and some driver boards and I was looking for a quick setup to test them before shelving them for now.

KWHCoaster
Автор

Thanks a lot for this video, i searched a ton of videos before but non of them were this easy to understand, also the code provided is so simple yet works so fine, thanks a ton for making this video

dhageakshay
Автор

Best video I have watched on this subject and I have watched quite a few! thank you

samrodian
Автор

Brilliant! I have an Arduino gathering dust which was a gift and I just took my old Umax Powerlook SCSI scanner apart which has two large belts driven by stepper motors. I reckon I could make a really smooth camera track with this which would be ideal for product photography.

PrinceWesterburg
Автор

Ty very much. Exactly what I was looking for 🤗

jarrodcacree
Автор

Thank you very much for the very informative video. I will give this a shot.

UzunKamis
Автор

Omg this video super helped me. Thank you

chaosloveBronson
Автор

very helpful project. Many thanks for excellent tutorial

elBendary
Автор

Nice job .so can u help me about the coding and programing to make a electric deviding indexer with stepper moter for 40:1 ratio to make any index

iqbalsingh
Автор

You saved my life on 14 dic 2018 and you didn't know. THANKS A LOT

sobreviviendoalau
Автор

Hi friend!! Very well! Thanks! Is it possible to connect at the same time a potentiometer, a button to stop and a screen 1602 with I2C

sculptory
Автор

Like in ur this video as u change the speed with scre driver exactly wat i want is a knob to change the speed but motor should start rotating when i use joy stick to move them

KurioTechSphere
Автор

Finally got my code to work with yours I tried about 10 others..thanks so much!! I bashed together the code from the button one and the speed one and made it reversable, so thanks a bunch!!

maddercat
Автор

Have you got the combined code for pot and switch control? I need both functions but do not know how to combine the 2 blocks of code. Any help would be appreciated

philipmaud
Автор

hi first Thanks for this instructive video and a question ?? If I want to design this project in Proteus What should I do <Can I help me>

ahmadrezaghanaatian
Автор

I wants to control 2 stepper motors with joy stick and speed of the motor needs to be change with another knob can u plz help me with this its my project

KurioTechSphere
Автор

All right thanks for the tutorial I have a question can the motor driver power to stepper motors at the same time thank you have a good day

derrickharvey
Автор

Hi guys. What is the max resolution (micro steps) possible with arduino / per revolution?

thanasisathanasi
Автор

HI SUPERB, IS THERE A WAY YOU CAN MAKE A CODE TO USE BOUTH AT THE SAME TIME? CHANGE DIRECTION AND SPEED CONTROL? THX

DemonMix