Infrared Reciever problem.

Hello, i got an Arduino 2 days ago and i wanted to make something.
This is what i came up with: An infrared reciever on my little breadboard hooked up to my Arduino and when i press a button on my tv remote --> turn on the light.

here is my code:

#define LED 13

int val = 0;

void setup(){
  pinMode(LED, OUTPUT);
  Serial.begin(9600);
}

void loop(){
  val = analogRead(0);
  Serial.println(val);
  delay(100);
  }

I use the serial port to see what values the IR reciever gets.
its like this:

602
601
602
603
601
1023
602
600
602
601
1023
1023
602
603
600
602
601
1023
1023
603
603
603
601
603
1023
602
603
603
601
601
603
603
601
601
601
600
1023
1023
600
603
603
601
602
602
602
602
600
1023
1023
603
601
602
603
602
601
603
1023
603
601
601
603
603
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
603
601
600
602
601
603
603
1023

the big 1023 part is when is press the power button from my remote.
the problem is the other 1023 values that apear random.
if anyone knows how to fix this please let me know.
this might be a 'noob' question but i just got my arduino and im still learning.

Thanks in advance.
Max

PS: ill post pictures soon.

here are the pictures: ir_thing_2 | max tangelder | Flickr
ir_thing_1 | max tangelder | Flickr

It looks like that the value on the pin is floating when it's not picking up the IR signal from the remote.

Try tying the pin to ground with a resistor, and that should work better.

Programmer, the ground pin is tied to a resistor (10k ohm)
should i try a bigger one?

Programmer, think i sholved it!
I hooked up a slightly bigger resistor and now its giving me 1023's and some sort of code ( in the numbers 1,2,3 when i press buttons!)

now i can figure out what code is what button and program it to for example the power button.

Thanks!

Well, I haven't had a chance to work out Sending IR codes.. but with a receiver, there is a very good library available! Very simple to use, but I'm not sure it's as easy to send as it is to receive(using this library anyway)

This was taken from another thread:
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1210243556/15
Also, here's the library, since the first post link doesn't work anymore:
http://lemio.nl/download.php?info=arduino.cc&file=http://lemio.nl/files/necirrcv.zip

The code is fairly simple to work with, only problem I have had so far, is that some keys on my remote , such as the 2 and the 3, and the 4 and the 5, both register as the same key. But other keys are different so I just use those!:stuck_out_tongue:
Here's a sample of how easy it is to receive information from a remote, and say.. turn on a light!

// look for IR codes and print them as they are received

#include <WProgram.h>
#include <NECIRrcv.h>
#define IRPIN 4    // pin that IR detector is connected to
#define ledPin 13  // ledPin for debugging or turning on and off

NECIRrcv ir(IRPIN) ;

void setup()
{
  Serial.begin(9600) ;
  Serial.println("NEC IR code reception") ;
  ir.begin() ;
}

void loop()
{
  unsigned long ircode ;
  
  while (ir.available()) {
    ircode = ir.read() ;
    Serial.print("got code: 0x") ;
    Serial.println(ircode,HEX) ;
  }
   if (ircode == 0x5E4F930) // After testing code, insert the key here
{
   digitalWrite(ledPin, HIGH);
} else {
   digitalWrite(ledPin, LOW):
}

}
  • CaptainObvious,
    Thanks for the respond, but it doesnt work!
    i tried the code you gave me, but when i zap the IR with my remote, nothing happens! Maybe my circuit is wrong or something :frowning:
    Please help.

Thanks Max

Have a look at Lady Ada's TV B Gone project at:

http://www.ladyada.net/make/tvbgone/index.html

It uses an AVR chip to mimic a remote control, and in the Design section theres a lot of notes on how remote controls work. Will probably help to decipher what it's sending.

Hey max,
keep in mind, some of the newer remotes use the (I THINK) it's called RC6? Where this library will only do RC5.

Pretty much the big difference is how the information is sent and received, so try a different remote. Also, it only works for some protocols.. like picked up all my TV remotes, but not my DVD players, or my Satellite receivers.

Also I just want to be sure, you're using a 38KHZ receiver right? like this one from radioshack RadioShack.com Official Site - America's Technology Store

captain, i dont know what kind it is.
let me explain :stuck_out_tongue:
my grandpa had this tv and he bought a new flat one.
so i could have the tv ( note: remote was not included, tv was broken!)
so i opened it up and took everything usefull from it :stuck_out_tongue:

ill try some different remotes!
thanks for the help.

Hooking up a IR-receiver on a analog port will not work.

Your IR-PIN will go LOW if its receives a IR-signal. Based on the timing, and protocol you can read out bit's

Best way to do this, is interrupt driven, as IR is 36/38Khz you don't want to miss a bit.

as IR is 36/38Khz you don't want to miss a bit

If you demodulate it first, the code bit rate is very much lower.

Yes your right, that what i mean, but still timing is very precise, often as low as 300us, so still using a interrupt suits best. Using a whilelus to wait for IR, well then you cant do anything else.

I have interrupt based code, so if your interested i can post it.
(its for lego protocol, you have to change the timing for a other remote control)

  • supercow
    if that piece of code works, if possible can i see it?
    that way i learn something aswell.

thanks alot, all of you guys!

anyone got an idea?
im like stuck with it... :frowning: