Pages: [1]   Go Down
Author Topic: How to use Infra red numbers  (Read 452 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi, newbie here but i love this Arduino,heres my problem i have a IR receiver and can get an out put on serial (ie  press 1 i get 687CBE2 or press 2 i get 687CBEA) i use the IRremote.h to get this using this example sketch


Code:
// example 32.1 - IR receiver code repeater

// http://tronixstuff.com/tutorials > chapter 32

// based on code by Ken Shirriff - http://arcfn.com

#include <IRremote.h> // use the library

int receiver = 11; // pin 1 of IR receiver to Arduino digital pin 11

IRrecv irrecv(receiver); // create instance of 'irrecv'

decode_results results;

void setup()

{

  Serial.begin(9600); // for serial monitor output

  irrecv.enableIRIn(); // Start the receiver

}

void loop()

{

  if (irrecv.decode(&results)) // have we received an IR signal?

  {

    Serial.println(results.value, HEX); // display it on serial monitor in hexadecimal

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

  }  // Your loop can do other things while waiting for an IR command

}

Now i am a bit lost on how to use these numbers (from serial) to do anything like turn a LED on say pin 13 and then off.I understand Ledpin HIGH LOW etc but not how to use the HEX (i think) numbers from the remote?
Logged

0
Online Online
Shannon Member
****
Karma: 222
Posts: 12724
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The Serial.print is printing the number in its hex representation - but you could print it in decimal if you wanted.

To use the value you just need to compare it with the relevant value - if working in HEX use hexadecimal long integer constants:

Code:
  switch (results.value)
  {
  case 0x687CBE2L:
    // do something for '1'
    break ;
  case 0x687CBEAL:
    // do something for '2'
    break ;
    // etc etc
  }
Logged

[ I won't respond to messages, use the forum please ]

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I solved this problem and will show anyone interested the sketch in case it helps you .first what i did is wire up a IR receiver i reclaimed from an old DVD player the 3 pins left to right were Data, Ground and VCC +5V (looking at the IR receiver from the front where the half bubble is) ,Data went to digital pin 11,Ground to GRD and VCC to 5V, i then tested this with an example sketch from the IRremote. library (which you need) this sketch just read a HEX number from the remote when i pressed a button on the remote and sent it to a serial console,In my case pressing "1" on the remote would give me a code of 687CBE2 which i noted down on paper ,getting this code i knew this was working what i didnt know was what to do with code,here is the sketch which should explain how it works (pressing 1 on remote control would turn LED on pressing 2 on remote would turn LED off.


Code:
// example 32.1 - IR receiver code repeater

// http://tronixstuff.com/tutorials > chapter 32

// based on code by Ken Shirriff - http://arcfn.com

#include <IRremote.h> // use the library

int receiver = 11; // pin 1 of IR receiver to Arduino digital pin 11
int ledPin = 13;  // Pin 13 as LED

IRrecv irrecv(receiver); // create instance of 'irrecv'

decode_results results;

void setup()

{

  Serial.begin(9600); // for serial monitor output

  irrecv.enableIRIn(); // Start the receiver

  pinMode(ledPin, OUTPUT);  //Pin 13 as output for LED
}

void loop()

{

  if (irrecv.decode(&results)) // have we received an IR signal?

  {
{
      if (results.value == 0x687CBE2L) {   // 0x687CBE2L button press 1 on remote control
      Serial.write("ON\n"); 
      digitalWrite(ledPin, HIGH);  // turn on LED
      }
           
    else if (results.value == 0x687CBEAL) { // 0x687CBE2L button press 2 on remote control
      Serial.write("off\n");
       digitalWrite(ledPin, LOW); // turn LED off
   
     


   
      }
}
    Serial.println(results.value, HEX); // display it on serial monitor in hexadecimal

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

  }  // Your loop can do other things while waiting for an IR command

}





I can now  control LED,servo's and motors etc from the Arduino with a free reclaimed remote control how cool is that ,Hope this helps anyone else .
Logged

Pages: [1]   Go Up
Jump to: