I am trying to get my stepper motor to respond to my IR controls. I'm using a mash up of code from different sources. I've tested the Stepper motor with an independent code, and it works. I've tested the IR receiver with an independent code, and it works. I just can't get my code to work. Below is a diagram, the code, as well as the outputs from the IR remote in the COM Monitor, which I utilized in assigning remote button cases.
#include "Stepper.h"
#include "IRremote.h"
/*----- Variables, Pins -----*/
#define dirPin 2
#define stepPin 3
#define STEPS 32 // Number of steps per revolution of Internal shaft
int Steps2Take; // 2048 = 1 Revolution
int receiver = 6; // Signal Pin of IR receiver to Arduino Digital Pin 6
int val ; // define numeric variables
/*-----( Declare objects )-----*/
Stepper small_stepper(STEPS, 8, 10, 9, 11);
IRrecv irrecv(receiver); // create instance of 'irrecv'
decode_results results; // create instance of 'decode_results'
void setup()
{
irrecv.enableIRIn(); // Start the receiver
Serial.begin(9600);
}
void loop()
{
if (irrecv.decode(&results)) // have we received an IR signal?
{
switch (results.value)
{
case 16748655: // UP button pressed
small_stepper.setSpeed(500); //Max seems to be 700
Steps2Take = 2048; //
small_stepper.step(Steps2Take);
delay(10);
break;
case 16769055: // DOWN button pressed
small_stepper.setSpeed(500);
small_stepper.step(Steps2Take);
delay(10);
break;
case 16712445: // STOP button pressed
small_stepper.setSpeed(0);
Steps2Take = 0; //
small_stepper.step(Steps2Take);
delay(10);
break;
}
irrecv.resume(); // receive the next value
}
}
COM Monitor IR Remote Results:
The function decode(&results)) is deprecated and may not work as expected! Just use decode() without a parameter and IrReceiver.decodedIRData. .
Code: 16769055
Code: 16712445
Code: 4294967295
Code: 16748655
Code: 4294967295