GoRobotics - Robotics news, robot projects

Building an Infrared Remote Decoder

Posted on May 29th, 2005 in Sensors

Craig Gardner shows you how to build an infrared remote decoder – control your robot with a TV remote!


Adding a form of remote control to your robot can be fun but radio can sometimes be over kill. Infrared such as used for your

TV, VCR and other equipment is a simple way to add control to a project and can be used to control your robot or as a

wireless keypad to enter parameters and you can get universal remotes for as little as $5.

You will need the following parts for the receiver.
1 PIC12F675 or PIC12F629
1 PNA4612M
2 .1uf capacitors
2 390 ohm resistors
1 LED

The circuit is very straight forward and can be built point to point on perfboard or you can etch a board with the artwork

provided. The pdf of the board has 4 boards side by side each board is very compact and it is easy to etch your own using the

toner transfer method.

Infrared remotes send out a stream of pulses of different lengths to indicate a start bit then data bits the decoder

described decodes Sony IR remotes which are based on a pulse code signal coding which have a start bit of about 2200 us then

12 data bits the first 5 are the device data bits such as TV, VCR, etc. the next 7 are the command bits. A logic 0 is about

550 us and a logic 1 is 1100 us.

The circuit uses a Microchip PIC12F675 or PIC12F629 the main difference between the chips is that the PIC12F675 has 4

channels of 10 bit A/D. Pin 3 GPIO.4 of the PIC is connected to a PNA4612M module which sets the output pin low when it

receives a 38khz modulated infrared signal there is also a resistor and LED connected from +5 to the output pin so you can

see it flash on as the module receives data, these 2 parts can be left out if you want. There is a resistor on the serial

output pin 7 GPIO.0 which is there to limit current as a precaution. The circuit only requires 3 pins to your microcontroller

GND, +5 volts, serial out you can use your choice of connectors or just wires. When mounting the PNA4612M I leave the leads

long and bend it over so that it points up making it easier to receive the IR signal. After soldering the connector on the

bottom I use hot glue to add a little extra mechanical strength so the connector won’t bend over easy.

The program was written using ME Labs Pic Basic Pro and is small and straight forward. The program gets the 7 command bits

and 1 device bit and sends it out serially at 9600 baud inverted then waits for the next command.

A step by step of the program flow is.

Set fuse settings and control registers since we don’t need A/D or Comparators we turn them off.

@ DEVICE INTRC_OSC, MCLR_off, PROTECT_OFF, WDT_OFF
CMCON = 7 ‘ Comparators OFF
ANSEL = 0 ‘ A/D OFF — Port pins all digital
TRISIO = %010000 ‘ All I/O but GPIO3 = outputs
GPIO = %00000000 ‘ All 0 on boot
Define OSCCAL_1K 1 ‘ Set OSCCAL for 1K device

Next we define variables and clear them all to 0

IRpulse_length var word(13)
xx var Byte
Command Var Byte
Clear

Then using the pulsin command the program will measure the length of pulses and if the pulse is less than 2000us it tries

again if no pulse is present the pulsin command will time out and give a result of 0.

Getstartbits:
Pulsin GPIO.4,0,IRpulse_length(0)
if IRpulse_length(0) < 200 then
goto getstartbits
Endif

Once a start bit is received the program begins measuring the next 12 pulses storing the values in the array Irpulse_length.

for xx=1 to 12
pulsin GPIO.4,0,IRpulse_length(xx)
next xx

Now the program has to check the pulse widths and determine if it is a logic 1 or a logic 0 if it is less than 1000us it is a

0 otherwise it is a 1.

displaybits:
if IRpulse_length(1) < 100 then
Command.bit0 = 0
Else
Command.bit0 = 1
endif
if IRpulse_length(2) < 100 then
Command.bit1 = 0
Else
Command.bit1 = 1
endif
if IRpulse_length(3) < 100 then
Command.bit2 = 0
Else
Command.bit2 = 1
endif
if IRpulse_length(4) < 100 then
Command.bit3 = 0
Else
Command.bit3 = 1
endif
if IRpulse_length(5) < 100 then
Command.bit4 = 0
Else
Command.bit4 = 1
endif
if IRpulse_length(6) < 100 then
Command.bit5 = 0
Else
Command.bit5 = 1
endif
if IRpulse_length(7) < 100 then
Command.bit6 = 0
Else
Command.bit6 = 1
endif
if IRpulse_length(8) < 100 then
Command.bit7 = 0
Else
Command.bit7 = 1
Endif

The program only gets 1 device bit this is bit 7 of the command byte and will be 0 if your remote is set for a VCR and a 1 if

it is set for a TV. When set for VCR if you press the number 1 key it will send a 0 and will increment up from there sending

a 9 when you press 0. The next part checks bit 7 and if it is a 0 then it adds 1 to the command this is so if you press the

number one on the remote it the command will be one and it also checks for the command to be 10 if it is it changes the

command to 0 so you can use the remote as an infrared numeric pad.

If Command.bit7 = 0 then ‘Bit 7 is one of the device bits
Command = Command + 1
Endif
If Command = 10 then
Command = 0
Endif

Now that the command has been decoded the program sends it out serially at inverted 9600 baud then pauses for 100ms so if the

remote sends the command twice it won’t get the second and goes back nand waits for the next command.

SEROUT GPIO.0,2,[Command]
pause 100
goto Getstartbits

A sample program for the Basic Atom to receive the commands and send them out the built in serial port to a terminal program

as a decimal number is.

Temp var byte
Main
Serin 0,I9600,[Temp]
Serout S_out,I9600,[Dec Temp,13]
Goto Main

All of the parts needed except the PIC12F675 can be found at any good electronic store or even Radio Shack which has a

limited selection of parts, they can even be scavenged from an old VCR. The PIC12F675 can be requested as a FREE sample from

Microchip you can register as a student and they will send you your choice of 3 pieces of 1 part

Other Files

Silkscreen PDF
IRreceiver.bas
IRreceiver.hex

Data sheets
PNA4612M
Http://www.semicon.panasonic.co.jp/ds/eng/SHE00046AED.

pdf

PIC12F629 PIC12F675
Http://www.microchip.com/download/

lit/pline/picmicro/families/12f6xx/41190c.pdf

Microchip samples
Http://sample.microchip.com/Default.aspx?

Information on Sony IR remotes can be found at
Http://pasture.ecn.purdue.edu/~laird/electronics/Sony/

If you need parts or a PIC programmer Peter Anderson sells parts and programmers at reasonable prices he gets a A+++++

recommendation.
Http://www.phanderson.com/

H sells the PIC-PG2C for $12.95 it is a simple programmer that works ok but may not work with some laptops he also has better

programmers as well as development boards.
Http://www.phanderson.com/ordering_1.html


TrackBack URL

18 Responses to “Building an Infrared Remote Decoder”

  1. Maria Mojica Says:

    Do you know how to write a code using the PIC12F675 and GP2D12 for obstacle avoidance in a robot?

  2. cory Says:

    thats kool

  3. Mark Says:

    Good question, I have sourced the very same components to create a Lego RCX sensor. I am currently researching designs for the circuit and when I have a suitable circuit / program I will post details.
    M

  4. quino Says:

    Do we need the ME Labs PicBasic Pro? It’s too expensive

  5. JIJU Says:

    can we write a program in PIC that can execute two subprograms simultaneously

  6. mark Says:

    Shouldn’t the description on line
    TRISIO = %010000 ‘ All I/O but GPIO3 = outputs
    say
    TRISIO = %010000 ‘ All I/O but GPIO4 = outputs
    ?

  7. ahmad Says:

    yar excellent!!

    i am also making itt!!

    if u can help me in making thiss sso plzz help me in one day bcz i hve to submit thiz project to uet on friday!!!

    thankkxxx!!
    best regards!!!
    Muhammad Ahmad Islam

  8. ismail Says:

    hi all, just wondering if u electronics wizes can help me with somthing.. i want a circuit that will take ir signals above a cirtain threshold and repeat them exactly. basically i want to be able to etend the range of a tv remote controll. there are products that do this but they are too expensive and fancy for such a basic job.

    can anyone help,

    regards ismail.

  9. Kok Chun Hong Says:

    Thank you for the circuit:) May i know what purpose of “out” connected to GP0.0?

  10. William Cox Says:

    Kok,

    GP0.0 is the output from the PIC chip. You hook that pin to your microcontroller to read the output of the IR detector.

  11. Youssef Says:

    i am asking if i can use Atmel’s products instead of pic in this circuit such as ATMega16,32

  12. Mosses Odep Odago Says:

    why is it called decoder?

  13. admin Says:

    Because it decodes the IR light pattern from a remote control into a binary string that you can use in your code.

  14. Mosses Odep Odago Says:

    Functionality,adecoder performs areverse function of an encoder.Why is this not practically possible?And is it possible to convert an encoder into adecoder?

  15. steve Says:

    Hi Admin, I am trying to clone a remote control, is there an IR receiver/decoder platform available at all?

    Steve

  16. edencircle Says:

    What I’m trying to do is very similar to ismail. I want a circuit that will take all ir signals and emit them exactly as output. Just like what some commerical IR repeater does. But I need to one thing extra. When the few specifc incoming IR signals, actually they are several IR signals from my Panasonic TV remote control, I want my IR repeater just ignore them and not emit them.

    So I need an IR decoder to detect those signal from Panasonic but I’m wondering if I can clone all other IR signals using the same circuit.

    Please kindly advise.

    edencircle

  17. Hardev Says:

    Good IR Decoder. We have designed in CCS to control dental XRAY machine.

    We have cloned several proprietary remotes in the past also.

    For Edencircle: Yes, you can filter the signals you wish to emit. Its Simple.

    Hardev Singh
    Universal Electronics

  18. Prince Says:

    Hi all,

    does anybody knows how to get ir signals through com port and display them as wave shape like some analyzer. Thanks.

Leave a Comment

Subscribe to the RobotShop Blogs RSS feed!

Enter your email address: