Hardware: Arduino Uno R3, 3 jumper wires, breadboard, IR Receiver module, IR Remote
I'm trying to print data from the IR Remote transmitted to the IR Receiver in hexadecimal yet the program only prints a "0". Hardware is set up properly, and I've tested several IR Remotes only to lead to this same problem.
#include <IRremote.h>
const int receiver = 2;
IRrecv irrecv(receiver);
decode_results results;
void setup() {
Serial.begin(9600);
irrecv.enableIRIn();
}
void loop() {
if (irrecv.decode(&results)) { // if we received an IR signal
Serial.println(results.value, HEX); // display HEX results
irrecv.resume(); // next value
}
}
The IRremote library was recently updated. Unfortunately the new version (3.x) will not work with old code. Either fix the older code to run with the new library or install an older version of the library that will work with old code. The older versions of the IRremote library are available via the library manager.
Now there is an IRreceiver and IRsender object like the well known Arduino Serial object.
Just remove the line IRrecv IrReceiver(IR_RECEIVE_PIN); and/or IRsend IrSender; in your program, and replace all occurrences of IRrecv. or irrecv. with IrReceiver.
Since the decoded values are now in IrReceiver.decodedIRData and not in results any more, remove the line decode_results results or similar.
Like for the Serial object, call IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK); or IrReceiver.begin(IR_RECEIVE_PIN, DISABLE_LED_FEEDBACK); instead of the IrReceiver.enableIRIn(); or irrecv.enableIRIn(); in setup().
Old decode(decode_results *aResults) function is replaced by simple decode(). So if you have a statement if(irrecv.decode(&results)) replace it with if (IrReceiver.decode()).
The decoded result is now in in IrReceiver.decodedIRData and not in results any more, therefore replace any occurrences of results.value and / or results.decode_type (and similar) to IrReceiver.decodedIRData.decodedRawData and / or IrReceiver.decodedIRData.decodedRawData.
Overflow, Repeat and other flags are now in IrReceiver.receivedIRData.flags.
Seldom used: results.rawbuf and results.rawlen must be replaced by IrReceiver.decodedIRData.rawDataPtr->rawbuf and IrReceiver.decodedIRData.rawDataPtr->rawlen.
The old functions sendNEC() and sendJVC() are deprecated and renamed to sendNECMSB() and sendJVCMSB() to make it clearer that they send data with MSB first, which is not the standard for NEC and JVC. Use them to send your old 32 bit IR data codes. In the new version you will send NEC commands not by 32 bit codes but by a (constant) 8 bit address and an 8 bit command.
The examples that come with the library have been updated, too. Look at the examples to see how to use the new version.
Here is my test code using the new version.