Can someone help me clean my code?

So, I’m trying to control my air conditioner with arduino, but I have to input the code as RAW data, that makes it to heavy for the arduino, I think uploading the RAW data to an SD card could help, but I don’t know. would someone help me?

Here is my code (this is the code for 1 air conditioner ONLY, it’s just a part of my code. :grin: )

#define BLYNK_PRINT Serial
#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
#include <IRremote.h>
IRsend irsend;

char auth[] = "XXXXXXXXXXXX";

#define W5100_CS  10
#define SDCARD_CS 4

void setup()
{
  pinMode(SDCARD_CS, OUTPUT);
  digitalWrite(SDCARD_CS, HIGH);

  Serial.begin(115200);
  Blynk.begin(auth);
}

// Início Funções Ar da Sala

BLYNK_WRITE(V4) // On/off
{
  int ligdesl = param.asInt();
  if (ligdesl == 1) {
    int khz = 38; // 38kHz carrier frequency for the NEC protocol
    unsigned int irSignal[] = {3188, 9856, 548, 1544, 520, 524, 520, 516, 520, 516, 524, 1532, 548, 520, 520, 516, 520, 524, 520, 504, 544, 520, 520, 500, 548, 512, 520, 524, 460, 596, 520, 520, 524, 496, 548, 496, 548, 1564, 460, 1620, 544, 1552, 520, 516, 520, 524, 520, 524, 460, 568, 548, 512, 520, 1560, 460, 1620, 460, 1612, 520};

    irsend.sendRaw(irSignal, sizeof(irSignal) / sizeof(irSignal[0]), khz);
  }
  else {
    int khz = 38; // 38kHz carrier frequency for the NEC protocol
    unsigned int irSignal[] = {3212, 9848, 532, 1536, 564, 504, 536, 488, 560, 500, 536, 1536, 536, 508, 536, 480, 564, 500, 536, 1516, 564, 1532, 536, 504, 536, 500, 536, 484, 560, 500, 528, 500, 560, 480, 572, 484, 560, 480, 564, 484, 560, 500, 524, 504, 560, 1520, 560, 484, 560, 1548, 536, 512, 536, 484, 560, 496, 540, 1548, 460};

    irsend.sendRaw(irSignal, sizeof(irSignal) / sizeof(irSignal[0]), khz);
  }
}
BLYNK_WRITE(V5) //Control Temp
{
  int temparsala = param.asInt();
  if (temparsala == 18) {
    int khz = 38; // 38kHz carrier frequency for the NEC protocol
    unsigned int irSignal[] = {3132, 9912, 528, 1532, 488, 580, 464, 572, 464, 572, 492, 1580, 464, 572, 464, 580, 464, 584, 488, 524, 520, 544, 464, 580, 464, 572, 464, 1616, 464, 580, 464, 580, 464, 564, 516, 552, 464, 564, 516, 1584, 464, 1616, 516, 544, 464, 572, 464, 580, 464, 592, 488, 1588, 464, 572, 464, 1616, 464, 1592, 516, 3876, 208};

    irsend.sendRaw(irSignal, sizeof(irSignal) / sizeof(irSignal[0]), khz);
  }
  else if (temparsala == 19) {
    int khz = 38; // 38kHz carrier frequency for the NEC protocol
    unsigned int irSignal[] = {3196, 9860, 548, 1520, 488, 580, 464, 580, 464, 572, 464, 1608, 464, 580, 464, 556, 488, 572, 464, 556, 488, 576, 468, 572, 460, 572, 464, 1612, 464, 576, 464, 572, 464, 584, 460, 564, 488, 1624, 464, 556, 488, 572, 464, 568, 484, 556, 488, 572, 464, 572, 464, 1608, 464, 1608, 464, 572, 464, 580, 464};

    irsend.sendRaw(irSignal, sizeof(irSignal) / sizeof(irSignal[0]), khz);
  }
  else if (temparsala == 20) {
    int khz = 38; // 38kHz carrier frequency for the NEC protocol
    unsigned int irSignal[] = {3208, 9852, 516, 1600, 464, 580, 464, 560, 484, 580, 464, 1600, 488, 572, 464, 572, 464, 580, 464, 556, 488, 572, 464, 564, 488, 560, 484, 1632, 464, 556, 488, 572, 464, 580, 464, 572, 464, 1608, 464, 580, 464, 1588, 492, 576, 468, 556, 488, 564, 488, 556, 488, 1600, 484, 1592, 488, 580, 464, 1616, 464};

    irsend.sendRaw(irSignal, sizeof(irSignal) / sizeof(irSignal[0]), khz);
  }
  else if (temparsala == 21) {
    int khz = 38; // 38kHz carrier frequency for the NEC protocol
    unsigned int irSignal[] = {3164, 9908, 484, 1584, 488, 556, 516, 544, 464, 564, 516, 1564, 516, 528, 516, 544, 464, 572, 464, 580, 532, 492, 516, 552, 468, 564, 516, 1592, 464, 568, 484, 556, 520, 528, 512, 544, 464, 1616, 464, 1616, 464, 580, 464, 576, 460, 560, 512, 552, 464, 560, 512, 1596, 464, 1608, 464, 1624, 464, 556, 488};

    irsend.sendRaw(irSignal, sizeof(irSignal) / sizeof(irSignal[0]), khz);
  }
  else if (temparsala == 22) {
    int khz = 38; // 38kHz carrier frequency for the NEC protocol
    unsigned int irSignal[] = {3212, 9856, 488, 1584, 564, 476, 564, 496, 492, 564, 536, 1516, 520, 524, 516, 552, 492, 556, 488, 544, 492, 544, 492, 544, 496, 540, 492, 1588, 492, 556, 488, 552, 492, 552, 492, 536, 516, 1596, 492, 1600, 496, 1584, 496, 540, 496, 544, 492, 540, 496, 552, 492, 1568, 520, 1584, 492, 1572, 516, 1580, 492, 21260, 260};

    irsend.sendRaw(irSignal, sizeof(irSignal) / sizeof(irSignal[0]), khz);
  }
  else if (temparsala == 23) {
    int khz = 38; // 38kHz carrier frequency for the NEC protocol
    unsigned int irSignal[] = {3172, 9872, 548, 1508, 556, 516, 460, 556, 556, 508, 524, 1544, 464, 580, 464, 584, 528, 504, 536, 492, 556, 488, 560, 492, 556, 516, 532, 1536, 556, 484, 560, 504, 464, 572, 528, 1544, 528, 508, 532, 504, 528, 508, 464, 580, 532, 504, 528, 492, 556, 512, 528, 492, 556, 504, 528, 492, 556, 504, 528};

    irsend.sendRaw(irSignal, sizeof(irSignal) / sizeof(irSignal[0]), khz);
  }
  else if (temparsala == 24) {
    int khz = 38; // 38kHz carrier frequency for the NEC protocol
    unsigned int irSignal[] = {3136, 9904, 484, 1576, 516, 552, 492, 528, 516, 544, 492, 1580, 492, 552, 492, 528, 516, 544, 492, 536, 516, 528, 516, 532, 520, 552, 492, 1576, 520, 524, 520, 540, 492, 544, 496, 1576, 492, 544, 496, 540, 492, 1580, 492, 544, 496, 548, 492, 544, 492, 544, 492, 544, 492, 536, 516, 528, 516, 1580, 516};

    irsend.sendRaw(irSignal, sizeof(irSignal) / sizeof(irSignal[0]), khz);
  }
  else {
    int khz = 38; // 38kHz carrier frequency for the NEC protocol
    unsigned int irSignal[] = {3224, 9820, 588, 1504, 568, 504, 540, 476, 564, 496, 540, 1532, 540, 504, 544, 488, 560, 496, 540, 496, 540, 504, 540, 480, 564, 504, 540, 1540, 540, 480, 564, 504, 540, 480, 564, 1528, 568, 512, 540, 1520, 568, 496, 536, 504, 544, 492, 540, 500, 536, 496, 540, 500, 540, 512, 536, 1548, 544, 512, 536, 47064, 208};

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

BLYNK_WRITE(V6) // Control Swing
{
  int swingarsala = param.asInt();
  if (swingarsala == 1) {
    int khz = 38; // 38kHz carrier frequency for the NEC protocol
    unsigned int irSignal[] = {3128, 9916, 456, 1604, 512, 560, 484, 560, 480, 556, 452, 1616, 456, 592, 484, 552, 456, 564, 480, 572, 508, 560, 456, 572, 508, 1604, 456, 572, 508, 536, 508, 1572, 508, 1596, 452, 584, 456, 564, 508, 560, 484, 1588, 456, 588, 484, 1588, 456, 580, 484, 552, 484, 1552, 520, 560, 456, 580, 484, 1572, 508};

    irsend.sendRaw(irSignal, sizeof(irSignal) / sizeof(irSignal[0]), khz);
  }
  else {
    int khz = 38; // 38kHz carrier frequency for the NEC protocol
    unsigned int irSignal[] = {3152, 9908, 492, 1600, 464, 572, 464, 572, 464, 572, 464, 1592, 512, 548, 464, 564, 492, 564, 508, 536, 508, 556, 464, 572, 464, 1604, 468, 572, 464, 580, 464, 1628, 468, 1604, 468, 580, 464, 564, 512, 556, 464, 1600, 488, 580, 464, 1600, 488, 568, 468, 1604, 468, 1604, 468, 576, 468, 1596, 516, 544, 464};

    irsend.sendRaw(irSignal, sizeof(irSignal) / sizeof(irSignal[0]), khz);
  }
}
BLYNK_WRITE(V7) // Control Wind
{
  int windarsala = param.asInt();
  if (windarsala == 1) {
    int khz = 38; // 38kHz carrier frequency for the NEC protocol
    unsigned int irSignal[] = {3116, -9896, 500, -1608, 476, -564, 508, -548, 472, -596, 452, -1608, 480, -556, 480, -568, 448, -548, 572, -544, 452, -572, 476, -568, 476, -576, 476, -1608, 496, -536, 476, -584, 452, -516, 500, -588, 500, -1612, 452, -1600, 480, -1620, 452, -576, 448, -596, 476, -1640, 452, -564, 456, -584, 476, -560, 448, -620, 452, -1612, 476, -13360, 3164, -9876, 476, -1640, 448, -592, 452, -584, 452, -520, 516, -1604, 480, -588, 452, -584, 452, -592, 452, -568, 448, -620, 452, -568, 472, -588, 452, -1644, 452, -592, 452, -576, 472, -572, 472, -584, 452, -1604, 476, -1620, 452, -1596, 448, -620, 452, -1616, 472, -560, 472, -596, 452, -568, 476, -560, 448, -1656, 448, -1624, 424, -15456, 3116, -9916, 448, -1636, 452, -608, 452, -560, 500, -568, 452, -1620, 452, -576, 476, -568, 472, -572, 448, -588, 476, -592, 452, -560, 476, -600, 448, -1612, 476, -560, 476, -556, 484, -564, 452, -616, 428, -1644, 424, -1640, 476, -1612, 476, -556, 452, -1652, 452, -568, 480, -1628, 452, -560, 472, -1612, 448, -608, 444, -620, 452, -12648, 3188, -9824, 572, -1560, 520, -500, 480, -596, 520, -524, 456, -1604, 548, -512, 520, -528, 516, -528, 520, -496, 544, -508, 544, -500, 484, -596, 516, -1532, 548, -516, 520, -516, 516, -528, 456, -576, 520, -1544, 548, -1532, 544, -1552, 456, -572, 544, -524, 456, -572, 544, -516, 520, -1556, 520, -1560, 520, -1552, 516, -1552, 460};

    irsend.sendRaw(irSignal, sizeof(irSignal) / sizeof(irSignal[0]), khz);
  }
  else if (windarsala == 2) {
    int khz = 38; // 38kHz carrier frequency for the NEC protocol
    unsigned int irSignal[] = {3216, -9816, 552, -1532, 556, -504, 528, -512, 524, -496, 552, -1540, 532, -524, 524, -520, 524, -520, 524, -508, 524, -520, 524, -512, 532, -496, 552, -1560, 528, -508, 524, -512, 524, -520, 524, -496, 552, -1544, 524, -1560, 524, -1564, 528, -508, 528, -508, 528, -1528, 552, -520, 524, -508, 524, -520, 528, -516, 528, -1544, 524, -40984, 204};

    irsend.sendRaw(irSignal, sizeof(irSignal) / sizeof(irSignal[0]), khz);
  }
  else if (windarsala == 3) {
    int khz = 38; // 38kHz carrier frequency for the NEC protocol
    unsigned int irSignal[] = {3164, -9824, 572, -1560, 524, -524, 516, -512, 544, -496, 484, -1604, 544, -516, 520, -524, 520, -500, 544, -500, 484, -568, 544, -500, 544, -508, 544, -1532, 548, -512, 524, -516, 520, -520, 524, -512, 524, -1540, 548, -1532, 544, -1552, 460, -568, 544, -1568, 520, -500, 544, -516, 520, -524, 520, -516, 516, -1540, 552, -1548, 524};

    irsend.sendRaw(irSignal, sizeof(irSignal) / sizeof(irSignal[0]), khz);
  }
  else {
    int khz = 38; // 38kHz carrier frequency for the NEC protocol
    unsigned int irSignal[] = {3192, -9876, 536, -1536, 544, -496, 548, -512, 460, -568, 548, -1532, 544, -500, 544, -520, 524, -524, 520, -524, 520, -516, 520, -524, 520, -500, 544, -1552, 520, -520, 524, -512, 524, -516, 520, -524, 520, -1556, 524, -1532, 544, -1552, 460, -568, 544, -1544, 544, -516, 456, -1612, 460, -576, 460, -1628, 460, -564, 480, -584, 460};

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



void loop()
{
  Blynk.run();
}

@borges_rafa does your code work without Blynk and what Arduino are you using?

I would buy an ESP for a few dollars with 1MB of programmable memory and ditch the Arduino.

Yes, it works works without blynk, but I tested separately each button, just to see if it works. It is working fine if I use less functions, but it would not be usefull…

Which Arduino?

it’s an arduino uno :grin:

So, I got an ESP (NodeMCU) but now I can’t make it work, I’m trying to use the IR Remote ESP 8266 library, but it simply does not work, I’m not even using blynk yet for the IR.

I’m using Arduino IDE

Have you tried the receive demo for ESP to recapture the IR codes before trying to send them?

So, yes, i recaptured the IR codes today, but I found another sketch that works, but I can go up to 6 feet away from the device, would you know to increase that distance?

I learnt much of my IR stuff from these guys https://www.analysir.com/blog/2013/11/22/constant-current-infrared-led-circuit/

The link is for boosting the abysmal range you get with a regular IR circuit.

Cool, thank you, now my project is almost over. thank you again.

@borges_rafa the Infrared modules they sell can handle 10m+ range and further if you add a resistor. Well worth a look.