Need a little help arduino stepper motor with ir contol

I'm having problems with my negative values. it doesn't seem to rotate ccw and I'd also want to add a Stop command whenever I press the button 5, but just don't know how

#include "Stepper.h"
#include "IRremote.h"

#define STEPS 32
int Steps;
int receiver = 6;

Stepper small_stepper(STEPS, 8, 10, 9, 11);
IRrecv irrecv(receiver);
decode_results results;
void setup()
{
irrecv.enableIRIn();
}

void loop()
{
if (irrecv.decode(&results))

{
switch(results.value)

{

  case 0x20DF8877: // BUTTON 1
                  small_stepper.setSpeed(500); 
                  Steps  =  384;  // 60 Rotate CW
                  small_stepper.step(Steps);
                  delay(500); 
                  break;

  case 0x20DF48B7: // BUTTON 2
                  small_stepper.setSpeed(500);
                  Steps  =  -128;  // 180 Rotate CCW
                  small_stepper.step(Steps);
                  delay(500); 
                  break;

  case 0x20DFC837: // BUTTON 3
                  small_stepper.setSpeed(500); 
                  Steps  =  768;  // 30 Rotate CW
                  small_stepper.step(Steps);
                  delay(500); 
                  break;

  case 0x20DF28D7: // BUTTON 4
                  small_stepper.setSpeed(500);
                  Steps  =  -256;  // 90 Rotate CCW
                  small_stepper.step(Steps);
                  delay(500); 
                  break;
                  
  case 0x20DFA857: // BUTTON 5
                  Steps  =  0;  // STOP
                  delay(500); 
                  break;                          
}

  irrecv.resume();

}
}

Check the stepper library, what functions it provides and what it accepts.

1 Like

HI, @markyuu793

To add code please click this link;

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

1 Like

Hi,
Have you developed your code in stages, because with all the IR code in there it seems strange that you have only just got this problem.

Have you got just simple code without the IR to do basic control to the stepper?
Have you checked your hardware using a Stepper.h example in the IDE?

Can you please post a circuit diagram, just a pen(cil) and paper drawing will be fine?

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

1 Like

Thank you. ill check it

im new to this im really sorry

Check out my tutorial on Multi-tasking in Arduino which contains a complete stepper example controlled by user input and a sensor.
It uses the AccelStepper non-blocking library.