IR troubleshooting

hi everyone, this is my first post!

for my year 12 project, i am creating a ground station for my FPV hexacopter. I am trying to turn the various components on (receiver, tv, voltage regulator, LED, DVR, Voltage display etc) with an infrared remote.

so basically, my idea was to have the arduino register the the button press, and then change the state of the pin from high to low or vice versa. this would then connect to a transistor or a relay which would allow for it to work.

i have gotten it to work ok, however sometimes, when i turn something on, it will flicker. here is a copy of the code:

#include <IRremote.h>
int redledState = LOW;
int greenledState = LOW;
int buzzerstate = LOW;
int buzzer2state = LOW;
int fanState = LOW;
int buzzerpin = 11;
int buzzer1pin = 12;
int redPin = 13;
int greenPin = 7;
int fanPin = 10;
int irpin = 8;
IRrecv irIN(irpin);
decode_results results;
void setup()
{
Serial.begin(9600);
pinMode(10,OUTPUT);
pinMode(7, OUTPUT);
pinMode(13, OUTPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
irIN.enableIRIn();
}
void loop()
{
if(irIN.decode(&results))
{
Serial.println(results.value, HEX);
irIN.resume();
}

if(results.value == 16753245)

{

redledState = !redledState;
delay(15);
digitalWrite(redPin, redledState);

}

if(results.value == 16736925)
{

greenledState = !greenledState;
delay(15);
digitalWrite(greenPin, greenledState);

}

if(results.value == 16769565)
{

fanState = !fanState;
delay(15);
digitalWrite(fanPin, fanState);

}

if(results.value == 16720605)
{
buzzerstate = !buzzerstate;
delay(15);
digitalWrite(buzzerpin, buzzerstate);

}
if(results.value == 16712445)
{
buzzer2state = !buzzer2state;
delay(15);
digitalWrite(buzzer1pin, buzzer2state);

}

}

do you have any idea why it would flicker? it only happens sometimes. othertimes it works flawlessly.

thanks in advance for the replies!
regards, George

Hi-

It might be that the button press is very long compared to the looping of the Arduino. Since each of your "ifs" is a toggle, if it loops a number of times while the button is pressed, the led or whatever will be toggling and thus appear to flicker.

Some remote protocols repeat the key code if a button is held. You might take a look at the raw IR remote output to see if that happens. If so, code so that it reads a code and won't read the next unless the code changes.

ok. that makes sense. do you have any solutions to this problem? thanks for the reply.
George.