IR Remote , Some body can help me to review

with below program I connect the IR Emissor anode on pin 3 and Catode on GND
but every 2 seconds the IR send different codes,
some body can connect and confirm that code 0xE817C7EA is correct sended

Thank you , Im from Mexico .

#include <IRremote.h>

int IRPin = 3;
IRsend irsend;

void setup() {
pinMode(IRPin, OUTPUT);
}

void loop() {

delay(2000);
enviarCodigoIR(0xE817C7EA);
}

void enviarCodigoIR(unsigned long codigo) {
digitalWrite(IRPin, HIGH);
irsend.sendNEC(codigo, 32);
digitalWrite(IRPin, LOW);
}

Hello from Germany

Keep it simple and stupid firstly.

Follow the example code that comes with the library or
run some tutorials for the hardware selected.

If you are happy with the results of the tutorials you can merge these to your project.

Have a nice day and enjoy coding in C++.

1 Like

Do you know that the IR LED is sending? Most cell phone cameras can see the flashing of the LED while it sends.

I second that.
What version of the IRremote library do you have installed? The IRremote library has been updated recently and some random code from the internet that is written for an older version may not work with the new. In most cases only trust example code that comes with the library.

Please read the forum guidelines to see how to properly post code and some good information on making a good post.
Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in code tags.

1 Like

yes IR is working well , I have another Arduino for reading the codes ,
but as I mention send different codes every 2 seconds ,
I Just want to confirm if you have on hand one IR emissor if my program is working or not
probably you can change the code for antother one example power button of your TV .

I get frustrated due this project is not working

Hello @aeliasdiamond!

Is your IRLED a KY-005? If not, how are you connecting the IRLED to the Arduino? Would you provide a drawing? It might help solve this issue.

#include <IRremote.h>

int IRPin = 3;
IRsend irsend;

void setup() {
  pinMode(IRPin, OUTPUT);
}

void loop() {
  delay(2000);
  enviarCodigoIR(0xE817C7EA);
}

void enviarCodigoIR(unsigned long codigo) {
  digitalWrite(IRPin, HIGH);
  irsend.sendNEC(codigo, 32);
  digitalWrite(IRPin, LOW);
}

Thank you for your support , I will really apreciate your help .

Diagrama Arduino.pdf (206,8 KB)

#include <IRremote.h>

int interruptorPin = 4;
int ledPin = 7;
int transistorPin = 11;

int ledIRPin = 3;
int transistorBaseResistor = 220;

IRsend irsend;

// Definición de códigos IR
unsigned long codigo1 = 0xE817C7EA;
unsigned long codigo2 = 0x9966C7EA;
unsigned long codigo3 = 0xFC03C7EA;
unsigned long codigo4 = 0xE619C7EA;

bool programaIniciado = false;

void setup() {
  pinMode(interruptorPin, INPUT_PULLUP);
  pinMode(ledPin, OUTPUT);
  pinMode(transistorPin, OUTPUT);
  pinMode(ledIRPin, OUTPUT);

  digitalWrite(ledPin, LOW);
  digitalWrite(transistorPin, LOW);
  digitalWrite(ledIRPin, LOW);
}

void loop() {
  if (digitalRead(interruptorPin) == LOW && !programaIniciado) {
    delay(10); // Debounce
    if (digitalRead(interruptorPin) == LOW) {
      programaIniciado = true;
      digitalWrite(ledPin, HIGH);
      digitalWrite(transistorPin, HIGH);
      delay(1000);
    }
  }

  if (programaIniciado) {
    enviarCodigoIR(codigo1);
    delay(2000);
    enviarCodigoIR(codigo2);
    delay(2000);
    enviarCodigoIR(codigo3);
    delay(2000);
    enviarCodigoIR(codigo4);
    delay(2000);
    
    digitalWrite(ledPin, LOW);
    digitalWrite(transistorPin, LOW);
    delay(1000);
    
    programaIniciado = false;
  }
}

void enviarCodigoIR(unsigned long codigo) {
  digitalWrite(ledIRPin, HIGH);
  irsend.sendNEC(codigo, 32);
  digitalWrite(ledIRPin, LOW);
}

Posting (your drawing) for viewing...

I do not know how to generate the IR pulse train... maybe @docdoc has insight? This thread is similar:

[edit] I just recognized that your second sketch is not the same as the first sketch. Which sketch are you asking about?

second sketch is the correct , first one is was used for test only


I have another Arduino connected with IR Receiving but as you can see the codes are different from the sketch , I confirm that the IR received is working ok with ROKU Remote control ,

I do not understand how the receive sketch is using the hardware receiver without an "instance" created to operate the hardware, like this (example using a different IRremote.h library):

#include <IRremote.h> // IR library
#define IR_PIN 2 // IR receiver pin
IRrecv irrecv(IR_PIN); // instance of IRrecv

And to initialize/begin/enable the driver and hardware to use it, something like this...

  irrecv.enableIRIn(); // Start the IR receiver

Then, to read and interpret the data from the receiver, something like this...

  if (irrecv.decode()) { // updated library files use this, old library files want (&results)
    if (irrecv.decodedIRData.protocol == NEC) { // looking for NEC remote
.
.

Your receive sketch shows

#include <IRremote.h>

but not this

IRreceiver IrReceiver; // an example of making an instance of IRreceiver (inside IRremote.h)

Would you try adding the line to make an instance of IRreceiver

Like I said on the other thread, I have never used/studied NEC IR protocol so I don't really know how it works and why it seems to decode a different value than the sent one.

But before the code, let's talk about the schematic, as it seems to me a real mess.

First of all I don't understand why this:
image
The button goes between pin 4 and pin 7: it is defined INPUT_PULLUP, so it should go from pin 4 and GND!

Then the transistor and its IR LED.
It is an NPN transistor, so the emitter should go to GND and the collector to the load, in this case the LED cathode (and LED anode to +5V through a small resistor):
image
instead, I see here the collector here goes to GND, emitter is connectetd to the cathode, but the anode is connected to pin 3 (instead of +5V)!

I really hope it's just a wrong schematic, while the "real" project is well designed, anyway this is my "redesigned" version:
image

What is missing here is to know if the OP is using a UNO or whatever else, and exactly what is the IR LED used (a direct link to the real product is always appreciated).

Then, going back to the code, the first thing to investigate on is the IRremote library.
There are some around, with the same name, so we need to know what is the library used here. Like THIS other topic about NEC codes, it seems to me the send() and receive() should use a different approach and methods.

Once those questions will be answered, we can try to go ahead and see what's going on.

@docdoc Thank you for your support, with the help of all of you the problem is solved , I placed this issue in 2 forums finally we found the solution , the circuit that I used is the original one that I shared on this post the problem was in the Sketch but finally is solved , now I can send the correct codes and not changed even I push again the buttom ,
here is the sketch that is working properly , I already include more functions !!

I am really happy, you are a strong community and I am very proud to be a part of it.

reason why failed is for below issue ,
Solution : I include Raw after the irsend.sendNEC and change the code from 32 to 0

void enviarCodigoIR(unsigned long codigo) {
  digitalWrite(ledIRPin, HIGH);
  irsend.sendNEC(codigo,32 );
  delay(100); // Agrega un pequeño retardo para asegurar el envío completo del código IR
  digitalWrite(ledIRPin, LOW);
void enviarCodigoIR(unsigned long codigo) {
  digitalWrite(ledIRPin, HIGH);
  irsend.sendNECRaw(codigo, 0);
  delay(100); // Agrega un pequeño retardo para asegurar el envío completo del código IR
  digitalWrite(ledIRPin, LOW);
#include <IRremote.h>
#include "LowPower.h"

int interruptorPin = 4;
int ledPin = 7;
int transistorPin = 11;

int ledIRPin = 3;
int transistorBaseResistor = 1000;

IRsend irsend;

// Definición de códigos IR
unsigned long codigo1 = 0xE817C7EA; //Power
unsigned long codigo2 = 0x9966C7EA; //Back
unsigned long codigo3 = 0xFC03C7EA; //Home
unsigned long codigo4 = 0xE619C7EA; //Up
unsigned long codigo5 = 0xCC33C7EA; //Down
unsigned long codigo6 = 0xE11EC7EA; //Left
unsigned long codigo7 = 0xD22DC7EA; //Right
unsigned long codigo8 = 0xD52AC7EA; //OK
unsigned long codigo9 = 0x8778C7EA; //Return
unsigned long codigo10 = 0x9D62C7EA; //Sleep
unsigned long codigo11 = 0x9E61C7EA; // *
unsigned long codigo12 = 0xCB34C7EA; // Rew
unsigned long codigo13 = 0xAA55C7EA; // Fwr
unsigned long codigo14 = 0xB34CC7EA; // Play Pause
unsigned long codigo15 = 0xAD52C7EA; // Netflix
unsigned long codigo16 = 0xAB54C7EA; // Google Play
unsigned long codigo17 = 0x9867C7EA; // Estrella TV
unsigned long codigo18 = 0x8E71C7EA; // Claro Video
unsigned long codigo19 = 0xF00FC7EA; // Vol +
unsigned long codigo20 = 0xEF10C7EA; // Vol -
unsigned long codigo21= 0xDF20C7EA; // Mute

bool programaIniciado = false;

void setup() {
  irsend.begin(ledIRPin); // Iniciar la comunicación con el sensor IR
  pinMode(interruptorPin, INPUT_PULLUP);
  pinMode(ledPin, OUTPUT);
  pinMode(transistorPin, OUTPUT);
  pinMode(ledIRPin, OUTPUT);

  digitalWrite(ledPin, LOW);
  digitalWrite(transistorPin, LOW);
  digitalWrite(ledIRPin, LOW);
}

void loop() {
  if (digitalRead(interruptorPin) == LOW && !programaIniciado) {
    delay(10); // Debounce
    if (digitalRead(interruptorPin) == LOW) {
      programaIniciado = true;
      digitalWrite(ledPin, HIGH);
      digitalWrite(transistorPin, HIGH);
      delay(1000);
    }
  }

  if (programaIniciado) {
    enviarCodigoIR(codigo3);
    delay(50);
     enviarCodigoIR(codigo3);
    delay(50);
     enviarCodigoIR(codigo3);
    delay(50);
     enviarCodigoIR(codigo3);
    delay(50);
     enviarCodigoIR(codigo3);
    delay(50);
    enviarCodigoIR(codigo12);
    delay(100);
    enviarCodigoIR(codigo12);
    delay(100);
    enviarCodigoIR(codigo13);
    delay(100);
    enviarCodigoIR(codigo13);
    delay(100);
    enviarCodigoIR(codigo14);
    delay(100);
   
    digitalWrite(ledPin, LOW);
    digitalWrite(transistorPin, LOW);
    delay(1000);
    
    programaIniciado = false;
  }
}

void enviarCodigoIR(unsigned long codigo) {
  digitalWrite(ledIRPin, HIGH);
  irsend.sendNECRaw(codigo, 0);
  delay(100); // Agrega un pequeño retardo para asegurar el envío completo del código IR
  digitalWrite(ledIRPin, LOW);
}escribe o pega el código aquí

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