Hi Guys
I wonder if the resident genius can help me figure out what is wrong with this project. I must point out I'm very much a novice.
bit of background .. .. I've been playing with IR remote controls and built a Nano code reader to display a transmitted code when a button is pressed .. .. so I thought the next logical step was to use the code to make something happen.
I found a sketch to control a servo motor which I don't have but I do have steppers so I modified it.
However, I can't get it to work.
I've checked that the Uno is receiving the code from the remote; I've checked that the Uno will run the stepper, but I cannot get it to act upon the IR code received.
Here is my code ..
#include "Stepper.h"
#include "IRremote.h"
/*----- Variables, Pins -----*/
#define STEPS 32 // Number of steps per revolution of Internal shaft
int Steps2Take; // 2048 = 1 Revolution
int receiver = 3; // Signal Pin of IR receiver to Arduino Digital Pin 3
/*-----( Declare objects )-----*/
// Setup of proper sequencing for Motor Driver Pins
// In1, In2, In3, In4 in the sequence 1-3-2-4
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
}
void loop()
{
if (irrecv.decode(&results)) // have we received an IR signal?
{
switch (results.value)
{
case 18615 : // UP button pressed (0xFF629D)
small_stepper.setSpeed(500); //Max seems to be 700
Steps2Take = 2048; // Rotate CW
small_stepper.step(Steps2Take);
delay(2000);
break;
case 10455: // DOWN button pressed (0xFFA857)
small_stepper.setSpeed(500);
Steps2Take = -2048; // Rotate CCW
small_stepper.step(Steps2Take);
delay(2000);
break;
}
irrecv.resume(); // receive the next value
}
}
The two codes - 18615 & 10455 are the codes identified by my code reader. The figure in brackets after the comment out is what was on the original sketch - I put that in because it appears to be a different language, which I don't understand. The Protocol is NEC.
I'd appreciate any help you can offer, I'm stumped !
Thanks
S