IR remote control, pt.1/2

IR remote control, pt.1/2

After buying myself a remote controlled helicopter which used infrared light to control the aircraft I was amazed by the ability to control something time critical in a reliable way. With light!

First some basics on the parts available to make your own IR remote control. It is important to know how the receiver works before making the transmitter! Also known as the remote control. You’ll need the two basic components, an infrared LED and an infrared receiver module. I used a TSOP4838 from Tayda Electronics, manufactured by Vishay. I do not know what the number 48 means, but the number 38 is the carrier frequency, which I’ll explain in more detail now.

The carrier frequency of a IR receiver module is the frequency at which the IR light must be emitted. When light IR light is emitted at this frequency it is defined as a correct burst to the module. Built inside the module is a band-pass filter to eliminate surrounding noise from fluorescent light bulbs. etc. There are also some other precautions to be taken to avoid loss of data. For example, one burst must be between 10 and 70 cycles which is approximately 2,63e-4 to 1.8 ms followed by a gap time of at least 14 cycles. If a burst exceeds this limit, there are other ways to find the gap time to follow. From the datasheet:
For each burst which is longer than 1.8ms a
corresponding gap time is necessary at some time in
the data stream. This gap time should be at least 4
times longer than the burst.

The module is a 3 pin device, Vcc, Gnd and Vout. Vout i active low, that means the voltage on the pin is high for as long as no burst of IR light at 38KHz is detected. When a burst is detected, Vout goes low (0v) for as long as the burst is present.

To control the bursts I used an Atmega8 microcontroller. I am sure there are more clever and accurate ways of doing this, but as I found out, it works great! My remote control consists of a standard IR led, the Atmega8 and four tactile switches. The four tactile switches are all connected to port B on the Atmega8, but all are also connected to the external interrupt pin INT0 at PD2. Whenever an external interrupt occurs, I read the value of port B, and use the internal timer 2 on the Atmega8 to create the bursts at the correct frequency using the CTC mode on the timer 2. I split the bursts into four bit data packets by turning on and off the timer pin OC2 output in sequences by writing to the Data Direction Register (DDR).

One consideration you can take, which I didn’t, is not to drive the LED directly off the OC2 pin, which can delivers a maximum of around 20mA. For a normal LED and a normal application, this is sufficient. But since the LED is bursting at a given frequency, you can actually up the volts a bit to make it shine brighter, since the LED will only see the mean of the voltage provided. It should then be controlled by a transistor and a resistor to limit the current below the rated peak current of the IR LED.


Whuups, just noticed the diodes to prevent the buttons from interfering are layed out the wrong way.

This is the code for the Atmega8

#include <avr/io.h>
#include <avr/interrupt.h>
#define F_CPU 8000000UL
#include <util/delay.h>

int main(void)
{
//timer 2
TCCR2 |= (1<<WGM21) | (1<<COM20) | (1<<CS20);
OCR2 = 48;

DDRC = 0x00;
PORTC= 0xF; //Pullup
PORTD=0xFF;

//INT0
MCUCR |= /*(1<<ISC00)*/ (1<<ISC01);
GICR |= (1<<INT0);

sei();

while(1)
{
}

return 0;
}

ISR(INT0_vect)
{
// -__----
if ((PINC & (1<<PIN0)) == 0)
{
DDRB |= (1<<PIN3);
_delay_us(2000);
DDRB &= ~(1<<PIN3);

}

// -_-_--
if ((PINC & (1<<PIN1)) == 0)
{
DDRB |= (1<<PIN3);
_delay_us(1000);
DDRB &= ~(1<<PIN3);
_delay_us(1000);
DDRB |= (1<<PIN3);
_delay_us(1000);
DDRB &= ~(1<<PIN3);
}

// -___--
if ((PINC & (1<<PIN2)) == 0)
{
DDRB |= (1<<PIN3);
_delay_us(3000);
DDRB &= ~(1<<PIN3);
}

// -_--_-
if ((PINC & (1<<PIN3)) == 0)
{
DDRB |= (1<<PIN3);
_delay_us(1000);
DDRB &= ~(1<<PIN3);
_delay_us(2000);
DDRB |= (1<<PIN3);
_delay_us(1000);
DDRB &= ~(1<<PIN3);
}
}

Here is a video demonstrating the use. The four low bits on the STK500 corresponds to the different data packets and can be used for various other things. The receiver circuit will be covered in detail in part 2 of this remote control blog.
Notice the oscilloscope connected to Vout on the TSOP4838

This article has 4 comments

  1. […] on to the Christmas tree itself. You might have already seen the remote control, where I was wise enough to use a stripboard (a very pretty one, with silver colored strips, maybe […]

  2. […] on to the Christmas tree itself. You might have already seen the remote control, where I was wise enough to use a stripboard (a very pretty one, with silver colored strips, maybe […]

  3. Your syntax highlighter is not escaping signs. Can we download the code?

Leave a Reply