Arduino and Infrared (IR) Remotes

This Article is the first of a series on programming an Arduino micro controller to control X-10 devices using an infrared (IR) remote control. This is a relatively cheap project. To make the first part of this project you will need an Arduino micro-controller, an IR receiver and any IR remote control. The overall cost should not exceed $50.

First you need to crack the protocol of the IR remote control you picked up. You can pretty much use any IR remote control you have in your house – no complex circuit is required. If you purchased the ZX-IRM infrared receiver, you can connect it directly to your Arduino board. Otherwise, you will find plenty of information on the web on how to build an IR receiver.

Infrared communication is carried using pulses of infrared light. Most packets of data contain about 16 bits of data. The duration of the light pulse determines if the bit transferred is 0 or 1. The following program displays all light pulses received through the infrared (IR) receiver. This information will help you crack the protocol used by your remote control. Because of delays produced by the Serial communication with the Arduino board, there may be some inconsistencies in the data displayed. I recommend pressing more than once the remote key to get an accurate reading of the binary stream received.

These are the things you first have to look at when reading the program outputs:

  • The duration of the START pulse.
  • The duration of 0 and 1 pulses.
  • The presence and duration of a STOP/REPEAT pulse.
  • The length, in bits, of the data stream.
#define IR_LED 7
#define MAX 128
#define MICRO_STEP 10
#define IDLE_PULSE 10000

unsigned long pulses[MAX];

void setup()
  pinMode(IR_LED, INPUT);

void loop()
  // The IR receiver output is set HIGH until a signal comes in ...
  if( digitalRead(IR_LED) == LOW)
    //Start receiving data ...
    int count = 0;
    int exit = 0;
      while( digitalRead(IR_LED) == LOW )

      // Store the time when the pulse begin
      unsigned long start = micros();

      int max_high = 0;
      while( digitalRead(IR_LED) == HIGH )
        max_high += MICRO_STEP;
        if( max_high > IDLE_PULSE )
          exit = 1;

      unsigned long duration = micros() - start;
      pulses[count++] = duration;

    for(int i=0; i<count; i++)
      if(pulses[i] > IDLE_PULSE)
        Serial.print(pulses[i], DEC);
        Serial.print(pulses[i], DEC);


The start pulse is always the first and longest pulse of the stream. This pulse marks the starting point of the data stream. Subsequent to the start pulse are the data bits. There is no standard for this stream of bits but you will usually find about 8 to 16 bits of data.

Following the data stream, you should look for the stop pulse. The stop pulse is not mandatory and in most protocols, the stop pulse is used to signal command repetition. If the user maintains the remote button pressed, the stop pulse is sent repeatedly until the button is released. However, if there is no stop pulse, the data stream, starting with the start pulse, is repeatedly sent in its entirety when the remote button is maintained pressed.

Finally, you should look for the length of the data stream sent by the remote control every time a button is pressed. Most new remotes are using a fixed length data stream. You can easily determine the length of the stream by counting the number 0 and 1 pulses received for each command.

In the next article, I will put everything together and start writing code in order to use the remote control.

Philippe Chrétien


  1. […] the first article of the series, I explained how to break the code of a standard infrared remote control. In this article, we will […]

    1. Manolis Roxanas
      February 3, 2013

      Hi Philippe,
      What about a Hitach airconditioning unit remote that sends 296 bits of data on every command ?


Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top