Receiving raw IR signals from AC

Hello guys, I need some help with my code, I already decoded raw signals from my Air Conditioner, and they work perfectly, buy now I want make a new function.

When I receive a raw signal, for example Air Conditioner Power On I want to register this on my code, for example:


if (rawSignal == xxxxxx){
acIsOn = 1;

This is my entire code:


#include <OneWire.h>
#include <DallasTemperature.h>
#include <BlynkSimpleEsp8266.h>
#include <DHT.h>
#include <IRremoteESP8266.h>
#include "MUX74HC4067.h"



int RECV_PIN = D3; //PINO DIGITAL EM QUE O FOTORRECEPTOR ESTÁ CONECTADO - GPIO12 / PINO D6

const int RelePin = 2;
const int RelePin2 = 14;

const int sensorIn = A0;
int mVperAmp = 66; // Use 100 for 20A Module and 66 for 30A Module

double Voltage = 0;
double VRMS = 0;
double AmpsRMS = 0;

unsigned long inicio, fin, transcurrido;

unsigned int chequeado = 0;

unsigned long codeValue;





MUX74HC4067 mux(D0, D1);



//OneWire ourWire(D1);        //Se establece el D1  como bus OneWire

//DallasTemperature sensors(&ourWire); //Se declara una variable u objeto para nuestro sensor



#define DHTPIN 13         // Definimos el pin al que conectaremos el DHT22






WidgetTerminal terminal(V21);




// definimos que tipo de DHT estaerror lectura temperaturamos usando
#define DHTTYPE DHT22   // DHT 22, AM2302, AM2321


DHT dht(DHTPIN, DHTTYPE);

//SimpleTimer timer;

BlynkTimer timer;


IRrecv irrecv(RECV_PIN);

decode_results results; //Variable que alamacena resultados- b3ae4026b9f44f5eb6d28cb2cd385d0d


char auth[] = "xxxx";
char ssid[] = "xxxx";
char pass[] = "xxxx";





IRsend irsend(4); //LED emisor INFRA conectado en PIN 4

int khz = 38;

//Señal infrarroja de apagado AIRE
unsigned int OFF[] = {9022, 4016, 603, 612, 601, 587, 603, 613, 600, 588, 601, 612, 603, 588, 599, 613, 601, 589, 598, 1616, 602, 589, 599, 613, 601, 1592, 598, 613, 601, 591, 625, 586, 600, 613, 602, 586, 601, 618, 594, 589, 603, 612, 599, 589, 602, 1615, 598, 1592, 601, 613, 598, 589, 601, 613, 600, 587, 602, 612, 602, 1589, 599, 614, 601, 1589, 601, 613, 601, 588, 599, 1616, 600, 589, 600, 20001, 599, 613, 601, 589, 621, 590, 599, 590, 625, 584, 601, 613, 572, 615, 600, 614, 597, 590, 600, 613, 599, 588, 600, 612, 602, 587, 600, 1615, 601, 586, 600, 613, 601, 589, 599, 613, 600, 588, 626, 585, 602, 591, 623, 585, 601, 612, 574, 614, 602, 612, 599, 589, 601, 612, 600, 589, 599, 1615, 599, 588, 601, 1614, 600, 587, 602};

//Señal infrarroja de encendido AIRE
unsigned int ON[] =  {9019, 4017, 601, 613, 601, 588, 600, 613, 601, 1591, 599, 613, 602, 588, 599, 614, 600, 590, 621, 1593, 600, 591, 596, 614, 602, 1591, 599, 613, 602, 591, 650, 560, 602, 612, 574, 614, 602, 614, 596, 590, 601, 612, 599, 589, 600, 1616, 599, 1591, 601, 613, 598, 589, 601, 614, 600, 588, 600, 614, 601, 1590, 601, 612, 601, 1590, 601, 613, 601, 589, 599, 1617, 600, 588, 601, 20014, 601, 613, 601, 589, 651, 561, 601, 613, 602, 587, 601, 613, 572, 615, 602, 614, 597, 590, 600, 614, 601, 588, 601, 612, 601, 589, 599, 1616, 600, 588, 600, 614, 601, 588, 599, 613, 601, 592, 623, 587, 600, 614, 601, 587, 601, 614, 599, 589, 601, 613, 599, 589, 601, 613, 601, 589, 600, 1616, 601, 587, 601, 1616, 601, 1590, 602};

unsigned int aire24[] =  {9040, 3990, 629, 1588, 599, 588, 605, 614, 595, 1591, 602, 1615, 598, 1598, 624, 587, 597, 591, 602, 612, 599, 589, 602, 613, 599, 1592, 602, 612, 600, 589, 629, 586, 600, 588, 602, 614, 627, 561, 601, 613, 601, 589, 623, 589, 602, 1591, 627, 1587, 628, 1565, 628, 585, 602, 590, 625, 587, 627, 564, 626, 1589, 602, 589, 628, 1587, 629, 563, 624, 589, 600, 1593, 624, 588, 601, 19992, 650, 587, 596, 590, 629, 586, 599, 589, 602, 613, 599, 590, 627, 587, 600, 588, 626, 588, 600, 589, 599, 613, 627, 565, 624, 587, 626, 1568, 626, 585, 602, 590, 595, 616, 627, 587, 599, 588, 657, 557, 599, 588, 629, 585, 625, 564, 600, 612, 601, 589, 599, 615, 628, 560, 599, 613, 602, 1592, 626, 585, 627, 1565, 626, 1589, 628};


unsigned int ventilador[] =  {9034, 3994, 626, 1593, 571, 1619, 601, 593, 593, 1620, 629, 1569, 595, 1621, 623, 1569, 624, 590, 599, 593, 624, 586, 624, 591, 598, 1593, 600, 615, 574, 614, 602, 614, 572, 618, 625, 588, 599, 589, 628, 588, 598, 590, 600, 616, 600, 1591, 627, 1592, 572, 616, 627, 588, 598, 592, 625, 589, 600, 590, 598, 1618, 627, 564, 625, 1592, 599, 590, 626, 590, 599, 1593, 625, 588, 600, 19998, 651, 1566, 598, 615, 625, 566, 596, 617, 599, 592, 596, 614, 628, 590, 570, 617, 627, 589, 595, 593, 625, 588, 600, 590, 600, 614, 601, 1591, 601, 616, 597, 592, 598, 614, 626, 567, 597, 614, 628, 566, 620, 590, 625, 591, 599, 590, 600, 615, 596, 590, 629, 588, 570, 615, 599, 617, 599, 1590, 630, 1588, 573, 1621, 625, 1589, 600};


unsigned int Grados20[] = {8928, 4080, 539, 1679, 540, 674, 516, 674, 567, 1623, 569, 1678, 515, 1652, 568, 647, 542, 645, 544, 805, 406, 674, 542, 1651, 567, 649, 541, 673, 541, 647, 594, 596, 595, 620, 540, 755, 461, 621, 566, 677, 540, 622, 566, 674, 539, 1652, 541, 1677, 567, 1652, 540, 702, 512, 641, 524, 649, 566, 673, 513, 1652, 567, 647, 570, 1619, 570, 648, 540, 647, 540, 1703, 517, 648, 566, 20024, 593, 700, 490, 752, 462, 673, 513, 673, 540, 650, 566, 648, 541, 648, 567, 621, 568, 646, 568, 623, 591, 620, 568, 622, 539, 703, 539, 1652, 541, 672, 545, 697, 516, 620, 569, 622, 592, 622, 591, 623, 567, 676, 513, 673, 514, 646, 543, 701, 542, 645, 568, 597, 564, 702, 516, 672, 540, 1624, 594, 620, 567, 647, 569, 1650, 542};


unsigned int Grados21[] = {8956, 4053, 571, 1650, 567, 620, 595, 622, 568, 1649, 540, 1679, 513, 1677, 542, 647, 541, 673, 543, 1649, 571, 644, 544, 1650, 569, 595, 620, 619, 543, 672, 567, 622, 567, 621, 594, 621, 568, 619, 568, 700, 489, 672, 542, 649, 567, 1678, 515, 1675, 543, 1623, 569, 621, 591, 622, 570, 646, 595, 619, 569, 1622, 598, 593, 567, 1656, 562, 647, 540, 677, 540, 1624, 568, 647, 568, 20026, 620, 622, 541, 647, 564, 676, 515, 676, 539, 649, 542, 700, 542, 620, 567, 620, 571, 672, 541, 621, 567, 674, 515, 703, 547, 689, 491, 1626, 542, 701, 540, 673, 461, 699, 569, 646, 566, 623, 567, 646, 568, 646, 542, 673, 516, 673, 541, 646, 593, 593, 571, 647, 568, 619, 540, 649, 593, 620, 569, 1648, 623, 594, 542, 1647, 570};


unsigned int Grados22[] = {9003, 4045, 572, 1619, 623, 591, 572, 616, 598, 1617, 571, 1618, 599, 1618, 598, 587, 626, 590, 570, 616, 626, 1591, 570, 1618, 627, 568, 593, 616, 623, 590, 571, 616, 599, 614, 599, 589, 625, 588, 571, 618, 599, 615, 623, 564, 598, 1617, 597, 1592, 602, 1613, 596, 593, 599, 614, 598, 589, 626, 586, 600, 1596, 594, 616, 623, 1564, 624, 590, 601, 589, 596, 1617, 625, 565, 624, 19959, 642, 591, 624, 591, 571, 617, 622, 589, 572, 616, 626, 586, 575, 613, 598, 616, 597, 591, 651, 562, 598, 590, 597, 615, 599, 590, 624, 1589, 600, 590, 598, 614, 600, 592, 595, 617, 597, 618, 569, 617, 623, 591, 571, 615, 624, 591, 571, 617, 626, 588, 597, 591, 625, 591, 596, 592, 597, 1617, 596, 1596, 596, 616, 598, 1594, 621};


unsigned int Grados23[] = {8953, 4141, 395, 1742, 556, 716, 500, 671, 513, 1680, 514, 1699, 517, 1673, 461, 855, 415, 725, 461, 1730, 492, 1620, 568, 1676, 564, 623, 540, 699, 492, 724, 462, 728, 513, 674, 516, 835, 269, 781, 514, 748, 520, 646, 489, 673, 539, 1704, 488, 1702, 516, 1647, 567, 623, 619, 592, 543, 645, 596, 673, 487, 1627, 589, 730, 432, 1675, 565, 677, 442, 774, 535, 1628, 540, 674, 541, 20043, 570, 657, 532, 726, 486, 726, 462, 675, 538, 754, 456, 682, 513, 672, 546, 707, 478, 716, 498, 705, 485, 764, 449, 673, 541, 640, 548, 1732, 459, 624, 564, 701, 542, 620, 622, 594, 538, 675, 540, 673, 516, 674, 566, 654, 536, 672, 514, 673, 542, 647, 541, 649, 566, 674, 543, 619, 565, 650, 566, 714, 473, 1679, 513, 1704, 513};


unsigned int Grados24[] = {8976, 4046, 569, 1620, 596, 595, 595, 615, 598, 1618, 571, 1619, 597, 1593, 598, 616, 597, 616, 598, 590, 595, 617, 596, 591, 624, 1592, 570, 619, 596, 617, 569, 619, 595, 617, 596, 591, 597, 617, 569, 641, 569, 623, 592, 617, 572, 1619, 594, 1597, 595, 1619, 595, 592, 598, 641, 596, 565, 597, 616, 625, 1566, 596, 617, 595, 1593, 599, 615, 596, 592, 598, 1619, 595, 593, 595, 20009, 597, 618, 596, 617, 573, 616, 597, 616, 571, 616, 598, 616, 570, 617, 597, 619, 568, 619, 597, 617, 595, 592, 621, 617, 597, 566, 597, 1621, 618, 567, 622, 589, 597, 591, 624, 588, 598, 617, 594, 592, 598, 615, 570, 617, 597, 640, 546, 618, 594, 619, 595, 592, 598, 639, 570, 592, 624, 1593, 593, 592, 596, 1620, 569, 1620, 596};


unsigned int Grados25[] = {9027, 4019, 571, 1619, 599, 614, 573, 617, 598, 1617, 571, 1621, 599, 1594, 597, 614, 628, 586, 573, 1620, 599, 613, 573, 616, 600, 1617, 573, 616, 626, 588, 571, 617, 627, 587, 571, 616, 600, 615, 623, 564, 600, 616, 623, 565, 598, 1618, 597, 1591, 627, 1593, 623, 564, 597, 616, 599, 590, 625, 589, 598, 1593, 626, 588, 598, 1593, 626, 588, 626, 566, 597, 1618, 597, 591, 626, 19985, 626, 588, 624, 591, 571, 616, 599, 616, 572, 617, 598, 615, 598, 591, 625, 590, 597, 591, 599, 615, 599, 589, 626, 589, 626, 565, 595, 1617, 627, 563, 599, 616, 625, 565, 595, 616, 599, 617, 596, 590, 601, 615, 572, 615, 627, 587, 574, 617, 625, 588, 598, 592, 626, 589, 596, 593, 597, 617, 598, 1591, 629, 1593, 623, 1563, 600};


unsigned int Grados26[] = {9025,4017,574,1616,625,584,604,588,624,1570,595,1618,624,1566,625,586,626,566,595,614,599,1593,622,589,627,1567,594,615,600,614,599,590,599,615,571,615,600,614,571,616,626,588,597,589,627,1590,596,1593,599,614,598,589,599,615,625,564,626,586,600,1589,625,589,600,1590,600,614,599,588,599,1617,598,590,598,20010,598,617,598,590,625,588,654,558,573,615,628,586,597,590,599,616,596,591,626,587,599,589,600,614,599,590,625,1590,599,589,600,615,599,590,622,590,600,592,619,590,600,615,573,616,624,588,571,616,600,614,597,591,627,588,597,590,600,1616,626,1564,626,1591,572,1618,654};

unsigned int Grados27[] = {9081, 3966, 626, 1568, 623, 587, 627, 565, 622, 1594, 599, 1591, 626, 1589, 628, 563, 625, 588, 628, 1564, 626, 1592, 626, 563, 623, 1594, 599, 590, 625, 585, 630, 561, 626, 588, 626, 565, 623, 588, 626, 588, 599, 588, 600, 615, 597, 1594, 626, 1590, 602, 1588, 628, 587, 573, 614, 629, 586, 572, 615, 627, 1588, 575, 614, 601, 1616, 571, 615, 629, 587, 597, 1593, 629, 585, 599, 20011, 599, 590, 602, 614, 599, 590, 628, 584, 602, 589, 598, 615, 626, 564, 624, 587, 602, 612, 599, 592, 627, 585, 573, 616, 626, 588, 571, 1619, 626, 587, 577, 612, 626, 587, 599, 589, 628, 586, 625, 563, 601, 615, 627, 563, 623, 589, 601, 590, 625, 587, 625, 567, 594, 615, 626, 589, 597, 593, 625, 587, 596, 592, 625, 587, 600};


unsigned int Grados28[] = {9061, 3992, 629, 1564, 602, 612, 628, 563, 624, 1590, 630, 1563, 601, 1617, 599, 588, 602, 614, 626, 562, 603, 612, 628, 1564, 627, 1589, 598, 590, 629, 585, 629, 559, 600, 614, 601, 587, 601, 612, 602, 590, 598, 613, 629, 585, 573, 1618, 627, 1568, 624, 1591, 625, 565, 624, 587, 602, 591, 594, 614, 602, 1595, 595, 615, 628, 1566, 597, 615, 600, 613, 600, 1591, 603, 611, 599, 19992, 620, 588, 629, 587, 627, 561, 601, 613, 626, 562, 600, 612, 602, 588, 627, 587, 601, 589, 599, 613, 629, 565, 593, 614, 629, 585, 598, 1592, 629, 586, 598, 588, 603, 613, 599, 587, 628, 586, 628, 560, 601, 613, 602, 587, 601, 612, 629, 562, 626, 584, 603, 591, 624, 585, 602, 613, 573, 1618, 602, 612, 573, 614, 628, 588, 598};


unsigned int Grados29[] = {9016, 3995, 597, 1616, 603, 588, 625, 587, 602, 1592, 599, 1617, 625, 1567, 601, 611, 605, 588, 599, 1616, 654, 537, 624, 1590, 603, 1591, 628, 587, 627, 563, 624, 586, 631, 560, 627, 585, 602, 593, 595, 615, 602, 612, 596, 590, 656, 1562, 574, 1618, 629, 1567, 597, 614, 627, 586, 574, 616, 628, 586, 597, 1594, 628, 587, 595, 1594, 628, 587, 599, 590, 600, 1618, 571, 617, 626, 19988, 602, 613, 600, 589, 627, 587, 626, 563, 627, 585, 628, 563, 626, 586, 626, 565, 624, 588, 627, 587, 571, 616, 628, 587, 598, 590, 600, 1617, 598, 590, 627, 588, 597, 590, 626, 586, 605, 584, 627, 586, 630, 561, 599, 611, 631, 562, 625, 586, 627, 586, 574, 615, 628, 584, 574, 616, 629, 583, 599, 1593, 628, 585, 599, 588, 602};


unsigned int Grados30[] = {9004, 4044, 572, 1618, 600, 615, 570, 617, 598, 1617, 572, 1617, 628, 1564, 623, 588, 599, 592, 593, 616, 626, 1589, 572, 1617, 626, 1564, 598, 611, 628, 565, 620, 589, 628, 588, 595, 590, 627, 588, 598, 589, 625, 590, 597, 590, 599, 1618, 598, 1592, 626, 1590, 597, 591, 601, 614, 597, 589, 654, 559, 600, 1592, 599, 614, 598, 1592, 600, 614, 597, 589, 628, 1589, 600, 589, 627, 19958, 649, 586, 625, 565, 598, 612, 628, 588, 598, 589, 625, 588, 572, 616, 625, 588, 598, 590, 627, 586, 598, 590, 624, 588, 626, 562, 600, 1615, 599, 590, 624, 588, 627, 563, 624, 587, 628, 562, 626, 587, 625, 565, 623, 586, 600, 614, 570, 616, 627, 588, 597, 591, 625, 589, 599, 588, 628, 1588, 597, 1593, 629, 584, 598, 589, 629};

 




void setup()
{
  irsend.begin();
  Serial.begin(115200);
  Blynk.begin(auth, ssid, pass);
  pinMode(RelePin, OUTPUT);
  pinMode(RelePin2, OUTPUT);
  dht.begin();
  // sensors.begin();   //Se inicia el sensor
  mux.signalPin(A0, INPUT, ANALOG);





  // Configuramos el timer para que se ejecute cada 2 segundos
  timer.setInterval(60000L, sendSensor);
  // timer.setInterval(50000L, TempExterior);
  // timer.setInterval(70000L, SensorGas);

  timer.setInterval(10000L, CurrentSensor);
  timer.setInterval(5000L, Multiplexor);



  irrecv.enableIRIn();  //Inicia receptor INFRA

  ESP.wdtDisable();
  ESP.wdtEnable(WDTO_8S);




}



BLYNK_WRITE(V1) {
  int onoff = param.asInt();
  if (onoff == 1) {

    for (int i = 0; i < 3; i++)
    {

      irsend.sendNEC(0x20DF10EF, 32); // Prende TV Cuarto principal

      

    }

    Serial.println("Transmitting");
    terminal.println("Prender TV Main") ;
    terminal.flush();

    delay(1000);
    CurrentSensor();

  }

}
BLYNK_WRITE(V2) {
  int mode = param.asInt();
  if (mode == 1) {
    terminal.println("Apaga Aire Main") ;
    irsend.sendRaw(OFF, sizeof(OFF) / sizeof(OFF[0]), khz);  //Apaga aire
  }
  /* else
    {
            terminal.println("Apagar Aire Main") ;

    irsend.sendRaw(OFF, sizeof(OFF) / sizeof(OFF[0]), khz); //Apaga Aire Cuarto Principal

    }*/

}

BLYNK_WRITE(V3) {

  int aireFrio = param.asInt();
  if (aireFrio == 1) {

    irsend.sendRaw(aire24, sizeof(aire24) / sizeof(aire24[0]), khz);
Blynk.virtualWrite(V8, 24);
    
  }


}

BLYNK_WRITE(V4) {

  int ventilador_1 = param.asInt();
  if (ventilador_1 == 1) {

    irsend.sendRaw(ventilador, sizeof(ventilador) / sizeof(ventilador[0]), khz);


  }


}

BLYNK_WRITE(V8){
  // receive the step value as param.asInt() and then use switch to run different code
  switch(param.asInt()){
    
    case 20:
        irsend.sendRaw(Grados20, sizeof(Grados20) / sizeof(Grados20[0]), khz);    
        break;
    
    case 21:
    irsend.sendRaw(Grados21, sizeof(Grados21) / sizeof(Grados21[0]), khz);    
    break;    
    
    case 22:
    irsend.sendRaw(Grados22, sizeof(Grados22) / sizeof(Grados22[0]), khz);    
    break;
    
    case 23:
    irsend.sendRaw(Grados23, sizeof(Grados23) / sizeof(Grados23[0]), khz);    
    break;
    case 24:
    irsend.sendRaw(Grados24, sizeof(Grados24) / sizeof(Grados24[0]), khz);   
    break;
    case 25:
    irsend.sendRaw(Grados25, sizeof(Grados25) / sizeof(Grados25[0]), khz);    
    break;
    case 26:
    irsend.sendRaw(Grados26, sizeof(Grados26) / sizeof(Grados26[0]), khz);    
    break;
    case 27:
    irsend.sendRaw(Grados27, sizeof(Grados27) / sizeof(Grados27[0]), khz);    
    break;
    case 28:
    irsend.sendRaw(Grados28, sizeof(Grados28) / sizeof(Grados28[0]), khz);   
    break;
    case 29:
    irsend.sendRaw(Grados29, sizeof(Grados29) / sizeof(Grados29[0]), khz);    
    break;
    case 30:
    irsend.sendRaw(Grados30, sizeof(Grados30) / sizeof(Grados30[0]), khz);    
    break;
  }
}

BLYNK_WRITE(V10){
  // receive the step value as param.asInt() and then use switch to run different code
  switch(param.asInt()){
    
    case 1:
        irsend.sendRaw(Grados20, sizeof(Grados20) / sizeof(Grados20[0]), khz);    
        break;
    
 
  }
}

BLYNK_WRITE(V11) {
  switch (param.asInt())
  {
    case 1: // Item 1
      irsend.sendRC5(0x201, 12);
delay(200);
irsend.sendRC5(0xA00, 12);
delay(200);
irsend.sendRC5(0xA00, 12);
delay(200);
irsend.sendRC5(0x201, 12);

      break;
    
    case 2: // Item 2
      irsend.sendRC5(0x201, 12);
delay(200);
irsend.sendRC5(0xA00, 12);
delay(200);
irsend.sendRC5(0xA00, 12);
delay(200);
irsend.sendRC5(0x203, 12);
      break;

    case 3: // Item 3
 irsend.sendRC5(0x201, 12);
delay(200);
irsend.sendRC5(0xA00, 12);
delay(200);
irsend.sendRC5(0xA00, 12);
delay(200);
irsend.sendRC5(0xA05, 12);
      break;
  
  case 4:  // Item 4

   irsend.sendRC5(0x201, 12);
delay(200);
irsend.sendRC5(0xA00, 12);
delay(200);
irsend.sendRC5(0x203, 12);
delay(200);
irsend.sendRC5(0xA00, 12);
      break;


    default:
      Serial.println("Unknown item selected");
  }
}


BLYNK_WRITE(V12) {
  switch (param.asInt())
  {
    case 1: // Item 1
     Blynk.virtualWrite(V12, 1);
           irsend.sendRC5(0xA11, 12);

      break;

    case 2:
      Blynk.virtualWrite(V12, 2);
            irsend.sendRC5(0xA10, 12);

      break;

  }}
    






//Funcione lectura codigos INFRA

void dump(decode_results *results) {
  int count = results->rawlen;
  if (results->decode_type == UNKNOWN) {
    Serial.print("Unknown encoding: ");
  }
  else if (results->decode_type == NEC) {
    Serial.print("Decoded NEC: ");
  }
  else if (results->decode_type == SONY) {
    Serial.print("Decoded SONY: ");
  }
  else if (results->decode_type == RC5) {
    Serial.print("Decoded RC5: ");
  }
  else if (results->decode_type == RC6) {
    Serial.print("Decoded RC6: ");
  }
  else if (results->decode_type == PANASONIC) {
    Serial.print("Decoded PANASONIC - Address: ");
    Serial.print(results->panasonicAddress, HEX);
    Serial.print(" Value: ");
  }
  else if (results->decode_type == LG) {
    Serial.print("Decoded LG: ");
  }
  else if (results->decode_type == JVC) {
    Serial.print("Decoded JVC: ");
  }
  else if (results->decode_type == AIWA_RC_T501) {
    Serial.print("Decoded AIWA RC T501: ");
  }
  else if (results->decode_type == WHYNTER) {
    Serial.print("Decoded Whynter: ");
  }
  Serial.print(results->value, HEX);
  Serial.print(" (");
  Serial.print(results->bits, DEC);
  Serial.println(" bits)");
  Serial.print("Raw (");
  Serial.print(count, DEC);
  Serial.print("): ");

  for (int i = 1; i < count; i++) {
    if (i & 1) {
      Serial.print(results->rawbuf[i]*USECPERTICK, DEC);
    }
    else {
      Serial.write('-');
      Serial.print((unsigned long) results->rawbuf[i]*USECPERTICK, DEC);
    }
    Serial.print(" ");
  }
  Serial.println();






}
void loop() {
  Blynk.run();
  timer.run(); // Iniciamos SimpleTimer


  //Lectura codigos infrarrojos

  if (irrecv.decode(&results)) {

    codeValue = (results.rawlen, DEC);
    Serial.println(codeValue);
    dump(&results);
    irrecv.resume();
  }

  //Lectura codigos infrarrojos*/

}






//Definimos funcion para el DHT22
void sendSensor()
{


  float  h = dht.readHumidity();
  float  t = dht.readTemperature(); // o dht.readTemperature(true) para mostrar la Tº en Fahrenheit

  if (isnan(h) || isnan(t)) {
    Serial.println("Error al leer datos del sensor");
    //   Serial.println(DateTime.now());
    return;
  }
  // Puedes enviar cualquier datos en cualquier momento
  // pero no envíen más de 10 datos por segundo, sino su app no funcionará.
  Blynk.virtualWrite(V5, h);
  Blynk.virtualWrite(V6, t);
  Serial.println(t);
  Serial.println(h);




}


/*
  void TempExterior()
  {
   sensors.requestTemperatures();   //Se envía el comando para leer la temperatura
  float temp= sensors.getTempCByIndex(0); //Se obtiene la temperatura en ºC


  Blynk.virtualWrite(V7, temp);
  Serial.print("Temperatura= ");
  Serial.print(temp);
  Serial.println(" C");

  }
*/

/*
  void relayStatus_1(){

  int relayState = digitalRead(RelePin);
  if (relayState == LOW)
  {
  Serial.println("RELE1 LOW");
   led3.on();
  } else {
  Serial.println("RELE1 HIGH");
   led3.off();
  }


  }
*/




/* FUNCION SENSOR GAS
  void SensorGas()
  {
  int mq2 = (analogRead(gasPin));

  if (mq2>400){

           gasDetected = "Se detectó gas butano";
           Serial.println(gasDetected);
      }
      else
      {

           gasDetected= "Aire limpio";
           Serial.println(gasDetected);


      }

  Blynk.virtualWrite(V9, gasDetected);


  }*/

float getVPP()
{
  float result;
  int readValue;             // value read from the sensor
  int maxValue = 0;          // store max value here
  int minValue = 1024;       // store min value here

  uint32_t start_time = millis();
  while ((millis() - start_time) < 100) // sample for 1 Sec
  {
    readValue = analogRead(sensorIn);
    // see if you have a new maxValue
    if (readValue > maxValue)
    {
      /*record the maximum sensor value*/
      maxValue = readValue;
    }
    if (readValue < minValue)
    {
      /*record the minimum sensor value*/
      minValue = readValue;
    }
  }

  // Subtract min from max
  result = ((maxValue - minValue) * 5.0) / 1024.0;

  return result;
}

void CurrentSensor()
{



  Voltage = getVPP();
  VRMS = (Voltage / 2.0) * 0.707; //root 2 is 0.707
  AmpsRMS = (VRMS * 1000) / mVperAmp;

  /* Serial.print(AmpsRMS);
    Serial.println(" Amps RMS");*/

  //Blynk.virtualWrite(V9, AmpsRMS);


  if (AmpsRMS > 0.50) {
    Blynk.virtualWrite(V1, HIGH);
  }
  else
  {
    Blynk.virtualWrite(V1, LOW);
  }


}





void Multiplexor()

{





  ESP.wdtFeed();

  int data;


  // Reads from channel i. Returns a value from 0 to 1023
  data = mux.read(0);
  /* Serial.print("Potentiometer at channel ");
    Serial.print(0);
    Serial.print(" is at ");
    Serial.print((double)(data) * 100 / 1023);
    Serial.println("%%");

     Serial.println();*/




}



void apagarAire() {
  irsend.sendRaw(OFF, sizeof(OFF) / sizeof(OFF[0]), khz); //Apaga Aire Cuarto Principal

}

void prenderAire() {

  irsend.sendRaw(ON, sizeof(ON) / sizeof(ON[0]), khz);  //Prende Aire Cuarto Principal


}






/*  BLYNK_CONNECTED() {
    if (isFirstConnect) {
  Blynk.syncAll();
  isFirstConnect = false;}
          terminal.println("Blynk se ha conectado") ;

  }*/


I want this function to work because I need to know the status of my equipments, for example y need to know if my TV is on or if my AC is on FAN or COOL.

Thanks in advance

1 Like

It would help if you gave us a few clues about what happens when you compile and run your existing code. Is there one particular thing that’s not working.

Also, it’s not good to mix proper GPIO references with those printed on the NodeMCU board. Stick with the proper GPIO numbers.

Pete.

1 Like

The code work as expected, no errors, but as I comment I want to add the new function to log RAW signals from my AC, and log if its on or off, or if its on Cool or Fan, to reflect these on my blynk app. For example, I need to know if my AC is on to power it, or I want to know if in my son room the AC is on cool or fan. Thanks in advance.

Okay. I’m travelling at the moment and reading this on my phone, which makes it difficult to work-out what your code is doing, but you appear to be sending IR signals and monitoring power consumption with your existing setup.

The problem you’ll have is that an IR signal from an existing remote control could be sent at any time and could be quite short (half a second maybe), so you either need to be constantly listening g for that signal or you need to have the IR receiver connected to an interrupt that triggers a piece of code when a signal is received.
Because of the way that Blynk works in normal use, I don’t think this approach will work for you, especially not integrating the IR listening code into your existing sketch.

I think that if I were tackling this problem I’d use a separate MCU with the IR receiver connnected to it and use this to listen for IR signals and update Blynk when a recognised signal has been received.

Pete.