ARDUINO infrared IR remote stepper motor control

 

The IR remote library you will need can be downloaded at this link:  IRremote

 

arduino infrared ir remote stepper motor control
#include <IRremote.h>

int RECV_PIN = 5;

IRrecv irrecv(RECV_PIN);

decode_results results;

#include <Stepper.h>
int dir;
const int stepsPerRevolution = 200;
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11); //arduino pins to h-bridge inputs

void setup() {

myStepper.setSpeed(60);
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
}

void loop() {
// myStepper.step(encoderPos);
if (irrecv.decode(&results)) {
Serial.println(results.value);
irrecv.resume(); // Receive the next value
if (results.value == 1320358637)
{
myStepper.step(+1);
dir = 1;
}
else if (results.value == 4294967295 && dir == 1)
{
myStepper.step(+1);
}
else if (results.value == 1320368327)
{
myStepper.step(-1);
dir = -1;
}
else if (results.value == 4294967295 && dir == -1)
{
myStepper.step(-1);
}
else if (results.value == 1320392807)
{
myStepper.step(+100);
dir = 100;
}
else if (results.value == 4294967295 && dir == 100)
{
myStepper.step(+100);
}
else if (results.value == 1320360167)
{
myStepper.step(-100);
dir = -100;
}
else if (results.value == 4294967295 && dir == -100)
{
myStepper.step(-100);
}
else if (results.value == 1320401477)
{
myStepper.step(+1000);
dir = 1000;
}
else if (results.value == 4294967295 && dir == 1000)
{
myStepper.step(+1000);
}
else if (results.value == 1320417287)
{
myStepper.step(-1000);
dir = -1000;
}
else if (results.value == 4294967259 && dir == -1000)
{
myStepper.step(-1000);
}
else dir = 0;
}
delay(5);
}

 

 

 

Advertisements