[SOLVED] Problems receiving ir signals from a remote unit

I used to be able to connect an ir receiver unsoldered from a doner unit and decode signals from any remote unit.
I understand the commands for this have now changed.
I have opened the 'SimpleReceiver.ino sketch from the examples and managed to get it to receive a signal from my remote I used years ago by altering the defined pin to the pin 5 I have on my module I built to test remotes years ago.
It now shows 0xF609DF20 on the monitor and OxE21DDF20 on the monitor as raw-data if I press buttons 1 or 2 on my remote.
At the end of the SimpleReceiver.ino sketch it offers
'finally, check the received data and perform actions according to the received command'
If I add the following lines

 if (IrReceiver.decodedIRData.command == 0xF609DF20) {
            digitalWrite(LED_BUILTIN, HIGH);
            Serial.println(F("SEE THIS"));
            // do something
        } else if (IrReceiver.decodedIRData.command == 0xE21DDF20) {
            digitalWrite(LED_BUILTIN, LOW);
            // do something else
        }
should it not turn the led on and put 'see this' on the monitor? it does neither if I press 1 or 2 though it does show the 'raw-data' again?

It’s always best if you show us the complete sketch.

Also, a schematic helps us to visualize your setup.

2 Likes

I cannot see anything, please respond to LarryD's request.

None of these provided lines are printing the raw data.

Good evening! What arduino do you use?
You can see types of it here https://www.arduino.cc/en/hardware :+1:
AdviseYou can use Serial for finding the problem in your code Serial Comm Between Different Types of Arduino

I am using a nano, the same one I used years ago.
I built a small board consisting of the nano and an ir sensor socket. The sensor socket (a bit of an old ic socket) is just soldered onto pin 5 of the nano socket.
The sketch is the SimpleReceiver sketch from the examples.as I said in my first post but this is it in my altered state to light the led on 13 and serial print and add 'see this' to the monitor.

/*
 * SimpleReceiver.cpp
 *
 * Demonstrates receiving NEC IR codes with IRremote
 *
 *  This file is part of Arduino-IRremote https://github.com/Arduino-IRremote/Arduino-IRremote.
 *
 ************************************************************************************
 * MIT License
 *
 * Copyright (c) 2020-2023 Armin Joachimsmeyer
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is furnished
 * to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
 * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
 * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 ************************************************************************************
 */

/*
 * Specify which protocol(s) should be used for decoding.
 * If no protocol is defined, all protocols (except Bang&Olufsen) are active.
 * This must be done before the #include <IRremote.hpp>
 */
//#define DECODE_DENON        // Includes Sharp
//#define DECODE_JVC
//#define DECODE_KASEIKYO
//#define DECODE_PANASONIC    // alias for DECODE_KASEIKYO
//#define DECODE_LG
#define DECODE_NEC          // Includes Apple and Onkyo
//#define DECODE_SAMSUNG
//#define DECODE_SONY
//#define DECODE_RC5
//#define DECODE_RC6

//#define DECODE_BOSEWAVE
//#define DECODE_LEGO_PF
//#define DECODE_MAGIQUEST
//#define DECODE_WHYNTER
//#define DECODE_FAST

//#define DECODE_DISTANCE_WIDTH // Universal decoder for pulse distance width protocols
//#define DECODE_HASH         // special decoder for all protocols

//#define DECODE_BEO          // This protocol must always be enabled manually, i.e. it is NOT enabled if no protocol is defined. It prevents decoding of SONY!

//#define DEBUG               // Activate this for lots of lovely debug output from the decoders.

//#define RAW_BUFFER_LENGTH  180  // Default is 112 if DECODE_MAGIQUEST is enabled, otherwise 100.

#include <Arduino.h>

/*
 * This include defines the actual pin number for pins like IR_RECEIVE_PIN, IR_SEND_PIN for many different boards and architectures
 */
#include "PinDefinitionsAndMore.h"
#include <IRremote.hpp> // include the library

void setup() {
    pinMode(LED_BUILTIN, OUTPUT);
    Serial.begin(115200);
    // Just to know which program is running on my Arduino
    Serial.println(F("START " __FILE__ " from " __DATE__ "\r\nUsing library version " VERSION_IRREMOTE));

    // Start the receiver and if not 3. parameter specified, take LED_BUILTIN pin from the internal boards definition as default feedback LED
    IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK);

    Serial.print(F("Ready to receive IR signals of protocols: "));
    printActiveIRProtocols(&Serial);
    Serial.println(F("at pin " STR(IR_RECEIVE_PIN)));
}

void loop() {
    /*
     * Check if received data is available and if yes, try to decode it.
     * Decoded result is in the IrReceiver.decodedIRData structure.
     *
     * E.g. command is in IrReceiver.decodedIRData.command
     * address is in command is in IrReceiver.decodedIRData.address
     * and up to 32 bit raw data in IrReceiver.decodedIRData.decodedRawData
     */
    if (IrReceiver.decode()) {

        /*
         * Print a short summary of received data
         */
        IrReceiver.printIRResultShort(&Serial);
        IrReceiver.printIRSendUsage(&Serial);
        if (IrReceiver.decodedIRData.protocol == UNKNOWN) {
            Serial.println(F("Received noise or an unknown (or not yet enabled) protocol"));
            // We have an unknown protocol here, print more info
            IrReceiver.printIRResultRawFormatted(&Serial, true);
        }
        Serial.println();

        /*
         * !!!Important!!! Enable receiving of the next value,
         * since receiving has stopped after the end of the current received data packet.
         */
        IrReceiver.resume(); // Enable receiving of the next value

        /*
         * Finally, check the received data and perform actions according to the received command
         */
        if (IrReceiver.decodedIRData.command == 0xF609DF20) {
            digitalWrite(LED_BUILTIN, HIGH);
            Serial.println(F("SEE THIS"));
            // do something
        } else if (IrReceiver.decodedIRData.command == 0xE21DDF20) {
            digitalWrite(LED_BUILTIN, LOW);
            // do something else
        }
    }
}

It also has a file PinDefinitionsAndMore.h on another tab in the IDE that I have altered the IR_RECEIVER_PIN to 5 to work with my board.

1 Like

Try this test sketch to see what gets printed ?

//Install IRremote Version 3.3.0
#include <IRremote.h>   // Ver 3.3.0 <-------<<<<<<<

#define DECODE_NEC

const byte IR_RECEIVE_PIN = 2;               //<-------<<<<<  your receive pin


//******************************************************************************************
void setup()
{
  pinMode(LED_BUILTIN, OUTPUT);
  Serial.begin(115200);                      //<-------<<<<<  your baud rate

  IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK);

} //END of   setup()


//******************************************************************************************
void loop()
{
  //*********************************
  if (IrReceiver.decode())
  {
    if (IrReceiver.decodedIRData.protocol == UNKNOWN)
    {
      Serial.println(F("Received noise or an unknown (or not yet enabled) protocol"));
      // We have an unknown protocol here, print more info
      IrReceiver.printIRResultRawFormatted(&Serial, true);
    }

    if (IrReceiver.decodedIRData.command != 0)
    {
      Serial.print("Code: ");
      Serial.println(IrReceiver.decodedIRData.command);

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

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

} //END of   loop()


//******************************************************************************************

1 Like

Thanks Larry,
I have ir remote version 4.1.2 do you want me to remove that and install version 3.3.0?
I altered the receive pin to 5 and now I get a 2 figure output every time I press a key. I say 2 figure in fact if I press button 1 I get '9' and if I press button 2 I get '29'
I added


    if (IrReceiver.decodedIRData.command == 9)
    {
      digitalWrite(LED_BUILTIN, HIGH);
    }
    else if (IrReceiver.decodedIRData.command == 29)
    {
      digitalWrite(LED_BUILTIN, LOW);
    }

but still don't get the led_builtin to light?

Does that one without any changes, run without problems?

In other words, has

a small board consisting of the nano and an ir sensor socket

been tested with known good, example sketches?

1 Like

No, your version is the latest.

Instead of LED_BUILTIN (pin 13) use pin 12 (make sure it is set to OUTPUT)

if (IrReceiver.decodedIRData.command == 9)
{
  digitalWrite(12, HIGH);
}
else if (IrReceiver.decodedIRData.command == 29)
{
  digitalWrite(12, LOW);
}
1 Like

If I just alter the input pin to 5 which is mine and run it I get 3 lines of info

Protocol=NEC Address=0x20 Command=0x9 Raw-Data=0xF609DF20 32 bits LSB first
Send with: IrSender.sendNEC(0x20, 0x9, );

Protocol=NEC Address=0x20 Command=0x9 Repeat gap=39400us

Protocol=NEC Address=0x20 Command=0x1D Raw-Data=0xE21DDF20 32 bits LSB first
Send with: IrSender.sendNEC(0x20, 0x1D, );

Protocol=NEC Address=0x20 Command=0x1D Repeat gap=39400us

I have produced both button 1 and 2 above. if you look at the middle of the middle line in both you will see 0x9 and 0x1D (29) so it looks as if it is working? Same as I got before.

The test sketch given uses pin 13 as a IR feedback LED.

Try what was mentioned in post #10.

1 Like

I assume I will need to externally add a led to that pin?

Yes

//      Resistor        LED
Pin 12---[220R]---[Anode-Cathode]--- GND
1 Like

What is your alternative theory?

Jus checking
I have added a led and 1k resistor.
set it as an output and put


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


    if (IrReceiver.decodedIRData.command == 9)
    {
      digitalWrite(12, HIGH);
       Serial.print("HERE");
    }
    else if (IrReceiver.decodedIRData.command == 29)
    {
      digitalWrite(12, LOW);
    }
        IrReceiver.resume(); // Enable receiving of the next value
  }

} //END of   loop()

in the end of your sketch (I have shown the lines above and below so you can see where).
I don't get the led lighting or the message on the monitor?

Please show us your complete modified sketch.

1 Like

I altered the == in the line to = the led now lights but neither 29 or 1D turns it off again.

//Install IRremote Version 3.3.0
#include <IRremote.h>   // Ver 3.3.0 <-------<<<<<<<

#define DECODE_NEC

const byte IR_RECEIVE_PIN = 5;               //<-------<<<<<  your receive pin


//******************************************************************************************
void setup()
{
  pinMode(LED_BUILTIN, OUTPUT);
  pinMode(12, OUTPUT);
  Serial.begin(115200);                      //<-------<<<<<  your baud rate

  IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK);

} //END of   setup()


//******************************************************************************************
void loop()
{
  //*********************************
  if (IrReceiver.decode())
  {
    if (IrReceiver.decodedIRData.protocol == UNKNOWN)
    {
      Serial.println(F("Received noise or an unknown (or not yet enabled) protocol"));
      // We have an unknown protocol here, print more info
      IrReceiver.printIRResultRawFormatted(&Serial, true);
    }

    if (IrReceiver.decodedIRData.command != 0)
    {
      Serial.print("Code: ");
      Serial.println(IrReceiver.decodedIRData.command);

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


    if (IrReceiver.decodedIRData.command = 9)
    {
      digitalWrite(12, HIGH);
       Serial.println("HERE");
    }
    else if (IrReceiver.decodedIRData.command = 1D)
    {
      digitalWrite(12, LOW);
    }
        IrReceiver.resume(); // Enable receiving of the next value
  }

} //END of   loop()


//******************************************************************************************

and the word HERE shows up on the monitor

I need to prefix 1D with 0x but it still fails to trigger

Please re-post your sketch when you make changes.

1 Like