Problem with IRRemote sender

I have the following code:

#include <IRremote.h>      // importa libreria IRremote
#define Boton_1 0xFA057F80
#define Boton_2 0xF8077F80
#define Boton_3 0xF7087F80
#define Boton_4 0xF6097F80
#define Boton_5 0xE41B7F80

int SENSOR = A7;      // sensor KY-022 a pin digital 11

void setup() {
  IrSender.begin(SENSOR, DISABLE_LED_FEEDBACK);
  IrSender.enableIROut(38);
} 

void loop() {
  IrSender.sendNEC(Boton_1, 32);
  delay (2000);
  IrSender.sendNEC(Boton_2, 32);
  delay (2000);
  IrSender.sendNEC(Boton_3, 32);
  delay (2000);
  IrSender.sendNEC(Boton_4, 32);
  delay (2000);
  IrSender.sendNEC(Boton_5, 32);
  delay (2000);
}

the problem is that I can't get the arduino to send any data through the IR led, if I look at it with a mobile, no activity is seen (if I connect it to VCC, the led is visible)

Show us a schematic of your circuit.

Show us a good image of the wiring.

What Arduino? The A6 and A7 pins on the classic Nano can’t be used as digital outputs. They are only two more inputs to the multiplexer that feeds the ADC.

code of Arduino nano:

#include <IRremote.h>      // importa libreria IRremote
#define Boton_1 0xFA057F80
#define Boton_2 0xF8077F80
#define Boton_3 0xF7087F80
#define Boton_4 0xF6097F80
#define Boton_5 0xE41B7F80

int SENSOR = A3;      // sensor KY-022 a pin digital 11

void setup() {
  IrSender.begin(SENSOR, DISABLE_LED_FEEDBACK);
  IrSender.enableIROut(38);
} 

void loop() {
  IrSender.sendNEC(Boton_1, 32);
  delay (2000);
  IrSender.sendNEC(Boton_2, 32);
  delay (2000);
  IrSender.sendNEC(Boton_3, 32);
  delay (2000);
  IrSender.sendNEC(Boton_4, 32);
  delay (2000);
  IrSender.sendNEC(Boton_5, 32);
  delay (2000);
}

code of arduino leonardo:

#include <IRremote.h>    // importa libreria IRremote

void setup() { 
  Serial.begin(9600);             // inicializa comunicacion serie a 9600 bps
  IrReceiver.begin(13, DISABLE_LED_FEEDBACK);     // inicializa recepcion de datos
  IrSender.enableIROut(38);
} 

void loop() {
  if (IrReceiver.decode()) {          // si existen datos ya decodificados
    Serial.print(getProtocolString(IrReceiver.decodedIRData.protocol));
    Serial.print(" : ");
    Serial.print(IrReceiver.decodedIRData.numberOfBits);
    Serial.print(" : ");
    Serial.println(IrReceiver.decodedIRData.decodedRawData, HEX);  // imprime valor en hexadecimal en monitor
    IrReceiver.resume(); // resume la adquisicion de datos
  }
  delay (100);                  // breve demora de 100 ms.
}

terminal output:

//original remote
NEC : 32 : FA057F80
NEC : 32 : F8077F80
NEC : 32 : F7087F80
NEC : 32 : F6097F80
NEC : 32 : E41B7F80
//recived signal
NEC : 32 : 1FEA05F
NEC : 32 : 1FEE01F
NEC : 32 : 1FE10EF

problem:
the signal received by the arduino is not the same as by the original command

Try IrSender.sendNECRaw(Boton_1, 2); // 2 repeats

You know the difference between LSB and MSB?
Draw both values as bit streams and have a deeper look at them and you will understand :-).

this is the new code:

NEC : 32 : E41B7F80
NEC : 0 : 0
NEC : 0 : 0
NEC : 32 : FA057F80
NEC : 0 : 0
NEC : 32 : F8077F80
NEC : 0 : 0
NEC : 32 : F7087F80
NEC : 0 : 0
NEC : 0 : 0
NEC : 32 : F6097F80
NEC : 0 : 0
NEC : 32 : E41B7F80
NEC : 0 : 0
NEC : 32 : FA057F80
NEC : 0 : 0
NEC : 0 : 0
NEC : 32 : F8077F80
NEC : 0 : 0
NEC : 32 : F7087F80
NEC : 0 : 0
NEC : 32 : F6097F80
NEC : 0 : 0
NEC : 0 : 0
NEC : 32 : E41B7F80
NEC : 0 : 0
NEC : 32 : FA057F80
NEC : 0 : 0
NEC : 32 : F8077F80
NEC : 0 : 0
NEC : 0 : 0
NEC : 32 : F7087F80
NEC : 0 : 0

and this is the response by the terminal

#include <IRremote.h>      // importa libreria IRremote
#define Boton_1 0xFA057F80
#define Boton_2 0xF8077F80
#define Boton_3 0xF7087F80
#define Boton_4 0xF6097F80
#define Boton_5 0xE41B7F80

int SENSOR = A3;      // sensor KY-022 a pin digital 11

void setup() {
  IrSender.begin(SENSOR, DISABLE_LED_FEEDBACK);
  IrSender.enableIROut(38);
} 

void loop() {
  IrSender.sendNECRaw(Boton_1, 2);
  delay (2000);
  IrSender.sendNECRaw(Boton_2, 2);
  delay (2000);
  IrSender.sendNECRaw(Boton_3, 2);
  delay (2000);
  IrSender.sendNECRaw(Boton_4, 2);
  delay (2000);
  IrSender.sendNECRaw(Boton_5, 2);
  delay (2000);
}

as you can see, some of the messages are received correctly, but others only receive the protocol

I don't know now what exactly the reason is. Try other repeat parameters than 2 when calling IrSender.sendNECRaw. Maybe 0. Otherwise change the IF condition in the code for the reception.

E.g. like this:

if (IrReceiver.decode() && IrReceiver.decodedIRData.numberOfBits > 0) {          // si existen datos ya decodificados
    Serial.print(getProtocolString(IrReceiver.decodedIRData.protocol));
    Serial.print(" : ");
    Serial.print(IrReceiver.decodedIRData.numberOfBits);
    Serial.print(" : ");
    Serial.println(IrReceiver.decodedIRData.decodedRawData, HEX);  // imprime valor en hexadecimal en monitor
    IrReceiver.resume(); // resume la adquisicion de datos
  }
  delay (100);                  // breve demora de 100 ms.

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