Stepper Counter with IR Receiver

Hi Guys,
I am very new to Arduino, so sorry in advance if my question sounds stupid.

I have a Stepper Motor and IR receiver, and I want to make the Stepper either turn 360 degrees and stop, or stops at any time when I press a button on my remote.

My code works when i stop it manually, but it doesn't stop after 2048 steps.

I also have same issue with DC motor, can you please send me the corrected code and a short explanation of why my existing code doesn't work. I really appreciate it.

#include <Stepper.h>
#include <IRremote.h>

#define STEPS 32
int RECV_PIN = 6;
int Steps = 0;
int Stepsadd = 1;
int n;

Stepper small_stepper(STEPS, 8, 10, 9, 11);
IRrecv irrecv(RECV_PIN);
decode_results results;

void setup()
{
  Serial.begin(9600);
  Serial.println("Enabling IRin");
  irrecv.enableIRIn(); // Start the receiver
  Serial.println("Enabled IRin");
}

void loop() {
  if (irrecv.decode(&results)) 
  {
  irrecv.resume();   // Receive the next value
  Serial.println(results.value, HEX);
  } 
{small_stepper.step(Steps);
n = n + 1;
        if (results.value == (0xFF629D) && (n < 2048))
        {
        small_stepper.setSpeed(700);
        Steps = (Steps + Stepsadd);
        }
        if (results.value == 0xFFA857) && (n < 2084))
        {
        small_stepper.setSpeed(700);
        Steps = (Steps - Stepsadd);
        }
        if (results.value == 0xFF02FD) || (n > 2048))
        {     
        small_stepper.setSpeed(0);
        Steps = 0;
        small_stepper.step(Steps);      
        }
             }
Serial.println(n);
}

Thanks,
Iman

Stepper.ino (1.07 KB)

ImanGalaxy:
I have a Stepper Motor and IR receiver, and I want to make the Stepper either turn 360 degrees and stop, or stops at any time when I press a button on my remote.

My code works when i stop it manually, but it doesn't stop after 2048 steps.

I don't understand all that, taken together.

What do you mean by "stop it manually"?

Tell us in as much detail as possible what happens when you run the program.

Add some Serial.print() statements so you can identify what is received by the IR receiver and which of the IF statements is activated.

I notice in one place you have 2084 - is that a typo?

Why have you small_stepper.step(Steps); in one of the IF statements and not in the others? I suspect it does not need to be in any of them.

If you use the Auto-Format tool to indent your code consistently it will be much easier to figure things out.

...R