Hi, could someone please change this code for me to use the indicated button to change direction. Now it works, but as soon as the engine gets a smaller load, it changes direction by itself. Thank you for your help
`#include <Stepper.h>
It is very unlikely that this is a software-problem
Why should the software change anthing just because a mechanical load is applied to your steppermotor????
it is very likely that this is a hardware-problem
Photos are of marginal utility. Please post a schematic or wiring diagram. Hand drawn, photographed and posted is fine. Include all pin names/numbers, components, their part numbers and/or values and power supplies.
Please post specs of the power supply.
The ancient and inefficient L298 driver is not appropriate for a modern bipolar stepper motor. Those motors require a current controlled driver.
Would you like help for choosing an appropriate stepper driver? if so, please post a data sheet for the stepper motor.
The Pololu A4988 page will help with that. You will need a power supply with a minimum 8V output.
Make sure that you properly set the coil current limit before using the stepper. The coil current should be found in the motor data sheet. Set the current to less than or equal to the spec current. To set the current limit you will need to know the value of the sense resistor on the A4988 driver board. Then enter the value of the resistor and the required coil current into the formula Vref = Imot x 8 x Rsen where Imot = the coil current and Rsen = the value of the sense resistor. The Pololu A4988 page covers how to set the Vref but you must use the sense resistor value on YOUR board. This page shows how to locate the sense resistor.
and would it be connected to a non-soldering field, or how to connect it all, and would it be possible to somehow connect the button there so that the direction changes when it is clicked? I have a 12V power source, is that okay?
All the A4988 drivers connect the same. The diagram on the Pololu page will apply to your driver.
You can connect with a quality solderless breadboard for temporary testing, though that is not the best, at all. Better would be to solder the parts to a protoboard or use aCNC shield to mount the drivers and connect the steppers. I like the CNC shields for convenience.
So I connected it according to these instructions How to drive a stepper motor easily using A4988 and Arduino - YouTube
and it works, only the motor as soon as it gets a bit of a load can't turn any further and oscillates in the same place, by that I mean if it could be solved somehow? Thank you
You need to look up the datasheet of your stepper-motor.
Nema 17 is just a mechanical size what distance do the mounting screws have.
In the picture you can see all Nema17-stepper motors
In this datasheet you will find the rated current of the stepper-motor.
You have to adjust the current with this tiny potentiometer on the rated current
like described in the datasheet of your stepper-motor-driver
Additional you can not rotate a stepper-motor from zero rpm to 1500 rpm instantly
you have to accelerate / deccelerate the rpms
You can read this in the usermanual of your stepper-motor-driver.
If you use a more advanced stepper-motor-driver like a TMC2209 the motor can rotate very smooth and almost silent.
If you use microstepping your stepper-driver will create less noise for the cost that you have to increase the step-pulse-frequency . For really fast rotating an arduino-uno has a too slow clock.