Making a smart remote

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

How do you know they are not sent? Are you basing that on the response of the fan? A better first test would be to serial.Print() the values you are trying to send and see if they are what you think they should be.

Most of those remotes are modulated with something in the 38khZ range. There are libraries that will do the heavy work for you. There are several schemes, start with the NEC codes. Let us know what grade you get for this.

Please explain the evidence for that. Hint: "fan doesn't respond" is not enough.

For help, please provide more information: wiring diagram, links to the components, etc.

I'm using an Arduino with a HY-M302 shield to read out all the hex values through the IR receiver. For the wiring diagram, I have an ESP32 connected to a button linked to pin 14 that, when pressed, will be shorted to GND and a data pin of an IR LEDs module. I'm also using the HY-M302 shield as a 5V power source.
Ill post a more detailed wiring diagram later today!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.