Posted on by & filed under Electronics.

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

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.

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

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.

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

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.

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

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
If Command = 10 then
Command = 0

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
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

Data sheets


PIC12F629 PIC12F675


Microchip samples

Information on Sony IR remotes can be found at

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


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.

28 Responses to “Building an Infrared Remote Decoder”

  1. Maria Mojica

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

  2. Mark

    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.

  3. quino

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

  4. JIJU

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

  5. mark

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

  6. ahmad

    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!!!

    best regards!!!
    Muhammad Ahmad Islam

  7. ismail

    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.

  8. Kok Chun Hong

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

  9. William Cox


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

  10. Youssef

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

  11. admin

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

  12. Mosses Odep Odago

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

  13. steve

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


  14. edencircle

    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.


  15. Hardev

    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

  16. Prince

    Hi all,

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

  17. fahad naveed

    PNA4612 is not available in Pakistan. can some one tell me any alternative for this available in Pakistan.

  18. Vishal

    Hi sir I have design the decoder circuit but it is giving same o/p every time during pressing of diffrent keys

    Thanks pls reply

  19. cbenson

    Unfortunately the post is quite old and we now suggest RB-Cri-19

  20. yogesh

    hi guys.Can anyone guide me to decode infrared signal of tv remote using microcontroller 89c51?I want program for it.
    thanks plz rply.

  21. vishal

    Cbenson Thanks very much for reply.

    I have downloaded me basicpic pro with code studio
    And when I am compiling irreceiver.bad file it is giving

    illegal opcode (intrsc_osc)
    Please help me out once more

    Thanks & Regards

  22. cbenson

    Unfortunately the code is likely older, and there is a chance it might be outdated. You may need to debug line by line and/or try out sections.

Leave a Reply

  • (will not be published)