IR Repeats and Interrupts

Hello All,

I am new to the Arduino and this is one of my first more advanced sketches. Sorry if this is to much information. Any help is appreciated, I just want to learn!

The Goal of Project:
-To emulate a standing fan using a remote control. The Remote control sends power on signal to IR receiver and turns fan on. Another button from the controller makes the fan rotate\sweep from side to side, couple more buttons change the speed of the rotation\sweep.

This is what i'm currently having problems with. Right when everything is connected up my stepper motor steps 200 rotations clockwise and then goes the other way 200 steps counter-clockwise which rotates\sweeps the DC fan back and forth, works pretty good! Pressing volume up and down changes the speeds of the sweeps. What i'm currently having issues is with sometimes i get 5-6 repeat signals from the IR Remote: FFFFFFFF <-- how do I avoid these repeat signals. Serial Prints for Debugging Purposes.

Hardware)
-Arduino UNO
-12V Stepper Motor\Controller Board
-12V DC Fan
-IR Receiver
-10K Pull Up Resistor to IR Receiver

The Code:

/*---- Needed Libraries ----*/

//IR Libraries
#include "IRremote.h"
#include "IRremoteInt.h"

//Stepper Motor Libraries
#include <Stepper.h>

//Declare Variables and Constants

//IR
int receiver = 2; // pin 1 of IR receiver to Arduino digital pin 2
volatile int IR_state = HIGH;

//STEPPER
const int stepsPerRevolution = 200; //
Stepper myStepper(stepsPerRevolution, 8, 10, 9, 11); //Motor Pin Mapping
volatile int max_speed = 0;


//Declare Objects
IRrecv irrecv(receiver);           // create instance of 'irrecv'
decode_results results;            // create instance of 'decode_results'

void setup() {
  
  //Start Serial Interface
  Serial.begin(9600);
  
  //Start IR
  Serial.println("IR Receiver Raw Data Decode Test");
  irrecv.enableIRIn(); // Start the receiver
  
  //Set Settper Speed (Default Speed)
  myStepper.setSpeed(4);
  
  //Attach and Enable Interrupt
  attachInterrupt(0, IR_Controll, RISING);
  interrupts();
  
}

void loop()
{

//Run Motor Sweep

//Clockwise
Serial.println("Stepping Start Clockwise");
myStepper.step(stepsPerRevolution);
Serial.println("Stepping Done Clockwise");
delay(200);

//Counter-Clockwise
Serial.println("Stepping Start Counter Clockwise");
myStepper.step(-stepsPerRevolution);
Serial.println("Stepping Done Counter Clockwise");
delay(200);

}


//IR Interrupt
void IR_Controll()
{
  IR_state = !IR_state;
  if (irrecv.decode(&results))
  {
    IR_Translate();
    irrecv.resume();
  }
}

//IR DECODER
void IR_Translate()
{
  
   Serial.println();
   Serial.print("RAW DECODE: ");
   Serial.println(results.value, HEX);
  
   switch(results.value)
   {
     
     //Power
     case 0x10EF08f7:
     Serial.println("Power");
     break;
     
     //Volume Up
      case 0x10EF58A7:
      Serial.println("Volume Up!");
      if (max_speed >= 0 && max_speed <= 2) 
      { 
      max_speed = max_speed + 1;
      speedcontrol();
      }
      Serial.print("Max Speed ");
      Serial.println(max_speed);
      break;
      
      //Volume Down
      case 0x10EF708F:
      Serial.println("Volume Down");
      if (max_speed >= 1)
      {
      max_speed = max_speed - 1;
      speedcontrol();
      }
      Serial.print("Max Speed ");
      Serial.println(max_speed);
      break;
      
      //Repeat Signal
      case 0xFFFFFFFF:
      Serial.println("Repeat Signal");
      break;
      
      //Unknown Signal
      default:
      Serial.println("Unknown Button Signal");
    
   }
   delay(500);
   }

//STEPPER SPEED CONTROL   
void speedcontrol()
{
//Serial.println("Adjusting Speed");
switch(max_speed)
{
  case 0:
  myStepper.setSpeed(4);
  break;
  
  case 1:
  myStepper.setSpeed(8);
  break;
  
  case 2:
  myStepper.setSpeed(12);
  break;
  
  case 3:
  myStepper.setSpeed(16);
  break;
}

}

What i'm currently having issues is with sometimes i get 5-6 repeat signals from the IR Remote: FFFFFFFF <-- how do I avoid these repeat signals.

Quit holding the button down so long.

Seriously, as long as you don't plan to act on the repeat signal, what difference does it make?

Read this before posting a programming question

Please edit your post, select the code, and put it between [code] ... [/code] tags.

You can do that by hitting the # button above the posting area.

I think remotes are designed to send codes repeatedly, so you can, for example, turn the volume up by holding down the button.

You could:

  • Look for repeated codes and ignore subsequent ones
  • Ignore the same code if it happens within (say) 2 seconds of an earlier one