Problem with IR remote control device

hi i am Prasanta,
I have unique problem , when I am uploading IR decoder sketch in Arduino nano, the IR Remote is working fine but when I am uploading a IR remote control based sketch the same remote is not working, earlier this particular sketch is working fine in other Arduino nano and also in the same Arduino Nano, can anybody help me out with the problem. I am using Arduino 1.8.15 and the latest 2.0.0 rc3 version
I am uploading the two sketch as reference


IR decoder:
#include <IRremote.h>
int RECV_PIN = 12;
IRrecv irrecv(RECV_PIN);
decode_results results;

void setup()
{
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
}

void loop() {
if (irrecv.decode(&results)) {
Serial.println(results.value, HEX);

irrecv.resume(); // Receive the next value

}
}


IR remote control:
#include <IRremote.h>

int RECV_PIN = 12;
IRrecv irrecv(RECV_PIN);
decode_results results;

void setup() {
Serial.begin(9600);
irrecv.enableIRIn();
pinMode(8, OUTPUT); //Relay one
pinMode(9, OUTPUT); //Relay two
pinMode(10, OUTPUT); //Relay three
pinMode(11, OUTPUT); //Relay four

digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
digitalWrite(10, HIGH);
digitalWrite(11, HIGH);

}
void loop() {
if (irrecv.decode(&results)) {
irrecv.resume();
if (results.value == 0x1FE50AF ) {
digitalWrite(8, !digitalRead(8));
results.value = 0x00000000;
}
if (results.value == 0x1FED827 ) {
digitalWrite(9, !digitalRead(9));
results.value = 0x00000000;
}
if (results.value == 0x1FEF807 ) {
digitalWrite(10, !digitalRead(10));
results.value = 0x00000000;
}
if (results.value == 0x1FE30CF ) {
digitalWrite(11, !digitalRead(11));
results.value = 0x00000000;
}
irrecv.resume(); // Receive the next value
}
}

thanks and regards

void loop()
{
  if (irrecv.decode(&results))
  {
    irrecv.resume();     //  <----------<<<<<<< Why is this here ?
    if (results.value == 0x1FE50AF )
    {
      digitalWrite(8, !digitalRead(8));
      results.value = 0x00000000;
    }

Dear Larry D
But it's the same sketch which is working fine which I uploaded earlier. One more thing my other ac dimmer sketch is also not working, I can't i figure out the problem, but the same sketch is working fine.
Please help me with this problem.
Thanks and regards

Your sketch works fine here. :thinking:

Let's see your wiring.

Dear LarryD
I have connected the iR sensor HS0038 TO pin 12 of Arduino nano same as IR decoder connection, the iR decoder sketch is working ,when I press any buton of remote the Arduino nano responses, but when I uploaded the other sketch the Arduino doesn't respond.
And one more thing thing it is happening after the recent updates from windows 11.
Thanks and regards

Code works here on Windows 10

Dear Larry D
It also worked on win 11 before the last update .

Please help me out with this problem.

What version of this library do you have ?

Dear LarryD,
Latest one, as I told you it was working fine earlier, but all of sudden after windows 11 update it is not working, one more thing ,the same is working on IR decoder.
Thanks and regards

This example uses Library Version 3.3.0

I added your 4 LEDs to this example.


Check the serial monitor and write down the codes for each of your remote controller buttons.

Make whatever changes necessary.

//IR remote RX example

#include <Arduino.h>
//#include "PinDefinitionsAndMore.h"

#include <IRremote.h>          //Library Version 3.3.0          <---------<<<<<<

#define DECODE_NEC

const byte heartbeatLED      = 13;
const byte irFeedbackLED     = 12;
const byte LED1              = 11;
const byte LED2              = 10;
const byte LED3              = 9;
const byte LED4              = 8;

const byte TONE_PIN          = 4;
const byte IR_RECEIVE_PIN    = 2;

//timing stuff
unsigned long heartbeatMillis;

//*******************************************************
//17 button Keypad codes
const byte buttonCode[18]    =
{
  0x46, 0x44, 0x40,
  0x43, 0x15, 0x00,            //0X00, this is just a place holder
  0x16, 0x19, 0x0D,
  0x0C, 0x18, 0x5E,
  0x08, 0x1C, 0x5A,
  0x42, 0x52, 0x4A

}; //END of buttonCode Array

//*******************************************************
//assigned ASCII codes to the matrix buttons/switches
const byte ASCIIcode[18]     =
{
  // ^    <   New line
  0x5E, 0x3C, 0x0A,
  // >    v    nul             //nul, this is just a place holder
  0x3E, 0x76, 0x00,
  // 1    2    3
  0x31, 0x32, 0x33,
  // 4    5    6
  0x34, 0x35, 0x36,
  // 7    8    9
  0x37, 0x38, 0x39,
  // *    0    #
  0x2A, 0x30, 0x23

}; //END of ASCIIcode Array

//******************************************************************************************
void setup()
{
  Serial.begin(115200);

  pinMode(heartbeatLED, OUTPUT);

  //IR RX feedback LED
  pinMode(irFeedbackLED, OUTPUT);

  //LEDs
  pinMode(LED1, OUTPUT);
  pinMode(LED2, OUTPUT);
  pinMode(LED3, OUTPUT);
  pinMode(LED4, OUTPUT);

  //sonalert
  pinMode(TONE_PIN, OUTPUT);

  IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK, irFeedbackLED );

  Serial.print(F("Ready to receive IR signals on pin #"));
  Serial.println(IR_RECEIVE_PIN);

} //END of   setup()


//******************************************************************************************
void loop()
{
  //*******************************************************
  //is it time to toggle the heartbeat LED ?
  if (millis() - heartbeatMillis >= 500)
  {
    //restart this TIMER
    heartbeatMillis = millis();

    //toggle the LED
    digitalWrite(heartbeatLED, !digitalRead(heartbeatLED));
  }

  //*******************************************************
  //check for a RX character
  if (IrReceiver.decode())
  {
    //************************
    byte byteRX = IrReceiver.decodedIRData.command;

    //have we received a new IR code form the remote ?
    if (byteRX != 0)
    {
      //scan through the buttonCode array to see which code was received
      for (int i = 0; i < 18; i++)
      {
        if (buttonCode[i] == byteRX)
        {
          //sound a beep on the sonalert
          IrReceiver.stop();
          tone(TONE_PIN, 2200, 10);
          delay(8);
          // to compensate for 8 ms stop of receiver. This enables a correct gap measurement.
          IrReceiver.start(8000);

          //cross reference to the assigned ASCII character to this IR code
          Serial.println(char(ASCIIcode[i]));

          //We found it, no need to continue looking.
          break;
        }

      }

      //check the IR RX code against the action that needs to occur
      checkIRcode();

      //need to block repeat codes
      IrReceiver.decodedIRData.command = 0;

    }

    //enable receiving of the next value
    IrReceiver.resume();

  } //END of   if(IrReceiver.decode())

  //*******************************************************
  //other non-blocking code goes here
  //*******************************************************

} //END of   loop()


//******************************************************************************************
//required action for an IR RX code
void checkIRcode()
{
  //execute the necessary action
  switch (IrReceiver.decodedIRData.command)
  {
    //*********************  key #1
    case 0x16:
      {
        digitalWrite(LED1, !digitalRead(LED1));
      }
      break;

    //*********************  key #2
    case 0x19:
      {
        digitalWrite(LED2, !digitalRead(LED2));
      }
      break;

    //*********************  key #3
    case 0x0D:
      {
        digitalWrite(LED3, !digitalRead(LED3));
      }
      break;

    //*********************  key #4
    case 0x0C:
      {
        digitalWrite(LED4, !digitalRead(LED4));
      }
      break;

  }  //END of   switch ... case

} //END of   checkIRcode()

2022-02-25_20-44-10

Dear Larry D,
Thanks for the help, i will test it reply back to you when done.
Thanks again

Dear Larry D
Can you please tell me why the iR decoder sketch is working and not the iR remote control sketch.
Thanks

Both versions work here.

Dear Larry D
Maybe it's possible that problem with windows 11 update
I will check on other window 10 laptop
And get back to you
Thanks

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