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)