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:
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.
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.
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)
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!
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
Please help.
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.
captain, i dont know what kind it is.
let me explain
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
ill try some different remotes!
thanks for the help.
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)