IR remote control is a device you can find everywhere where you can find TV, VCR or home theatre. Why not to use one of them for controlling your own devices like light, air conditioning etc.
As we know remote control devices uses IR light. This is invisible light about 950nm wavelength. One biggest problem in using IR light is that there many other sources of it like sun, light bulbs, fire. In order to exclude other sources, IR signal is modulated by some frequency. Receiver has to be tuned for this frequency. Mostly remote controls transmit IR signal using 36kHz frequency signals. Transmitting and coding is one part which can be done more easily than receiving and decoding. Decoding is usually performed by using microcontrollers. Firs of all receiver has to get rid of 36kHz carrier frequency. This is not simple task to demodulate signal, this is why special IR receiver IC’s are produced. One of them is TSOP1736:

this receiver simply removes 36KHz carrier signal and gives clean pulses that are used for device control. I won’t go too deep in how it works – you can find this information in datasheets. This module is convenient to connect to microcontrollers like AVR or PIC, because it forms TTL signal levels compatible to them.
Lets go further. Remote controls usually uses three different types of modulation: Bi-phase coding; Pulse-distance modulation and Pulse-length code.
Pulse-distance modulations is commonly used by LG, JVC, Acorp, Hitachi, Nokia, Aiwa, Akai, AverMedia, NEC. So further we will discuss only this modulation type.
As you have noticed pulse-distance modulation uses fixed length pulses while gap defines weather it is “1â€(long gap) or “0â€(short gap) logical value. When using Pulse-Distance modulation firs goes LSB then MSB bits. If remote control button is pressed for a long time, then it sends one full packet and then after som time continuously sends unitary pulses informing that button is still pressed. Note, that different manufacturers may use different length of pulses.
Let’s write decoding algorithm for AVR-GCC compiler (Atmega162):
//pin connected to TSOP1736
#define K1 (1<
uint8_t impulse_prev = 0;
uint8_t counter_impulse_1 = 0;
uint8_t flag_rx = 0;
uint8_t counter_impulse_0 = 0;
uint8_t impulse = 0;
uint64_t counter_ik = 0;
uint64_t code = 0;
ISR(TIMER0_OVF_vect)
{
uint8_t c;
uint8_t str[35];
uint64_t i;
//Timer0 initialization
TCNT0=0xFF;
//Invert input signal
if (K1==1) impulse=0; else impulse=1;
if ((impulse_prev==0)&&(impulse==1))
{//rising edge detection
//reset counter
counter_impulse_1=0;
if ((counter_impulse_0>3)&&(flag_rx==1)&&(counter_impulse_0<23))
{//if receiving symbols
if(counter_impulse_0>12)
//logical 1 received
code |=(1<
counter_ik++;
};
};
if((impulse==1)&&(counter_impulse_1<50))
//counting positive pulses
counter_impulse_1++;
if((impulse_prev==1)&&(impulse==0))
{//negative front
counter_impulse_0=0;
if(counter_impulse_1>30)
{//one long synchro pulse
code=0;
counter_ik=0;
flag_rx=1;
}
};
if((impulse==0)&&(flag_rx==1)&(counter_impulse_1<150))
//counting negative pulses
counter_impulse_0++;
if((counter_impulse_0>50)&&(flag_rx==1)&&(impulse==0))
{//end of receive
flag_rx=0;
counter_impulse_0=0;
counter_impulse_1=0;
counter_ik=0;
code=0;
};
impulse_prev=impulse;
}
Interrupt service routine ISR(TIMER0_OVF_vect) is called with frequency of 10.8kHz. This frequency is more than enough comparing with pulse frequency of receiving code. At the beginning of procedure signal is inverted. Current signal level from photo-sensor is defined by variable impulse. Signal reference is signal front (variable impulse_prev). Duration of positive and negative impulses are defined by variables counter_impulse_0 and counter_impulse_1. They show how much time have passed since signal front was registered.
flag_rx variable indicates beginning of signal transfer.
Received code is stored in 64-byte variable code. Variable counter_ik indicates bit number in received code.
Algorithm can receive one code. Using this ISR you can program any control from your fantasy
Further example demonstrates hos this can be used to control remote light switch:
Download hex code for this circuit here: remote_light_switch.zip
Remote control button code is stored in EEPROM. It can be programmed by pressing remote control button 20 times. After this code is saved to EEPROM. If you missed button then start again from 0 to 20.
RS232 interface is optional if you want to expand functionality of remote switch by connecting it to another embedded platform or PC. Circuit sends code in ASCII format at kB/s speed.
LED D1 indicates that MCU works OK; LED D2 – indicates about receiving signal; LED D3 – indicates that Light switch is ON/OFF.
Of course it is easy to construct algorithm to another AVR MCU and for different purposes. This article only gives an idea of using a remote control with embedded platforms.
it is a great information for beginners
Hi,
Line 26 seems to be broken,
as code |=(1 Can you perhaps put the source code into a .txt file / zip it and send to me?
Thanks
Can you sand the full source code to me at pratheepmail@gmail.com
Unfortunately only hex and decoding code fragment is available for this circuit.
will you put full source code is txt format. i unable to understandhow it differtiate key of remote controller
i wont to use atmega8,will you put full source code
It’s grate. thanks!
hi guy’s……..
i am asking for your help guy’s….i have this project…the doctor asked me for a project to write alphabetic’s on lcd using avr and bascom programing lang….the idea is not that hard..but i can’t figure how to recognize different buttons on remote control using the avr…i mean this is how i imagine it…button 1 on remote is assembled by 5 0/1 digital signal’s …button2 by 6 and …etc.
plzzzzzzz help me with the hole concept…and how can i read a single 0/1 using avr …
hey
can anyone mail me the full code of this project,
i m unable to understand it clearly
hey
can anyone mail mw the whole code
at
er_vikram190@hotmail.com
Sigh, what’s up with all these people asking for source. It’s right there!
Can somebody send me full C code, because i see that there are some lack code.
xcentras@gmail.com Thanx.
I am looking for am explanation about IR tran/recieve .
i am a beginner.
where can i get tutorial about that in c language.
Pingback: RC5 and Manchester Coding « Sparktastic
I have assembled a IR Remote controller kit from Embedded For You magazine it works fine.
http://www.embedded4u.com/kits4u.asp?pno=1&sel=1&cat=