IR remote control signal receiver using AVR microcontroller
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.
Blogsphere: TechnoratiFeedsterBloglines
Bookmark: Del.icio.usSpurlFurlSimpyBlinkDigg
RSS feed for comments on this post | TrackBack URI for this post
New on WinAVR Tutorial
Running TX433 and RX433 RF modules with AVR microcontrollers,Sometimes in embedded design you may want to go wireless. Might be you will want to log various readi …Programming AVR ADC module with WinAVR,Most of AVR microcontrollers have Analog to Digital Converter (ADC) integrated in to chip. Such solut … |
New on WinARM Tutorial
What are differences between WinARM and WinAVR,Everyone who is working with AVR microcontrollers knows this powerful tool – WinAVR (http://win …LPC2000 watchdog timer,As in all microcontrollers watchdog timers purpose isto reset microcontroller after reasonable amount … |

March 18th, 2007 at 9:20 am
it is a great information for beginners
April 20th, 2007 at 2:01 am
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
April 23rd, 2007 at 11:11 am
Can you sand the full source code to me at pratheepmail@gmail.com
April 23rd, 2007 at 1:28 pm
Unfortunately only hex and decoding code fragment is available for this circuit.
May 5th, 2008 at 9:53 am
will you put full source code is txt format. i unable to understandhow it differtiate key of remote controller