Friday, February 27, 2015

Arduino RC5 IR Remote Control Decoder

Philips RC5 infrared remote control protocol decoder using Arduino

We can simply decode any IR remote control using Arduino board. Here we are not going to use any Arduino IR library, we are going to decode the Philips RC5 protocol using own software.
About Philips RC5 protocol:
The following link is from Wikipedia, it is very important to understand how the RC5 protocol works.
Arduino RC5 remote control decoder circuit:
Circuit schematic of this application is shown below:

arduino rc5 ir remote control decoder circuit rc5 protocol arduino code

As we see from the circuit there is IR receiver, this device receives the infrared signal.
The lcd display used is 1602 LCD which displays the results.
I took this picture from my home application:

arduino code circuit for rc-5 protocol remote control decoder

Philips RC5 remote control decoder Arduino code:
The application code is as the following one:


#include <LiquidCrystal.h>
 LiquidCrystal lcd(3, 4, 5, 6, 7, 8);
 unsigned char j, m, toggle, address, command=0;
 void setup() {
 lcd.begin(16, 2);
 pinMode(2, INPUT);
 }
 void loop() {
 lcd.clear();
 lcd.setCursor(3, 0); lcd.print("Arduino RC5");
 lcd.setCursor(3, 1); lcd.print("IR decoder");
 delay(5000);
 lcd.clear();
 lcd.setCursor(2, 0); lcd.print("Toggle bit:");
 lcd.setCursor(1, 1); lcd.print("Addr:   Cmd:");
 while(1){
  return_:
  while(digitalRead(2));
  //Check if the received signal is RC5 protocol
  for(m = 0; m < 24; m++){
    delayMicroseconds(105);
    if(digitalRead(2) != bitRead((m >> 3),0))
    goto return_;}
   //End checking 
 delayMicroseconds(1400);
 //Read data
 for(j = 0; j < 12; j++){
 if (j == 0){
   if(digitalRead(2) == LOW) toggle = 1;
   else toggle = 0;}
 else {
 if (j < 6){
  if(digitalRead(2) == LOW){ bitSet(address, 5 - j);}
  else bitClear(address,5 - j);}
  else{
  if(digitalRead(2) == LOW){ bitSet(command, 11 - j);}
  else bitClear(command, 11 - j);}}
 delayMicroseconds(1778);        }
 //End read data
 //Display results
 lcd.setCursor(13, 0); lcd.print(toggle);
 lcd.setCursor(6, 1); lcd.print(address / 10);
 lcd.setCursor(7, 1); lcd.print(address % 10);
 lcd.setCursor(13, 1); lcd.print(command / 10);
 lcd.setCursor(14, 1); lcd.print(command % 10);
 }  
 }


RC5 remote control decoder using Arduino video: