Pages: [1]   Go Down
Author Topic: Trying to get LED to light based on button pushed on IR Remote.  (Read 893 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 46
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I will start off with what I am trying to do.. I thought it would be simple, but I was soooo wrong. I have an IR remote I'm not using, and I want to use it for my Arduino to turn LEDs on and off. I have used scripts to grab the inputs of HEX and raw code for each button. When I try to turn around and use that code to execute commands, it does not work. Serial shows its seeing the input, but it wont do anything.

IR collector: 276-640 Infrared collector
IR REmote: Sony RMT-B101A

The hardware is all set up and works great, but the code is what I'm missing.

When I push the vol+ button on the remote, it sends back 90 though serial, when I push vol-, it sends back 890. When I try to put that into the logic of the code to turn on an LED, it never works. I erased everything and was wondering if anyone had any thoughts on this.

I already tried the following links:

http://learn.adafruit.com/ir-sensor

http://arduino.cc/playground/Main/InterfacingWithHardware

http://www.instructables.com/id/Arduino-IR-sensor-and-LEDs/


I appreciate ANY advice you have or any code I should try. My goal is to simply flash a few pins depending on the button i press. I was wondering if anyone knew about some simple code I can use to decode my remote and use it.  Keep in mind, I am quite new to this, and the code I am using, I did not write.

Thanks in advance!


This is the code i am using to decode the remote. There are what looks to be HEX values in the cases at the bottom, but i cant get it to react based on the button I push.

Code:
/*
 * IRhashdecode - decode an arbitrary IR code.
 * Instead of decoding using a standard encoding scheme
 * (e.g. Sony, NEC, RC5), the code is hashed to a 32-bit value.
 *
 * An IR detector/demodulator must be connected to the input RECV_PIN.
 * This uses the IRremote library: http://arcfn.com/2009/08/multi-protocol-infrared-remote-library.html
 *
 * The algorithm: look at the sequence of MARK signals, and see if each one
 * is shorter (0), the same length (1), or longer (2) than the previous.
 * Do the same with the SPACE signals.  Hszh the resulting sequence of 0's,
 * 1's, and 2's to a 32-bit value.  This will give a unique value for each
 * different code (probably), for most code systems.
 *
 * You're better off using real decoding than this technique, but this is
 * useful if you don't have a decoding algorithm.
 *
 * Copyright 2010 Ken Shirriff
 * http://arcfn.com
 */

#include <IRremote.h>

int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;

void setup()
{
  irrecv.enableIRIn(); // Start the receiver
  Serial.begin(9600);
}

// Compare two tick values, returning 0 if newval is shorter,
// 1 if newval is equal, and 2 if newval is longer
// Use a tolerance of 20%
int compare(unsigned int oldval, unsigned int newval) {
  if (newval < oldval * .8) {
    return 0;
  }
  else if (oldval < newval * .8) {
    return 2;
  }
  else {
    return 1;
  }
}

// Use FNV hash algorithm: http://isthe.com/chongo/tech/comp/fnv/#FNV-param
#define FNV_PRIME_32 16777619
#define FNV_BASIS_32 2166136261

/* Converts the raw code values into a 32-bit hash code.
 * Hopefully this code is unique for each button.
 */
unsigned long decodeHash(decode_results *results) {
  unsigned long hash = FNV_BASIS_32;
  for (int i = 1; i+2 < results->rawlen; i++) {
    int value =  compare(results->rawbuf[i], results->rawbuf[i+2]);
    // Add value into the hash
    hash = (hash * FNV_PRIME_32) ^ value;
  }
  return hash;
}

void loop() {
  if (irrecv.decode(&results)) {
    Serial.print("'real' decode: ");
    Serial.print(results.value, HEX);
    Serial.print(", hash decode: ");
    Serial.println(decodeHash(&results), HEX); // Do something interesting with this value
    irrecv.resume(); // Resume decoding (necessary!)
  }
}

#define LEDPIN 13
void blink() {
  digitalWrite(LEDPIN, HIGH);
  delay(200);
  digitalWrite(LEDPIN, LOW);
  delay(200);
}  

// Blink the LED the number of times indicated by the Philips remote control
// Replace loop() with this for the blinking LED example.
void blink_example_loop() {
  if (irrecv.decode(&results)) {
    unsigned long hash = decodeHash(&results);
    switch (hash) {
    case 0x322ddc47: // 0 (10)
      blink(); // fallthrough
    case 0xdb78c103: // 9
      blink();
    case 0xab57dd3b: // 8
      blink();
    case 0x715cc13f: // 7
      blink();
    case 0xdc685a5f: // 6
      blink();
    case 0x85b33f1b: // 5
      blink();
    case 0x4ff51b3f: // 4
      blink();
    case 0x15f9ff43: // 3
      blink();
    case 0x2e81ea9b: // 2
      blink();
    case 0x260a8662: // 1
      blink();
      break;
    default:
      Serial.print("Unknown ");
      Serial.println(hash, HEX);    
    }
    irrecv.resume(); // Resume decoding (necessary!)
  }
}

Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 180
Posts: 8108
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

For most IR Remote you can use Ken Shirriff's IR Remote library:

http://www.arcfn.com/2009/08/multi-protocol-infrared-remote-library.html

If the remote you are using does not speak one of the four common protocols (NEC, Sony SIRC, Philips RC5, Philips RC60 you can use this trick to associate the raw IR inputs with actions:

http://www.arcfn.com/2010/01/using-arbitrary-remotes-with-arduino.html
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

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

I forgot to mention that site, but I did try Ken Shirriff's blog. Apparently, my remote does register as a Sony remote, but the results come out looking like this for button presses:

90
90
90
890
890
890


but the code calls for results like this:

    case 0x4ff51b3f: // 4
      blink();
    case 0x15f9ff43: // 3
      blink();
    case 0x2e81ea9b: // 2
      blink();
    case 0x260a8662: // 1


So how do it turn my results like 90 and 890 into something that looks like 0x??????

I tried just replacing the 0x code for my simple numbers, but it didnt work.
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 180
Posts: 8108
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Use File->Examples->IRremote->IRrecvDump to get the button codes and show your results here.
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

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

I did the following buttons:

Ch+
Ch-
1
2
3
4
5
6
7
8
9
0

here are the results:
Code:
90
Decoded SONY: 90 (12 bits)
Raw (26): -2178 2400 -550 650 -550 650 -500 650 -550 650 -550 1250 -500 650 -550 650 -550 1250 -500 650 -550 650 -550 600 -550 650
890
Decoded SONY: 890 (12 bits)
Raw (26): 6818 2450 -550 1250 -500 650 -550 650 -500 650 -550 1250 -550 650 -500 650 -550 1250 -550 600 -550 650 -550 650 -550 650
B47
Decoded SONY: B47 (20 bits)
Raw (42): 28748 2450 -500 650 -550 650 -550 650 -500 650 -550 650 -550 650 -500 650 -550 650 -550 1250 -500 650 -550 1250 -550 1200 -550 650 -550 1250 -500 650 -550 650 -550 650 -500 1250 -550 1250 -500 1250
80B47
Decoded SONY: 80B47 (20 bits)
Raw (42): -23076 2400 -550 1250 -550 650 -500 650 -550 650 -550 650 -500 650 -550 650 -550 650 -550 1200 -550 650 -550 1250 -500 1250 -550 650 -500 1250 -550 650 -550 650 -500 650 -550 1250 -550 1200 -550 1250
40B47
Decoded SONY: 40B47 (20 bits)
Raw (42): 16948 2450 -500 650 -550 1250 -550 650 -500 650 -550 650 -550 650 -550 600 -550 650 -550 1250 -500 650 -550 1250 -550 1200 -550 650 -550 1250 -500 650 -550 650 -550 650 -500 1250 -550 1250 -500 1250
C0B47
Decoded SONY: C0B47 (20 bits)
Raw (42): -7034 2400 -550 1250 -550 1250 -500 650 -550 650 -550 650 -500 650 -550 650 -550 650 -500 1250 -550 650 -550 1250 -500 1250 -550 650 -500 1250 -550 650 -500 650 -550 650 -550 1250 -500 1250 -550 1250
20B47
Decoded SONY: 20B47 (20 bits)
Raw (42): -534 2450 -550 650 -500 650 -550 1250 -550 600 -550 650 -550 650 -550 650 -500 650 -550 1250 -500 650 -550 1250 -550 1250 -500 650 -550 1250 -500 650 -550 650 -550 650 -500 1250 -550 1250 -500 1250
A0B47
Decoded SONY: A0B47 (20 bits)
Raw (42): -29784 2400 -550 1250 -550 600 -550 1250 -550 650 -500 650 -550 650 -550 650 -500 650 -550 1250 -550 650 -500 1250 -550 1250 -500 650 -550 1250 -550 600 -550 650 -550 650 -550 1250 -500 1250 -550 1250
60B47
Decoded SONY: 60B47 (20 bits)
Raw (42): -3412 2400 -550 650 -550 1250 -500 1250 -550 650 -500 650 -550 650 -550 650 -500 650 -550 1250 -550 600 -550 1250 -550 1250 -500 650 -550 1250 -550 600 -550 650 -550 650 -550 1200 -550 1250 -550 1250
E0B47
Decoded SONY: E0B47 (20 bits)
Raw (42): -14120 2400 -550 1250 -550 1250 -500 1250 -550 650 -500 650 -550 650 -550 650 -500 650 -550 1250 -550 650 -500 1250 -550 1250 -500 650 -550 1250 -550 600 -550 650 -550 650 -550 1250 -500 1250 -550 1250
10B47
Decoded SONY: 10B47 (20 bits)
Raw (42): 6916 2400 -550 650 -550 650 -550 650 -500 1250 -550 650 -550 600 -550 650 -550 650 -550 1250 -500 650 -550 1250 -500 1250 -550 650 -550 1200 -550 650 -550 650 -500 650 -550 1250 -550 1250 -500 1250
90B47
Decoded SONY: 90B47 (20 bits)
Raw (42): -28234 2400 -550 1250 -550 650 -500 650 -550 1250 -550 600 -550 650 -550 650 -550 650 -500 1250 -550 650 -500 1250 -550 1250 -550 600 -550 1250 -550 650 -500 650 -550 650 -550 1250 -500 1250 -550 1250

Thanks in advance!!
Logged

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

found this, i dont know if it helps:

http://lirc.sourceforge.net/remotes/sony/RMT-B101A

Logged

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

SOLVED IT smiley-grin


Simply put 0x before any code I get and it works!!

Code:
#include <IRremote.h>

int RECV_PIN = 11;
int OUTPUT_PIN = 8;

IRrecv irrecv(RECV_PIN);
decode_results results;

void setup()
{
  pinMode(OUTPUT_PIN, OUTPUT);
  pinMode(13, OUTPUT);
  irrecv.enableIRIn(); // Start the receiver
}

void loop() {
  if (irrecv.decode(&results)) {
    if (results.value == 0x90) { // Sony DVD play
      digitalWrite(OUTPUT_PIN, HIGH);
    }
    else if (results.value == 0x890) { // Sony DVD stop
      digitalWrite(OUTPUT_PIN, LOW);
    }   
    irrecv.resume(); // Receive the next value
  }
}

so 90 becomes 0x90

how awesome is that!!

now to finish my project!!!!!!!!!!!!!!
Logged

Pages: [1]   Go Up
Jump to: