#include <IRremote.h> //including infrared remote header file
int RECV_PIN = 7; // the pin where you connect the output pin of IR sensor
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup()
{
Serial.begin(9600);
irrecv.enableIRIn();
}
void loop()
{
if (irrecv.decode(&results))// Returns 0 if no data ready, 1 if data ready.
{
int results.value = results;// Results of decoding are stored in result.value
Serial.println(" ");
Serial.print("Code: ");
Serial.println(results.value); //prints the value a a button press
Serial.println(" ");
irrecv.resume(); // Restart the ISR state machine and Receive the next value
}
Your post was MOVED to its current location as it is more suitable.
Could you also take a few moments to Learn How To Use The Forum.
Other general help and troubleshooting advice can be found here.
It will help you get the best out of the forum in the future.
Right there?
Doesn't make sense to put a . in a variable name.
Please remember to use code tags when posting code
Read the forum guidelines to see how to properly post code.
Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in code tags.
You cannot assign a value to results.value. in the old version of the IRremote library results.value holds the data from the decode action. You would assign a variable the value of results.value.
keyCode = results.value;
What version of the IRremote library do you have installed. That code is written for an older version (<3.0) of the library and may not work right with the new version. You can either change your code to work with the new version of the library, following the instructions in the github IRremote page or you can delete the new version of the IRremote library from your sketchbook/libraries folder and install an older version (2.x.x) and keep the code the way that it is. The older versions are available for install from the IDE library manager.
Look at the examples that come with the new version to see how to use it.
Here is kind of a "Hello World" example using the new version.
#include <IRremote.h>
const byte IR_RECEIVE_PIN = 7;
unsigned long checkIrInterval = 100; // millis
unsigned long keycommand = 0;
unsigned long keyAddress = 0;
unsigned long keycode = 0;
void setup()
{
Serial.begin(115200);
Serial.println("IR receive test");
IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK);
}
void loop()
{
checkIR();
}
void checkIR()
{
static unsigned long timer = 0;
unsigned long interval = checkIrInterval;
if (millis() - timer >= interval)
{
timer = millis();
if (IrReceiver.decode())
{
keycommand = IrReceiver.decodedIRData.command;
keyAddress = IrReceiver.decodedIRData.address;
keycode = IrReceiver.decodedIRData.decodedRawData;
printIR();
// ignore repeat codes
if ((IrReceiver.decodedIRData.flags & IRDATA_FLAGS_IS_REPEAT))
{
IrReceiver.resume();
return;
}
IrReceiver.resume();
}
}
}
void printIR()
{
Serial.print("decoded command = ");
Serial.print(keycommand);
Serial.print(" decoded address = ");
Serial.print(keyAddress);
Serial.print(" decoded raw data = ");
Serial.print(keycode);
Serial.print(" raw HEX = ");
Serial.println(keycode, HEX);
Serial.println();
}
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.