1

I made a Arduino program to control my air conditioner(model:GREE Lomo) by PC. I download IRremote library from here for that.

#include "IRremote.h"

IRsend irsend;
int irPin = 3; // pin IR led

int khz = 38; // 38kHz carrier frequency for the NEC protocol

const unsigned int irSignalOn[] = {8972, 4492, 644, 1664, 640, 564, 644, 564, 640, 1668, 636, 568, 640, 1664, 644, 560, 644,
                               560, 644, 564, 640, 564, 644, 560, 644, 1664, 640, 564, 644, 564, 640, 564, 640, 1668, 640, 1664, 640, 564, 644,
                               1664, 640, 564, 644, 564, 640, 1668, 640, 1664, 640, 564, 644, 564, 640, 564, 640, 564, 644, 564, 640, 1664, 644,
                               560, 644, 1664, 640, 564, 644, 564, 640, 1668, 640, 560, 644, 19980, 640, 564, 644, 1664, 640, 1668, 640, 564, 640,
                               564, 644, 1660, 644, 560, 644, 564, 644, 560, 644, 564, 640, 564, 644, 560, 644, 564, 640, 1664, 640, 564, 644, 564,
                               640, 564, 640, 564, 644, 564, 640, 564, 644, 560, 644, 564, 640, 564, 644, 564, 640, 564, 640, 564, 644, 560, 644, 564,
                               640, 564, 640, 564, 644, 1664, 640, 564, 644, 39972, 8976, 4496, 640, 1664, 644, 560, 644, 564, 640, 1668, 640, 564, 640,
                               1668, 640, 564, 640, 564, 644, 560, 644, 564, 640, 564, 644, 1664, 640, 564, 644, 564, 640, 564, 644, 1664, 640, 1668, 640,
                               564, 640, 1668, 640, 564, 640, 564, 644, 1668, 636, 1668, 640, 564, 640, 564, 640, 564, 644, 560, 644, 564, 644, 560, 644,
                               1668, 640, 1664, 640, 564, 644, 564, 640, 1668, 640, 564, 640, 19980, 640, 564, 644, 564, 640, 564, 644, 560, 644, 564, 640,
                               564, 644, 560, 644, 564, 640, 564, 640, 564, 644, 564, 640, 1668, 636, 568, 640, 1664, 640, 564, 640, 1672, 636, 1664, 640,
                               564, 644, 564, 640, 564, 640, 1668, 640, 564, 640, 564, 640, 568, 640, 1664, 640, 564, 640, 564, 644, 564, 640, 1692, 616,
                               1664, 640, 564, 640, 1664, 640, 39980, 8972, 4492, 644, 1664, 640, 568, 636, 564, 644, 1664, 640, 564, 640, 1668, 640, 564,
                               640, 564, 644, 564, 640, 564, 640, 564, 640, 1668, 640, 564, 640, 568, 640, 560, 644, 1664, 640, 1664, 644, 564, 640, 1668,
                               640, 564, 640, 564, 644, 1660, 644, 1664, 640, 564, 644, 560, 644, 564, 640, 564, 640, 564, 644, 1664, 640, 1664, 644, 1664,
                               644, 560, 644, 564, 640, 1668, 640, 560, 644, 19984, 640, 564, 644, 560, 644, 564, 640, 564, 640, 564, 640, 564, 644, 564, 640,
                               564, 644, 564, 640, 564, 640, 564, 640, 568, 640, 564, 644, 560, 644, 564, 640, 564, 644, 560, 644, 564, 640, 564, 644, 564,
                               640, 1664, 640, 1668, 640, 564, 640, 564, 640, 564, 644, 564, 640, 568, 640, 560, 644, 1668, 640, 1664, 640, 564, 640, 564, 644
                              };

const unsigned int irSignalOff[] = {8996, 4496, 640, 1688, 616, 568, 636, 568, 640, 568, 636, 568, 640, 1688, 616, 568, 640, 564, 640, 564, 640, 564, 644, 564,
                                640, 1688, 616, 1692, 616, 568, 640, 568, 636, 1668, 640, 1688, 616, 1692, 616, 568, 636, 568, 640, 564, 640, 1692, 616,
                                568, 636, 568, 636, 568, 640, 564, 640, 568, 636, 568, 640, 1688, 616, 564, 640, 1692, 616, 568, 636, 564, 640, 1672, 636,
                                564, 644, 19980, 640, 568, 636, 1692, 616, 1688, 616, 568, 636, 568, 640, 1688, 616, 572, 636, 564, 640, 568, 640, 564, 640,
                                568, 636, 568, 636, 568, 640, 1688, 616, 568, 640, 564, 640, 568, 636, 564, 640, 568, 640, 564, 640, 564, 640, 568, 640, 568,
                                636, 568, 636, 568, 640, 564, 640, 564, 640, 568, 636, 568, 640, 1688, 616, 568, 636, 1692, 616, 39980, 8972, 4496, 640, 1688,
                                616, 568, 636, 568, 640, 568, 636, 568, 636, 1692, 616, 564, 640, 568, 640, 564, 640, 564, 640, 568, 640, 1688, 616, 1692, 612,
                                568, 640, 564, 640, 1692, 612, 1692, 616, 1692, 616, 564, 640, 568, 640, 564, 640, 1692, 612, 568, 640, 568, 636, 568, 636, 568,
                                640, 564, 640, 564, 640, 568, 640, 1692, 612, 1692, 616, 568, 640, 564, 640, 1688, 616, 568, 636, 19984, 640, 564, 640, 568, 640,
                                564, 640, 568, 636, 568, 636, 568, 640, 564, 640, 568, 636, 568, 640, 564, 640, 564, 644, 1688, 616, 568, 640, 564, 640, 568, 636,
                                568, 640, 564, 640, 568, 636, 1672, 636, 1692, 612, 568, 640, 564, 640, 568, 636, 568, 640, 1692, 612, 568, 640, 568, 636, 568, 640,
                                564, 640, 1692, 616, 1668, 632, 568, 640, 39980, 8972, 4500, 640, 1688, 616, 568, 636, 568, 640, 564, 640, 568, 636, 1668, 640, 568,
                                636, 568, 640, 568, 636, 564, 640, 568, 636, 1692, 616, 1688, 616, 568, 636, 568, 640, 1668, 636, 1688, 620, 1692, 612, 568, 640, 564,
                                640, 564, 640, 1692, 612, 568, 640, 564, 644, 564, 640, 564, 640, 552, 652, 568, 640, 1688, 616, 1688, 616, 1692, 616, 564, 640, 568,
                                640, 1664, 640, 564, 640, 19988, 636, 568, 640, 564, 640, 568, 636, 568, 640, 564, 640, 568, 636, 568, 640, 564, 640, 564, 640, 568,
                                636, 568, 640, 568, 636, 568, 640, 568, 640, 564, 636, 568, 640, 568, 636, 568, 636, 568, 636, 568, 640, 1668, 636, 1692, 616, 568,
                                640, 564, 640, 564, 640, 568, 636, 568, 640, 564, 640, 1692, 616, 564, 640, 568, 636, 1692, 616
                               };

void setup() {
  pinMode(irPin, OUTPUT);
  Serial.begin(9600);
}

void loop() {

  if (Serial.available() > 0) {
    char letter = Serial.read();
    if (letter == '1') {
      irsend.sendRaw(irSignalOn, sizeof(irSignalOn) / sizeof(irSignalOn[0]), khz); //Note the approach used to automatically calculate the size of the array.
      Serial.println("ON");
    } else if (letter == '0') {
      irsend.sendRaw(irSignalOff, sizeof(irSignalOff) / sizeof(irSignalOff[0]), khz); //Note the approach used to automatically calculate the size of the array.
      Serial.println("OFF");
    }
  }
}

i got an error for arduino uno : Global variables use 2080 bytes (101%) of dynamic memory, leaving -32 bytes for local variables. Maximum is 2048 bytes.

how can i fix it?

EDIT 07/26:

I know with board like ATmega2560 problem will fix but I want use Arduino uno.

I tried to save my data at program memory but I don't know how to read that.

5
  • 1
    Search “PROGMEM”. Commented Jul 23, 2018 at 17:21
  • arduino.stackexchange.com/questions/54150/…
    – Juraj
    Commented Jul 23, 2018 at 17:24
  • what make and model of air conditioner?
    – jsotola
    Commented Jul 24, 2018 at 2:26
  • the signal data could be greatly reduced .... techdocs.altium.com/display/FPGA/…
    – jsotola
    Commented Jul 24, 2018 at 3:34
  • Re “I don't know how to read that”: 1. Search the Web for “Arduino PROGMEM”, or “AVR PROGMEM”. 2. Carefully read the resources you find, and try for yourself. 3. If you still can't after having given a genuine effort, then post here another question. Commented Jul 26, 2018 at 12:15

3 Answers 3

3

A solution is to move the tables into program memory (aka PROGMEM). Use the below:

const unsigned int irSignalOn[] PROGMEM = {
 ...
};

And modify the call to sendRaw() to sendRaw_P().

irsend.sendRaw_P(irSignalOn, sizeof(irSignalOn) / sizeof(irSignalOn[0]), khz);

For more information see the library documentation.

Cheers!

2
  • i used shirriff's IRremote library and compiler don't find sendRaw_P function ?
    – Morteza
    Commented Jul 26, 2018 at 6:14
  • @MortezaMirzai Please update your question with all relevant information. Commented Jul 26, 2018 at 10:58
1

not an answer

please try this

let me know if it turns on the A/C when you press 1

#include "IRremote.h"

IRsend irsend;
int irPin = 3; // pin IR led

int khz = 38; // 38kHz carrier frequency for the NEC protocol


void setup() {
  pinMode(irPin, OUTPUT);
  Serial.begin(9600);
}

void loop() {

  if (Serial.available() > 0) {
    char letter = Serial.read();
    if (letter == '1') {
      irsend.sendNEC(0x4A08D3052, 35);
      irsend.sendNEC(0x64040002,  32);
      irsend.sendNEC(0x4A08D3032, 35);
      irsend.sendNEC(0x0015888D,  32);
      irsend.sendNEC(0x4A08D3072, 35);
      irsend.sendNEC(0x00000C0C,  32);

      Serial.println("ON");
    }
  }
}
3
  • I test that but it don't work. (maybe my fault) and compiler give a warning.
    – Morteza
    Commented Jul 26, 2018 at 6:20
  • that's it? .... compiler give a warning .... nothing about the warning? .... do you want help or not?
    – jsotola
    Commented Jul 27, 2018 at 1:50
  • warning: large integer implicitly truncated to unsigned type [-Woverflow] irsend.sendNEC(0x4A08D3052, 35);
    – Morteza
    Commented Jul 31, 2018 at 7:58
0

One can also jump to a Atmega1284P based board, with it's 16K of SRAM, 8x that of a '328P's 2K and 2x that of the Mega's 8K. Dual hardware serial ports too if your project should need one.

2
  • or an esp8266 for cheaper and with 4X the ram and dozens of times the flash...
    – dandavis
    Commented Jul 24, 2018 at 16:32
  • But limited to 3.3V operation, and I think much less current capability on the IO, if the project needs that.
    – CrossRoads
    Commented Jul 24, 2018 at 17:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.