Hello, this is my first post on this forum, I have an Arduino Uno rev.3 that I’ve bought some weeks ago and after having followed some tutorials I’m trying my first project to control my ceiling fan in my home with my tv remote: I’ve decoded the raw IR codes with arduino and created an array for each code, I’ve tried them individually and I can remotely control my fan from the board, now I’ve decoded some buttons on my Acer TV remote and I need to send an IR to the ceiling fan when a IR code is received from the tv remote. Below you can see my code. My problem is that the tv remote sends a lot of 0xFFFFFFFF if I keep a button pressed, but if I release the button before any of these codes is received from the arduino, the board keeps turning on and off the light very fast for a few seconds and then it stops. How can I avoid this? I’ve tried inserting a line like this after the irsend results.value = 0xFFFFFFFF; but if I use this the light gets triggered once and then my board seems to hang up. Someone could helpm me? This is driving me crazy!
#include <IRremote.h>
byte rcvPin = 2; // sets IR receiver Pin
byte ldrPin = 0; // sets light dependent resistor Pin
IRrecv irrecv(rcvPin); // enables IR receiving on Pin D2
decode_results results;
IRsend irsend; // enables IR sending on Pin D3
/*Remote IR Codes:
Vortice ceiling fan:
FanSpeed0: 0xD1D354D2
FanSpeed1: 0xC6B51673
FanSpeed2: 0x292CF9AD
FanSpeed3: 0x260C914D
FanSpeed4: 0x5D2ABE91
FanSpeed5: 0x352AD5F8
LightToggle: 0xB2A0D1ED
TimerToggle: 0xA4647371
Acer TV:
GreenE: 0x28A0F5F6
BottomLeft: 0x36C5EBDA
BottomRight: 0x7B782F3C
*/
// Arrays containing remote buttons IR raw codes for Vortice ceiling fan remote
unsigned int fanSpeed0[25] = {
250, 900, 250, 900, 250, 2500, 250, 2500, 250, 900, 250, 900, 250, 2500, 250, 900, 250, 2500, 250, 2500, 250, 2500, 250, 900, 250};
unsigned int fanSpeed1[25] = {
250, 900, 250, 900, 250, 2500, 250, 2500, 250, 900, 250, 900, 250, 2500, 250, 900, 250, 2500, 250, 2500, 250, 900, 250, 2500, 250};
unsigned int fanSpeed2[25] = {
250, 900, 250, 900, 250, 2500, 250, 2500, 250, 900, 250, 900, 250, 900, 250, 2500, 250, 900, 250, 2500, 250, 2500, 250, 2500, 250};
unsigned int fanSpeed3[25] = {
250, 900, 250, 900, 250, 2500, 250, 2500, 250, 900, 250, 900, 250, 900, 250, 2500, 250, 2500, 250, 2500, 250, 900, 250, 2500, 250};
unsigned int fanSpeed4[25] = {
250, 900, 250, 900, 250, 2500, 250, 2500, 250, 900, 250, 900, 250, 2500, 250, 900, 250, 900, 250, 2500, 250, 2500, 250, 2500, 250};
unsigned int fanSpeed5[25] = {
250, 900, 250, 900, 250, 2500, 250, 2500, 250, 900, 250, 900, 250, 900, 250, 2500, 250, 2500, 250, 2500, 250, 2500, 250, 900, 250};
unsigned int lightToggle[25] = {
250, 900, 250, 900, 250, 2500, 250, 2500, 250, 900, 300, 850, 250, 2500, 250, 2500, 250, 900, 250, 850, 300, 2500, 250, 2500, 250};
unsigned int timerToggle[25] = {
250, 900, 250, 900, 250, 2500, 250, 2500, 250, 900, 250, 900, 250, 2500, 250, 2500, 250, 2500, 250, 900, 250, 900, 250, 2500, 250};
void setup() {
Serial.begin(9600);
irrecv.enableIRIn(); // Start the IR receiver
}
void loop() {
if (irrecv.decode(&results)) {
Serial.println(results.value, HEX);
irrecv.resume(); // Receive the next value
}
switch(results.value) {
case 0x28A0F5F6:
Serial.println("GreenE");
irsend.sendRaw(lightToggle, 25, 38);
break;
case 0x36C5EBDA:
Serial.println("Bottom Left");
break;
}
delay(100);
}