Grabbing the codes from Existing Remote Controls so we can use them to control things using an Arduino, Rasberry Pi, or ESP8266
This short guide will show you how to decode the codes sent but almost any IR Remote and document the codes needed. The technique is the first step in several applications
- Extending an existing remote control (e.g. TV remote) to control things like a AV Amp or a fan
- Replacing a manual button push from a remote for home automation
- Replacing a remote control with one you made yourself
- Extending the range of a remote (Both IR and Network)
- Any combination of the uses above or other more advanced uses!
The output of this "Code grabbing" Process will be a table like this which we can use to develop home automation software.
Sample code table generated using "grabbed codes"
Command Button | Encoding | Code | Length |
Kitchen TV ON/OFF | NEC | FE50AF | (32 bits) |
AVR Media Centre Button | RC5 | 17F | (12 bits) |
AVR Media Centre Button | RC5 | 97F | (12 bits) |
AVR CBL/SAT Button | RC5 | 1BF | (12 bits) |
AVR CBL/SAT Button | RC5 | 9BF | (12 bits) |
AVR VOL+ Button | RC5 | C10 | (12 bits) |
AVR VOL+ Button | RC5 | 410 | (12 bits) |
AVR VOL- Button | RC5 | C11 | (12 bits) |
AVR VOL- Button | RC5 | 411 | (12 bits) |

This is the datasheet for the IR Receiver. The datasheet will tell you which pins on the IR receiver you should connect up. We will use the IR Receiver to grab codes from IR remote controls you want to capture or use spare buttons on existing remote controls e.g. say you have a TV remote with 3 spare buttons that do nothing on your TV but want to use these buttons to turn on the AV Amp and control the volume.
I used female to male dupont connectors to wire this up.
If you look at the front (receiver side) of the receiver unit with the legs pointing down There are 3 pins the centre one is ground (Negative) the right is VCC (Positive) and the left is Data out.
Use the IR library it will decode almost any IR Remote. Write down the code it receives and then you can use that code number to drive an IR LED to control a TV, AirCon, Fan, AV Amp, Radio etc.
I ran the sample IR receiver program for arduino and when I press the TV Power button I get this. Just use the manufacture in this case NEC and the code in this case FE50AF that's all you need now to reproduce the TV / ON OFF button
TV / ON OFF Button
Encoding : NEC
Code : FE50AF (32 bits)
Timing[67]:
+9100, -4350 + 700, - 450 + 650, - 450 + 700, - 450
+ 650, - 450 + 700, - 400 + 700, - 450 + 650, - 450
+ 700, - 450 + 650, -1600 + 650, -1550 + 700, -1600
+ 650, -1550 + 650, -1600 + 650, -1600 + 700, -1550
+ 650, - 450 + 650, - 450 + 700, -1550 + 700, - 450
+ 650, -1550 + 700, - 450 + 650, - 450 + 650, - 500
+ 700, - 400 + 650, -1600 + 650, - 450 + 700, -1550
+ 700, - 400 + 700, -1550 + 700, -1550 + 650, -1600
+ 650, -1600 + 650
unsigned int rawData[67] = {9100,4350, 700,450, 650,450, 700,450, 650,450, 700,400, 700,450, 650,450, 700,450, 650,1600, 650,1550, 700,1600, 650,1550, 650,1600, 650,1600, 700,1550, 650,450, 650,450, 700,1550, 700,450, 650,1550, 700,450, 650,450, 650,500, 700,400, 650,1600, 650,450, 700,1550, 700,400, 700,1550, 700,1550, 650,1600, 650,1600, 650}; // NEC FE50AF
unsigned int data = 0xFE50AF;
We can use the manufacture in this case NEC and the code in this case FE50AF to reproduce the TV / ON OFF button for the TV using code and an IR LED.
This setup where the IR Receiver is wired directly to the Arduino is not the setup recommend for production use. As you can see a lot of noise / false signals were detected. This is not a problem in this example as we just want to grab code. Press the button with the receiver nearby using fresh batteries. Note down the code you get.
I noticed some noise
Example of noise generating spurious detection events
Encoding : UNKNOWN
Code : 17FAE8DD (32 bits)
Timing[9]:
+ 100, - 200 + 200, - 550 + 150, -2850 + 150, - 300
+ 150
unsigned int rawData[9] = {100,200, 200,550, 150,2850, 150,300, 150}; // UNKNOWN 17FAE8DD
..
Encoding : SANYO
Code : FFFFFFFF (0 bits)
Timing[31]:
+ 250, - 200 +2500, - 600 + 250, -4750 +1600, - 600
+ 100, -1750 + 100, - 300 + 900, -4800 + 100, - 150
+ 700, - 200 +3800, -4950 + 650, - 200 + 800, - 200
+ 500, - 800 + 300, - 550 + 100, - 400 + 300
unsigned int rawData[31] = {250,200, 2500,600, 250,4750, 1600,600, 100,1750, 100,300, 900,4800, 100,150, 700,200, 3800,4950, 650,200, 800,200, 500,800, 300,550, 100,400, 300}; // SANYO FFFFFFFF
unsigned int data = 0xFFFFFFFF;
I found that on some remotes button do NOT product the SAME code each time they are pressed. The first example on my AVR AMP pressing the media play button generates 2 alternating codes. I've made a note of both codes but will only use one to turn the AVR to media centre input.
AVR Media Centre Button
Encoding : RC5
Code : 17F (12 bits)
Timing[23]:
+ 950, - 800 +1850, - 750 +1000, - 750 +1000, -1650
+1850, -1650 +1000, - 750 +1000, - 750 +1000, - 750
+1000, - 750 +1000, - 750 +1000, - 750 +1000
unsigned int rawData[23] = {950,800, 1850,750, 1000,750, 1000,1650, 1850,1650, 1000,750, 1000,750, 1000,750, 1000,750, 1000,750, 1000,750, 1000}; // RC5 17F
unsigned int data = 0x17F;
Encoding : RC5
Code : 97F (12 bits)
Timing[23]:
+1000, - 750 +1000, - 750 +1850, - 800 +1000, -1600
+1900, -1650 + 950, - 800 + 950, - 800 + 950, - 800
+ 950, - 800 + 950, - 800 +1000, - 750 +1000
unsigned int rawData[23] = {1000,750, 1000,750, 1850,800, 1000,1600, 1900,1650, 950,800, 950,800, 950,800, 950,800, 950,800, 1000,750, 1000}; // RC5 97F
unsigned int data = 0x97F;
I noticed the same alternating code for the CBL/SAT input command on the AVR. Again not a problem we will use the first code only. Note how the 1 changes to a 9 in both examples so far.
AVR CBL/SAT Button
Encoding : RC5
Code : 1BF (12 bits)
Timing[23]:
+ 950, - 800 +1750, - 850 + 900, - 850 + 900, -1750
+ 950, - 800 +1800, -1750 + 900, - 800 + 900, - 850
+ 900, - 850 + 900, - 850 + 900, - 850 + 950
unsigned int rawData[23] = {950,800, 1750,850, 900,850, 900,1750, 950,800, 1800,1750, 900,800, 900,850, 900,850, 900,850, 900,850, 950}; // RC5 1BF
unsigned int data = 0x1BF;
Encoding : RC5
Code : 9BF (12 bits)
Timing[23]:
+ 950, - 800 + 950, - 850 +1750, - 850 + 900, -1750
+ 950, - 800 +1750, -1750 + 950, - 800 + 900, - 850
+ 900, - 850 + 900, - 850 + 900, - 850 + 900
unsigned int rawData[23] = {950,800, 950,850, 1750,850, 900,1750, 950,800, 1750,1750, 950,800, 900,850, 900,850, 900,850, 900,850, 900}; // RC5 9BF
unsigned int data = 0x9BF;
Interestingly on the same AV AMP the Volume Up button does the same alternating code on each press. However holding down the Volume Up just repeats one of the codes.
AVR VOL+ Button
Encoding : RC5
Code : C10 (12 bits)
Timing[23]:
+1000, - 750 +1000, - 750 +1000, - 750 +1850, - 800
+ 950, - 800 + 950, - 800 + 950, - 800 + 950, -1650
+1900, - 750 +1000, - 750 +1000, - 750 +1000
unsigned int rawData[23] = {1000,750, 1000,750, 1000,750, 1850,800, 950,800, 950,800, 950,800, 950,1650, 1900,750, 1000,750, 1000,750, 1000}; // RC5 C10
unsigned int data = 0xC10;
Encoding : RC5
Code : C10 (12 bits)
Timing[23]:
+ 950, - 800 + 950, - 800 + 950, - 800 +1850, - 750
+1000, - 800 + 950, - 800 + 950, - 800 + 950, -1650
+1900, - 750 + 950, - 800 +1000, - 750 +1000
unsigned int rawData[23] = {950,800, 950,800, 950,800, 1850,750, 1000,800, 950,800, 950,800, 950,1650, 1900,750, 950,800, 1000,750, 1000}; // RC5 C10
unsigned int data = 0xC10;
Same behavior for Vol-
Encoding : RC5
Code : C11 (12 bits)
Timing[23]:
+1000, - 750 + 900, - 850 + 900, - 850 +1800, - 850
+ 900, - 850 + 900, - 850 + 900, - 850 + 900, -1750
+1850, - 750 + 900, - 850 + 900, -1750 +1000
unsigned int rawData[23] = {1000,750, 900,850, 900,850, 1800,850, 900,850, 900,850, 900,850, 900,1750, 1850,750, 900,850, 900,1750, 1000}; // RC5 C11
unsigned int data = 0xC11;
Encoding : RC5
Code : 411 (12 bits)
Timing[21]:
+ 950, - 800 +1800, -1700 +1900, - 750 + 900, - 850
+ 900, - 850 + 900, - 850 + 900, -1750 +1850, - 750
+ 950, - 800 + 950, -1700 +1000
unsigned int rawData[21] = {950,800, 1800,1700, 1900,750, 900,850, 900,850, 900,850, 900,1750, 1850,750, 950,800, 950,1700, 1000}; // RC5 411
unsigned int data = 0x411;
Now you know how to grab codes you can use this guide to send them https://learn.adafruit.com/using-an-infrared-library/sending-ir-codes