I've tried out many examples and tutorials to get a Nema17 stepper motor working with a L298N - the issue is that my Nema17 has 4 wires (instead of 5 in some examples) - Red, Blue, Green and Black. Others have 4 wires but these are 2 x Red and 2 x Black.
I've messed around trying to get it to work, but I'm getting nothing at all. I can see the Serial output so I know the Arduino is running the code (the stepper example from the menu), but nothing from the motor at all.
Does anyone know of an example that uses these wires that I could follow?
Nema 17 only defines the size of the front face of the motor - 1.7 inches. There are hundreds of different Nema17 motors and many (most?) of them are not suitable for use with an L298. Usually a specialized stepper motor driver is a better option but without details of your motor I can't recommend any.
You need to post a link to the datasheet for your motor.
You should use your multimeter to determine which pair of wires belongs to each of the two motor coils. The two wires for a single coil go to one output on the L298 and the two wires for the other coil go to the other output.
I've got it working, but with some quite bizarre behaviour.
I have the following code:
void loop() {
// step one revolution in one direction:
Serial.println("clockwise");
myStepper.step(stepsPerRevolution);
delay(500);
// step one revolution in the other direction:
Serial.println("counterclockwise");
myStepper.step(-stepsPerRevolution);
delay(500);
}
You would expect that it would spin in one direction, then stop for 500 milliseconds and then spin in the opposite direction.
It does...sometimes. It will spin in one direction, then stop, then spin in the same direction 2 or 3 times, then spin the other way for 1 or 2 spins, then back the other way...almost randomly.
Please post a link to the datsheet so we can read the technical details.
You would expect that it would spin in one direction, then stop for 500 milliseconds and then spin in the opposite direction.
You have not posted the complete program so we can't know how fast you are trying to move the motor. Always start testing with a very slow speed of (say) 2 or 5 steps per second.
And you have told us nothing about how you are powering the motors.
#include <Stepper.h>
const int stepsPerRevolution = 200; // change this to fit the number of steps per revolution
// for your motor
// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);
void setup() {
// set the speed at 60 rpm:
myStepper.setSpeed(190);
// initialize the serial port:
Serial.begin(9600);
}
void loop() {
// step one revolution in one direction:
Serial.println("clockwise");
myStepper.step(stepsPerRevolution);
delay(500);
// step one revolution in the other direction:
Serial.println("counterclockwise");
myStepper.step(-stepsPerRevolution);
delay(500);
}