How to use RAW data from IR detector

I have used code from Ken Shirriff to read the raw dump from an IR remote.

He also have a simple sketch to toggle a relay, but the relay toggles no matter what button I press on the remote. How can I use the raw dump received from a specific button only to toggle the relay, or make other things happen? Basically I want to read data from a remote, and that data must be able to control a gadget. I do get HEX dumps from the different remote buttons. I could'nt really care if it decodes the correct remote, all I want is if say I receive FFE21D, then toggle the relay.
Below is a typical output from the relay toggling code.

Decoded NEC: FF42BD (32 bits)
Raw (68): 25830 9050 -4450 600 -550 550 -600 550 -550 600 -500 600 -550 600 -550 550 -550 550 -550 600 -1700 500 -1700 600 -1700 550 -1650 550 -1750 550 -1700 550 -1600 600 -1750 550 -550 550 -1700 550 -600 500 -550 600 -550 600 -550 500 -1750 550 -550 550 -1650 600 -550 550 -1750 550 -1700 550 -1650 550 -1700 600 -550 500 -1700 600

Perhaps instead of printing out the decoded and raw data you could change the program to compare the decoded data to the data you got for the button you want to act on. Then if the data matches, toggle the relay. Perhaps if you posted your sketch we could make more specific suggestions.

Here is the sketch. I have very little knowledge of what is actually happening behind the scenes, this code is straight from Ken Shirrif. All I know is the last couple of lines is what toggles the relay.
What does this mean "result->value?" I'm not familiar with the symbol between the words.

/*

  • IRremote: IRrecvDemo - demonstrates receiving IR codes with IRrecv
  • An IR detector/demodulator must be connected to the input RECV_PIN.
  • Version 0.1 July, 2009
  • Copyright 2009 Ken Shirriff
  • http://arcfn.com
    */

#include <IRremote.h>

int RECV_PIN = 11;
int RELAY_PIN = 4;

IRrecv irrecv(RECV_PIN);
decode_results results;

// Dumps out the decode_results structure.
// Call this after IRrecv::decode()
// void * to work around compiler issue
//void dump(void *v) {
// decode_results *results = (decode_results *)v
void dump(decode_results *results) {
int count = results->rawlen;
if (results->decode_type == UNKNOWN) {
Serial.println("Could not decode message");
}
else {
if (results->decode_type == NEC) {
Serial.print("Decoded NEC: ");
}
else if (results->decode_type == SONY) {
Serial.print("Decoded SONY: ");
}
else if (results->decode_type == RC5) {
Serial.print("Decoded RC5: ");
}
else if (results->decode_type == RC6) {
Serial.print("Decoded RC6: ");
}
Serial.print(results->value, HEX);
Serial.print(" (");
Serial.print(results->bits, DEC);
Serial.println(" bits)");
}
Serial.print("Raw (");
Serial.print(count, DEC);
Serial.print("): ");

for (int i = 0; i < count; i++) {
if ((i % 2) == 1) {
Serial.print(results->rawbuf_*USECPERTICK, DEC);_

  • } *
  • else {*
    Serial.print(-(int)results->rawbuf_USECPERTICK, DEC);_
    _
    }_
    _ Serial.print(" ");_
    _
    }_
    _ Serial.println("");_
    _
    }_
    void setup()
    _
    {_
    pinMode(RELAY_PIN, OUTPUT);
    _
    pinMode(13, OUTPUT);_
    _ Serial.begin(9600);_
    _
    irrecv.enableIRIn(); // Start the receiver*_
    }
    int on = 0;
    unsigned long last = millis();
    void loop() {
    * if (irrecv.decode(&results)) {*
    * // If it's been at least 1/4 second since the last*
    * // IR received, toggle the relay*
    * if (millis() - last > 250) {*
    * on = !on;*
    * digitalWrite(RELAY_PIN, on ? HIGH : LOW);
    _
    digitalWrite(13, on ? HIGH : LOW);_
    _
    dump(&results);_
    _
    }_
    _
    last = millis(); _
    _
    irrecv.resume(); // Receive the next value*_
    * }*
    }
    [/quote]

results->value mean "The 'value' element of the data structure whose address is stored in the pointer named 'results'.

This part:

void dump(decode_results *results)

means that the value being passed to the function is a pointer to a variable of type 'dumpcode_results' and will be known within the function as 'results'.

A structure is just a way to group several variables together. The elements of a structure can be any type and name. Look in IRremote.h to see the declaration for the 'dumpcode_results' type, the elements it contains, and the names and types of those elements.

If you are looking for the NEC-encoded button with the code FFE21D you can say this:

if (results->decode_type == NEC && results->value == 0xFFE21DUL)

In the example code I was given the data structures were all referred to using dots, i.e.
if(results.value == 0x123abc99)
Etc
Trouble is we couldn't get the comparison to work. The relay clicked for any press of the remote.
No complaints from the compiler so we assumed we are referencing the data correctly.
I'm confused by the pointer use above.

@SimonSolar2C
are you working with the OP?

.

Code is doing exactly what you told it to do.

If any results are received, toggle relay.

void loop() {
  if (irrecv.decode(&results)) {

!!!!!!!!!!!

    // IR received, toggle the relay
    if (millis() - last > 250) {
      on = !on;
      digitalWrite(RELAY_PIN, on ? HIGH : LOW);
      digitalWrite(13, on ? HIGH : LOW);
      dump(&results);
    }
    last = millis();     
    irrecv.resume(); // Receive the next value
  }

Where !!!!!!!! is, you need another if statement like

if (results.value == 0xFFE21DUL ){

I use switch-case for my IR receiver since there's a bunch of inputs to recognize.

    switch (results.value) {
      case 0x00FF906F:
        digitalWrite(ledPin, ledState);
        break;