Ligando ar condicionado pelo código raw com esp32

Elaborei um código para ligar e desligar meu ar condicionado pelo ESP32, utilizando um sensor de temperatura e umidade, sensor de presença, emissor de infravermelho e um display lcd i2c.
Clonei o código raw do meu aparelho, porém não estou conseguindo executar.
Na biblioteca IRremote do ESP32 não há um exemplo de IRSendRaw. Tive que adaptar da biblioteca do Arduino.
Alguém poderia verificar? Desde já agradeço pelo atenção. Segue abaixo o código:

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <DHT.h>
#include <IRremoteESP8266.h>
#include <IRsend.h>

#define DHTPIN 15          // Pino ao qual o sensor DHT está conectado
#define DHTTYPE DHT11      // Tipo do sensor DHT utilizado
#define MOTION_PIN 34      // Pino de entrada para o sensor de movimento
#define IR_LED_PIN 26      // Pino para o emissor infravermelho

IRsend irsend(IR_LED_PIN);

//Valores do ar-condicionado
uint16_t rawDataOn[] = {3423, 1598, 503, 366, 472, 421, 400, 438, 395, 447, 393, 447, 392, 472, 366, 1245, 447, 462, 393, 449, 391, 474, 365, 450, 390, 450, 391, 450, 389, 452, 389, 452, 389, 462, 393, 450, 389, 450, 390, 1247, 446, 474, 365, 1246, 447, 473, 367, 474, 365, 463, 392, 1246, 446, 474, 367, 474, 365, 475, 365, 475, 365, 475, 365, 475, 365, 1262, 445, 1246, 446, 473, 367, 1246, 445, 475, 366, 474, 367, 1244, 449, 471, 366, 464, 391, 1247, 444, 452, 389, 1247, 445, 474, 366, 475, 364, 477, 364, 474, 367, 1260, 446, 474, 366, 476, 364, 1246, 445, 1246, 446, 1247, 444, 476, 365, 450, 391, 462, 392, 476, 364, 451, 389, 451, 390, 1247, 445, 473, 367, 1245, 446, 1246, 446, 1260, 446, 475, 365, 474, 364, 477, 366, 475, 364, 474, 366, 475, 366, 475, 367, 461, 392, 474, 368, 473, 365, 474, 367, 474, 367, 473, 367, 473, 366, 474, 366, 464, 391, 1247, 445, 476, 364, 475, 366, 475, 365, 474, 366, 474, 365, 476, 365, 463, 391, 475, 366, 1245, 446, 474, 366, 474, 366, 473, 367, 474, 366, 1246, 446, 480, 364};
uint16_t rawDataOff[] = {3423, 1598, 504, 366, 472, 418, 421, 445, 368, 446, 394, 447, 392, 449, 391, 1245, 444, 465, 391, 450, 391, 474, 365, 475, 366, 474, 365, 451, 390, 450, 389, 475, 366, 463, 393, 451, 388, 453, 387, 1247, 447, 473, 366, 1246, 445, 450, 390, 451, 388, 465, 392, 1246, 446, 474, 365, 474, 365, 453, 388, 450, 390, 451, 390, 449, 390, 1262, 445, 1245, 447, 474, 366, 1247, 444, 475, 366, 474, 366, 1246, 447, 472, 365, 464, 392, 475, 365, 1246, 446, 1246, 445, 452, 390, 473, 366, 474, 366, 474, 366, 1261, 446, 474, 366, 475, 366, 1245, 445, 1247, 445, 1247, 444, 475, 366, 475, 365, 463, 392, 474, 367, 473, 366, 451, 390, 1246, 446, 473, 366, 1246, 446, 1245, 447, 1260, 445, 474, 365, 452, 390, 473, 367, 475, 365, 474, 367, 475, 366, 471, 368, 463, 391, 475, 366, 451, 391, 473, 364, 452, 390, 473, 367, 474, 366, 475, 366, 462, 392, 1245, 447, 474, 365, 476, 366, 474, 365, 474, 366, 475, 366, 475, 365, 462, 391, 1245, 447, 1246, 444, 452, 388, 452, 390, 474, 366, 475, 365, 1246, 446, 454, 391};
unsigned int rawDataLen = sizeof(rawDataOn) / sizeof(rawDataOn[0]);  

DHT dht(DHTPIN, DHTTYPE);
LiquidCrystal_I2C lcd(0x27, 16, 2);  // Endereço I2C do display LCD

void setup() {
  irsend.begin();
  Serial.begin(9600);
  pinMode(MOTION_PIN, INPUT);

  dht.begin();
  lcd.init();                      // Inicializa o LCD
  lcd.backlight();                 // Liga a luz de fundo do LCD
}

void loop() {
  // Leitura da temperatura e umidade
  int temperature = dht.readTemperature();
  int humidity = dht.readHumidity();

  // Verificação de presença ou movimento
  int motionDetected = digitalRead(MOTION_PIN);

  // Exibição das informações no display LCD
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("T: ");
  lcd.print(temperature);
  lcd.print(" C");

  lcd.setCursor(9, 0);
  lcd.print("U: ");
  lcd.print(humidity);
  lcd.print("%");
  
  lcd.setCursor(0,1);
  lcd.print("P: ");
  lcd.print(motionDetected == HIGH ? "Sim" : "Nao");

  // Exibe as informações no monitor serial
  Serial.print("Temperatura: ");
  Serial.print(temperature);
  Serial.print("°C, Umidade: ");
  Serial.print(humidity);
  Serial.print("%, Presença: ");
  Serial.println(motionDetected == HIGH ? "Sim" : "Não");

  // Simula o controle do "ar condicionado"
  if (temperature >= 23 && motionDetected == HIGH) {
    irsend.sendRaw(rawDataOn, rawDataLen, 38);  // Envia o sinal de infravermelho para ligar
    lcd.setCursor(9, 1);
    lcd.print("AC: On");
    Serial.println("Ar condicionado ligado");
  } else {
    irsend.sendRaw(rawDataOff, rawDataLen, 38);  // Envia o sinal de infravermelho para desligar
    lcd.setCursor(9, 1);
    lcd.print("AC: Off");
    Serial.println("Ar condicionado desligado");
  }

  delay(60000); // Aguarda 60 segundos antes de fazer a próxima leitura
}

Como que voce obteve estes códigos RAW?

Clonando a tecla liga e desliga do aparelho de ar condicionado através do código abaixo:

#define LEDPIN 13
//you may increase this value on Arduinos with greater than 2k SRAM
#define maxLen 800
#define rxPinIR 35 //pin D2 or D3 on standard arduinos. (other pins may be available on More mordern modules like MEga2560, DUE, ESP8266, ESP32)


volatile  unsigned int irBuffer[maxLen]; //stores timings - volatile because changed by ISR
volatile unsigned int x = 0; //Pointer thru irBuffer - volatile because changed by ISR

void setup() {
  Serial.begin(115200); //change BAUD rate as required
  attachInterrupt(digitalPinToInterrupt(rxPinIR), rxIR_Interrupt_Handler, CHANGE);//set up ISR for receiving IR signal
}

void loop() {
  // put your main code here, to run repeatedly:

  Serial.println(F("Press the button on the remote now - once only"));
  delay(5000); // pause 5 secs
  if (x) { //if a signal is captured
    digitalWrite(LEDPIN, HIGH);//visual indicator that signal received
    Serial.println();
    Serial.print(F("Raw: (")); //dump raw header format - for library
    Serial.print((x - 1));
    Serial.print(F(") "));
    detachInterrupt(digitalPinToInterrupt(rxPinIR));//stop interrupts & capture until finshed here
    for (int i = 1; i < x; i++) { //now dump the times
      if (!(i & 0x1)) Serial.print(F("-"));
      Serial.print(irBuffer[i] - irBuffer[i - 1]);
      Serial.print(F(", "));
    }
    x = 0;
    Serial.println();
    Serial.println();
    digitalWrite(LEDPIN, LOW);//end of visual indicator, for this time
    attachInterrupt(digitalPinToInterrupt(rxPinIR), rxIR_Interrupt_Handler, CHANGE);//re-enable ISR for receiving IR signal
  }

}

void rxIR_Interrupt_Handler() {
  if (x > maxLen) return; //ignore if irBuffer is already full
  irBuffer[x++] = micros(); //just continually record the time-stamp of signal transitions

}

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