Stepper motor not running or rotating

Hello, could anyone assist me with an issue I am having with my stepper motor? I am using an Arduino UNO R3. My stepper motor is supposed to rotate when I press buttons on my IRRemote. It glitches and isn't running. Is there a way that I can get it to run, or can someone please proofread my code? The setup image I followed is attached below, along with my code:

#include <AccelStepper.h>
#include "IRremote.h"


int receiver = 13; // Signal Pin of IR receiver to Arduino Digital Pin 6




enum
stepper_Motor {
  FUNCTION = 0, DRIVER = 1, FULL2WIRE = 2, FULL3WIRE = 3,
  FULL4WIRE = 4, HALF3WIRE = 6, HALF4WIRE = 8
};




#define sleep_pwr 4




AccelStepper stepper_Motor(DRIVER, 3, 2); //stepper(driver, step, dir)
IRrecv irrecv(receiver);    // create instance of 'irrecv'
decode_results results;     // create instance of 'decode_results'


int stepsPerRev = 200; // Stepper motors are often 200 steps per revolution
int gearRatio = 4; // number of motor rotations required to rotate the drum one full revolution (e.g. motor pulley has 20 teeth, and the drum pulley has 80, so 4:1 ratio)
int microSteps = 16; // this can be manually specified using the "mode" pins on the DRV8825 board:


//         M0   M1    M2          RESOLUTION
//------------------------------------------------
//        LOW   LOW   LOW        FULL  STEP   1 Revolution  200  steps
//        HIGH  LOW   LOW        HALF  STEP   1 Revolution  400  steps
//        LOW   HIGH  LOW        1/4   STEP   1 Rrevolution  800  steps
//        HIGH  HIGH  LOW        1/8   STEP   1 Rrevolution  1600 steps
//        LOW   LOW   HIGH       1/16  STEP   1 Revolution  3200 steps
//        HIGH  LOW   HIGH       1/32  STEP   1 Revolution  6400 steps




float speedRPM = 1.0; // the speed of rotation. Optomotor experiments often use around 2-4 RPM
float timeRot = 45.0; // number of seconds to rotate in each direction
int nRot = 3; // the number of rotations in each direction
float stepperAccell = 5000; // acceleration and deceleration of stepper motor
int dir = -1; // initial direction: -1 = clockwise, 1 = anticlockwise


int nRem = 0;
//int nDec = 256; // number of decelleration steps when halt/reverse occurs


void setup() {


  Serial.begin(9600);
 
  Serial.println("Initialised");
  irrecv.enableIRIn(); // Start the receiver
  pinMode(sleep_pwr, OUTPUT);
  digitalWrite(sleep_pwr,LOW);
  stepper_Motor.setCurrentPosition(0);


}


void loop() {




  if (irrecv.decode(&results)){ // have we received an IR signal?


    Serial.println(results.value);
    switch(results.value){




      case 0xFFA25D: // power - stop everything!
          stepper_Motor.setCurrentPosition(0);
         //stepper_Motor.moveTo(stepper_Motor.currentPosition() + (nDec*dir));
         nRem = 0;
      break;


      case 0xFF02FD: // play/pause - switch direction manually
          stepper_Motor.setCurrentPosition(0);
         //stepper_Motor.moveTo(stepper_Motor.currentPosition() + (nDec*dir));
         nRem = nRem+1;
      break;


      case 0xFF906F: // up
         nRem = nRot;
         dir = -1;
      break;


      case 0xFFE01F: // down
         nRem = nRot;
         dir = 1;
      break;


      case 0xFF30CF: // 1
         speedRPM = 1.0;
      break;
     
      case 0xFF18E7: // 2
         speedRPM = 2.0;
      break;


      case 0xFF7A85: // 3
         speedRPM = 3.0;
      break;
     
      case 0xFF10EF: // 4
         speedRPM = 4.0;
      break;
     
      case 0xFF38C7: // 5
         speedRPM = 5.0;
      break;
     
      case 0xFF5AA5: // 6
         speedRPM = 6.0;
      break;


      case 0xFF42BD: // 7
         speedRPM = 7.0;
      break;
     
      case 0xFF4AB5: // 8
         speedRPM = 8.0;
      break;


      case 0xFF52AD: // 9
         speedRPM = 9.0;
      break;
     
      case 0xFF6897: // 0
         speedRPM = 10.0;
      break;
     
    }
      irrecv.resume(); // receive the next value
  }


  if(stepper_Motor.distanceToGo()==0)  {
    if(nRem > 0){


      stepper_Motor.setCurrentPosition(0);
     
      nRem = nRem-1;
      dir = dir*-1;
      long nSteps = round(stepsPerRev * gearRatio * microSteps * (speedRPM/60) * timeRot * dir);
      float stepperSpeed = nSteps/timeRot;
     
      stepper_Motor.setMaxSpeed(stepperSpeed);
      stepper_Motor.setAcceleration(stepperAccell);
      stepper_Motor.moveTo(nSteps);
   
      Serial.println((String)"nSteps = " + (nSteps));
      Serial.println((String)"stepperSpeed = " + (stepperSpeed));
   
      digitalWrite(sleep_pwr,HIGH);
 
    } else {
      digitalWrite(sleep_pwr,LOW);
    }
 
  }


  stepper_Motor.run();
 




}

The Arduino is not a power supply, and cannot provide power to motors or servos.

Steppers generally require 12 to 24V at several Amperes, provided by a dedicated motor power supply. You also must adjust the current limit properly on the motor driver.

1 Like

The DRV8825 requires a minimum of 8.2V to work.

Have you set the coil current limit on the DRV8825. That step is imperative. https://www.circuitist.com/how-to-set-driver-current-a4988-drv8825-tmc2208-tmc2209/

What version of the IRremote library are you using? The above is written for an older version (< 3.0).

1 Like

I am using version 2.0 of the IRremote library

Right, then your IRremote code is for the right version.

The newer versions are quite a bit different, but only somewhat backward compatible.

1 Like

What is the battery supply voltage?

Hi, @dcbarduino
Welcome to the forum.

Can I suggest you get your code working in stages.
The first stage is to JUST write code that JUST controls the stepper, makes it go forward, stop, reverse.
Prove that you have control and it works smoothly, THEN write some code that JUST reads the IR remote.
Get it working to prove you have reliable reception.
Then combine them.

Have you any working code JUST for the stepper?

Tom.. :grinning: :+1: :coffee: :australia:

Thank you so much. Adjusting the motor driver current limit is not something I thought of.

OMG the website you linked was super helpful. I'm gonna try that an give you the update

I am using a DC voltage of 12V

This is a good idea, that way I can isolate the problem. I'll do that and let you know. Thank you

Hello everyone, I used a potentiometer to set the reference voltage of my DRV8825 to 0.5V. But the stepper motor still isn't moving, and now whenever I plug it into a power source, the power input in the arduino circuit begins to fry. Also, when I plugged it into the computer to load my code onto it, my motherboard battery fried. Could anyone assist me?
I am using a 12V power source. I have attached a link to the video of what happens when I plug it in.

Do post a proper schematic of your setup.

As mentioned before, an Arduino is not a power supply. Don't use it to power your stepper. Use the 12V supply to power your stepper driver directly instead.

Again, do run a basic sketch that does nothing but running your stepper. Get that to work first.

Can you please post a copy of your circuit, a picture of a hand drawn circuit in jpg, png?
Hand drawn and photographed is perfectly acceptable.
Please include ALL hardware, power supplies, component names and pin labels.

Please post some images of your project.

Please post your test code that I referred to in post #7, that you write.

Tom.... :grinning: :+1: :coffee: :australia:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.