I have connected an Infrared LED and I'm trying to read some values from a TV remote control. From the examples I have found on the internet, they all use the pulseIn function, but I can't seem to get it to work.
This is the code I'm using :
void setup () {
pinMode(7, INPUT);
Serial.begin(9600);
}
void loop () {
Serial.println(pulseIn(7, LOW)); //tried with both LOW and HIGH
}
The pulseIn function is always returning a 0, and I have tried it with both LOW and HIGH.
The value returned is always 0, even when I'm pointing the remote control at it and pressing buttons.
What can I be doing wrong ?
The below is an image of my current setup (the resistor is 240[ch937]) :
You have the circuit wrong and you have probably fried the LED.
You have connected the LED direct to the 3V3 line without any current limiting resistor.
You also have the concept wrong, you don't detect pulses from a LED you generate them. You need a photo diode or photo transistor to detect light.
The part about the circuit being wrong and frying the LED is true.
However, it's not strictly true that one cannot detect pulses with a normal LED. If you reverse bias the LED it can be used as a photo diode. This will work for detecting light at the same wavelength that the LED would have put out. In this configuration, when the LED is in the presence of the proper wavelength light, it will start to conduct.
I don't know if you didn't mention that because it only complicates things for people new to the game. And, it's pretty confusing and easy to mess up. I'm not really saying that it's a good idea, but it WILL work.
So, assuming that the original poster still has some LED's around:
Wire it so that the LED is in reverse bias with the +5V rail going to the cathode of the LED. Then wire the 240 ohm resistor to the anode. Finally, wire the other side of the resistor to the digital input pin on the arduino. Then try your sketch.
Heh, yes, I suppose that's true! I don't do the LED backwards trick personally. Why not use the actual proper part? It's not as if photo transistors are a million bucks.
and not applicable here. most remotes use a 38khz modulated signal which the reverse biased LED won't pick up properly. I like to use the sharp ir detectors which output the proper binary form of the signal which makes it a lot easier
IR receiver modules can be easily scavenged from old VCRs. These are easy to use with the Arduino as they demodulate the 38 kHz carrier. Or you could just filter it out. There is even an example Sketch in the playground, I got it to work out of the box.
BTW is it true that the 38 kHz carrier is a throw back top the old ultrasonic remote controls ?