HELP! Motor not rotating correctly

Hello, this is my first post here and I am new to all of this.

I am using the arduino sample program called One Rotation

My stepper motor is not rotating correctly. as you can see in the video it moves a couple of times in one direction than in the other.

Here are my components;

Arduino Mega (Elegoo)
L298N stepper motor driver rated 2 amp
Nema 17 stepper motor, 2 amp bipolar 4 wire 1.8 degree 200 step
12 volt power supply to the driver
5 volt supplied to the Arduino via PC

Here is the wiring diagram I followed:

my video:

So how do I get this thing to correctly turn? Please help!

Well, your video shows everything except the 12V power supply, what is it's current rating?
Please post your complete code as shown by:
[How to use this forum - please read. - Installation & Troubleshooting - Arduino Forum]HowToPost](How to use this forum - please read. - Installation & Troubleshooting - Arduino Forum)

/*
 Stepper Motor Control - one revolution

 This program drives a unipolar or bipolar stepper motor.
 The motor is attached to digital pins 8 - 11 of the Arduino.

 The motor should revolve one revolution in one direction, then
 one revolution in the other direction.


 Created 11 Mar. 2007
 Modified 30 Nov. 2009
 by Tom Igoe

 */

#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(60);
  // 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);
}

2 Amp motor and 1 Amp power supply? Can you post a link to the motor and driver?
Also try setting speed down to 10 RPM & see if it makes a diff.

motor--https://www.amazon.com/gp/product/B00PNEQKC0/ref=oh_aui_detailpage_o01_s00?ie=UTF8&psc=1

Driver--https://www.amazon.com/gp/product/B00CAG6GX2/ref=oh_aui_detailpage_o01_s00?ie=UTF8&psc=1

I also have this power supply but I was afraid to use it since it was a 3.3 amp

I also have this power supply but I was afraid to use it since it was a 3.3 amp

Your fear is misguided. Circuits DRAW current, and the power supply must be able to supply MORE current than will be drawn.

The L298 motor driver is ancient technology and will not work for 2 Ampere stepper motors.

You should be using a modern motor driver, like this one. Be sure to follow instructions and set the current to about 1.5 Amperes per winding.

That PS should be safe to use with your components, the L298 driver with heatsink might be border line but should handle your motor OK, give it a try.

the L298 driver with heatsink might be border line but should handle your motor OK

No, it won't.

See The Motor Driver Myth — Rugged CircuitsRugged Industrial Arduino Microcontrollers

For the L298N .... it will work if the speed is slow enough and the load is relatively light. Just reduce average pwm output voltage until the stepper steps reliably. And put a big heatsink on.

But .... I do agree that it can be easier to use a driver like drv8825.

Anyway.... here's a video of my L298N with a nema 17.... with no load. This was before I started to use other things like drv8825.

The IC (chip) on my bread-board is only a 74LS04N logic level hex inverter.

Here's a board I like and have used successfully in several projects.

@jremington: Have you built a project with that exact motor, driver and power supply and given it a 1 hour burn-in test?

If I go with the drv8825 could you recommend a dc power supply. This will be powering a camera timelapse slider so it will need to be mobile.

@edgemoron: I wouldn't waste my time doing so.

It does beginners no good to give them bad recommendations. Doing so only increases their frustrations.

If I go with the drv8825 could you recommend a dc power supply.

A power supply capable of providing more the 8V is required. The higher the power supply voltage (up to about 35V is allowed), the less current is required.

The key details for your motor are:

  • Rated Current/phase: 2.0A
  • Phase Resistance: 1.4ohms

which means that it is rated for maximum power of (2A)^2*1.4(Ohms) = 5.6 Watts per winding or about 12 Watts total.

Your 12V power supply need only be able to provide a little more than 1 Ampere to meet that criterion (1.5 A to be conservative).

However, even the DRV8825 can't handle 2 Amperes/winding continuously without extra cooling, so you need to set the current limit for less. 1.5 A is recommended, which will provide about 3/4 of the maximum possible motor torque.

Pololu engineers support their products and also provide great instructional material. See in particular their product page video showing you how to set the DRV8825 current limit.

You didn't answer my question, and what "bad recommendation" did I give?
Do you remember this?
https://forum.arduino.cc/index.php?topic=487693.msg3329858#msg3329858
The post went unanswered for more than 31 hours until I did, immediately you jumped in to dispute my reply, I just wonder if I hadn't replied to this post if you would have ignored it too. Not much of a way to help beginners.

what "bad recommendation" did I give?

That the OP use the L298 driver for a 2 A/winding, 1.4 Ohm motor.

I did not "tell" him any thing, I suggested he "try" it since he already had it, it could have worked fine for his application which you didn't know.

Ok, so the L298N will drive it but is not ideal for my application. I am going to purchase a new driver and PS. Could you guys recommend a quality driver and PS that will work well together with my motor? I am looking for something that I will not have to worry about overheating in the field. I need a power supply that will run this setup for 4 hours.

Thank you all for your input. It is greatly appreciated. I wish I would have came here first. I had no idea that I was buying parts that were not sufficient for my needs. I apologize for my ignorance on the subject. You have both enlightened me and I appreciate your time and effort.

cdryden:
If I go with the drv8825 could you recommend a dc power supply. This will be powering a camera timelapse slider so it will need to be mobile.

Supply voltage depends on how fast you want the thing to move. So how fast (in rpm of the motor shaft)?

Steppers are very power hungry - for a battery operated slider I would suggest a standard DC motor,
a feedback loop and a shaft encoder (which is alas a lot more complication to setup).

With a stepper you'll ideally want a stepper driver that allows the current to be dropped to 30% to 50% of full
when stationary to save battery life - most of the standard modules like DRV8825 ones don't bring
out that input or don't have the option, alas.

The 40W power supply you mentioned in reply #4 might be OK, along with the DRV8825 driver mentioned in reply #5.

HOWEVER, you should build the camera slider first and measure the force/torque/power required to operate the mechanism properly, before deciding on and ordering motors, drivers and power supplies.

I hooked up a 12v 5 amp supply to see what would happen and it worked, but got hot pretty quick so I disconnected it.

I have a slider already, I am not sure how much torque is required. I will be moving 4lbs of camera+lens+carriage. The carriage moves along a Igus rail and uses bearing rollers instead of a friction bearing.
I would like to be able to move this straight up and down as well as horizontally which is why I got a 84oz motor to begin with. I figured it would handle the load but what I didn't count on was the strain that it would put on the driver.