For a school project of mine, I'm supposed to be able to control a teacher's ceiling fan that is controlled by an IR remote and connect it to Google Home. My plan was to first make a working IR remote, but I've run into an issue. My teacher lent me the remote for a day, and I got all the hex values of every button on the remote, but I'm unable to send them. I've tried a simple setup with just one button, and if it's pressed, the IR LEDs should send the four rows of hex values to the fan, but it just doesn't work. Can anyone please help me? Here's the code I tried and altered:
#include <IRremoteESP8266.h>
#include <IRsend.h>
const int buttonPin = 14;
const int irLedPin = 1;
IRsend irSender;
bool buttonState = HIGH;
bool lastButtonState = HIGH;
unsigned long lastDebounceTime = 0;
bool sendingIR = false;
void setup() {
pinMode(buttonPin, INPUT_PULLUP);
irSender.begin(irLedPin);
}
void loop() {
int reading = digitalRead(buttonPin);
if (reading != lastButtonState) {
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > 50) {
if (reading != buttonState) {
buttonState = reading;
if (buttonState == LOW) {
sendingIR = true;
sendIRCodes();
} else {
sendingIR = false;
digitalWrite(irLedPin, LOW);
}
}
}
lastButtonState = reading;
}
void sendIRCodes() {
unsigned long irCode1 = 0xF3E5FAF2;
unsigned long irCode2 = 0x39A89916;
unsigned long irCode3 = 0xF3E5FAF1;
unsigned long irCode4 = 0xF3E5FAF1;
digitalWrite(irLedPin, HIGH);
irSender.sendNEC(irCode1, 32);
delay(50);
irSender.sendNEC(irCode2, 32);
delay(50);
irSender.sendNEC(irCode3, 32);
delay(50);
irSender.sendNEC(irCode4, 32);
digitalWrite(irLedPin, LOW);
}
and these are the buttons with their corresponding hex values:
HI:
F3E5FAF2
39A89916
F3E5FAF1
F3E5FAF1
MED:
F3E5FAF2
39A89916
87D57E46
87D57E46
LOW:
F3E5FAF2
39A89916
9F5D826E
9F5D826E
OFF:
F3E5FAF2
39A89916
8A8F5F86
8A8F5F86
ON/OFF:
F3E5FAF2
39A89916
31538D76
31538D76
2H:
F3E5FAF2
39A89916
6DEB31B6
6DEB31B6
4H:
F3E5FAF2
3EC4A317
6DEB31B6
6DEB31B6
8H:
F3E5FAF2
39A89916
64ED689B
64ED689B