views:

222

answers:

5

Hi

Please let me know how to decode infrared remote control code using c or c++.

+4  A: 

I suppose your question is vague because you absolutely don't know where to start.

If you don't have a infrared receiver, here is a blog is used some time ago to learn how to build one. I hope you have some talents in electronics. Otherwise, it's time to learn ! :D

If you managed to build it (or have another known-working receiver), you can then take a look at LIRC, an open-source project which is compatible with the suggested device.

ereOn
LIRC is definitely a good place to start - potentially you could just port it (or the specific parts of it you need) to your target.
caf
+2  A: 

Well, I don't know about C++, but here it is in C#:

void ReadRemote()
{
    while(!Console.KeyAvailable)
        Console.Write(DecoderClass.ReadIR(IRType.TVRemoteControl));
}
Paul
That's amazing oO Is this serious ?
ereOn
No, not at all.
Paul
A: 

Looking at your tags, you probably want to do this on a micro controller.Here's one such project

itisravi
+2  A: 

Different manufacturers use different encoding schemes, different timing, and even different modulation frequencies. A typical IR receiver sensor performs the demodulation in hardware so that it outputs a logic pulse sequence rather than an OOK modulated signal. The receiver needs to match the transmitter modulation frequency. If you want to receive multiple modulation frequencies, you would have to use a simple IR photo-diode and provide your own OOK carrier detector circuitry for each modulation frequency of interest, or use multiple receivers.

Once you have the demodulates pulse sequence, it is a simple matter of decoding it according to the specific manufacturers encoding scheme. I have only ever done this for a Sony SIRC remote to use it as a robot controller. Where the sensor triggered an interrupt and the pulse timing was latched on each interrupt. If your device has input capture and compare timer hardware you could reduce the overhead and increase accuracy (although this is probably not necessary).

There are lots of resources on the subject for different protocols and manufacturers here

There are some applicable standards, but no manufacture has to adhere to them, and there is more that one. RC-5 and RECS 80 are two such standards that are fairly common.

Clifford
+1  A: 

Either buy some hardware that does it and make C or c++ api calls (lirc for example). or if you are interested in decoding the protocols and doing it with software instead of hardware then you want to use a microcontroller.

It is fun and easy and I recommend it as a first microcontroller project. There are a handful of popular protocols, most are a variation on a couple of themes. Basically you get a receiver which you can get from radio shack, although the amount of what used to be radio components at radio shack (maybe that is why they are changing the name to the shack) are much fewer and buried in a small drawer in the back of the store, soon to be gone. Anyway get a receiver there or digikey or mouser, a microcontroller, count the number of clock ticks between rising and falling edges (the receiver has removed the ~40Khz carrier frequency) compare those times to the expected protocol and determine the ones from zeros. Transmitting with just a microcontroller and an ir led can be done but is a little trickier because you need to do the modulation. A single and gate outside the microcontroller along with the modulation clock and/or a timer generated clock is much easier, but requires extra hardware.

The multi protocol receivers are likely not to be as good as a specific protocol receiver, in the same way that gcc is not very good at any one platform, but pretty good across all the platforms. Building your own is fun, educational, and generally results in a better receiver, although you wont be able to match the price of the mass produced products. Part of the problem also has to do with the carrier frequencies vary and ideally you want to choose the receiver that matches the carrier frequency for the protocol you are using. It makes a difference, for example instead of having to be 8 feet away you can be 30 feet away. Also it may work at 3 feet away but not one foot or three inches away. That sort of thing. cable and dish and other universal remotes generate all of the protocols so you are free to pick and choose depending on what your project is.

dwelch