Help for beginners - IR Remote Control Decoder

If you’re new (like me) and are interested in opening the door to infrared signal decoding so you might control devices remotely, here’s some code to help you along the way. It’s what I’ve learned so far.

I have no diagram or schematic…it’s just three wires: 5v (+) (-) to the IR receiver module and one wire from the IR receiver module to signal Arduino digital pin 11. Simple.

C&P - it’s free.

 *  File: IR_remote_control_decoder_v0.2_FINAL
 *  Author: Rex Qualis Tutorials
 *  Modified: Casey Gilbertson aka ItsCaseyDambit
 *  Date: 01/29/2020
 *  Hardware Required
 *    1 ea.   Arduino UNO card    ( I used Rex Qualis UNO R3 )
 *    1 ea.   IR receiver module  ( I used RQ-S003 )
 *    1 ea.   IR remote               ( unidentified )
 *    3 ea.   F-M Jumper Wires
 *  Purpose: This program is used to report which infrared (IR) remote control buttons are being pressed.
 *    The original "project" did not bother establishing any serial connection, so, there was ZERO report
 *    being accomplished. I included the serial connection and baud rate, cleaned-up the reports so they
 *    declare what's happening when the buttons are being held down OR when two-or-more buttons are
 *    being pressed at once.
 *    Note: controllers vary and your controller may transmit different signals than the one I used 
 *      (and, I have no ID for my controller). The signal values MAY be universal, I dunno.
 *      This is only a test. See if your controller's signals match these signals.
 *    I also documented the operations of the program so humans can (with hope) understand. PLEASE DOCUMENT EVERYTHING!
 *    If you're curious and like to experiment, try changing the REPEAT_READ_DELAY value and see how short
 *    a delay you can use before the "You're holding the button down too long..." message occurs.
 *    It's all about learning.
 *    Enjoy!


#include "IRremote.h"                           // include the IRremote.h file from our library for using predefined IR goodies

#define REPEAT_READ_DELAY 0x32                  // declares how long to delay before reading the next button being pressed...
                                                // ( 0x32 == 50/1000 of one second ) - too short of a delay and repeat reads occur

int receiver = 0xb;                             // set Arduino digital pin-11 as the IR signal receiver 

                                                // declare the objects...                                                  
IRrecv irrecv(receiver);                        // create an instance of 'irrecv'
decode_results results;                         // create an instance of 'decode_results'


void translateIR()                              // begin method translateIR() 
                                                // prints the IR remote control's send codes....
  switch ( results.value ) {                    // begin switch() 
    case 0xFFA25D: Serial.println( "Power ON/OF" );   break;    // print which remote control button has been pressed...
    case 0xFFE21D: Serial.println( "Mute" );          break;
    case 0xFF629D: Serial.println( "Mode" );          break;
    case 0xFF22DD: Serial.println( "Pause" );         break;
    case 0xFF02FD: Serial.println( "Fast Back" );     break;
    case 0xFFC23D: Serial.println( "Fast Forward" );  break;
    case 0xFFE01F: Serial.println( "EQ" );            break;
    case 0xFFA857: Serial.println( "Vol -" );         break;
    case 0xFF906F: Serial.println( "Vol +" );         break;
    case 0xFF9867: Serial.println( "Return" );        break;
    case 0xFFB04F: Serial.println( "USB Scan" );      break;
    case 0xFF6897: Serial.println( "0" );             break;
    case 0xFF30CF: Serial.println( "1" );             break;
    case 0xFF18E7: Serial.println( "2" );             break;
    case 0xFF7A85: Serial.println( "3" );             break;
    case 0xFF10EF: Serial.println( "4" );             break;
    case 0xFF38C7: Serial.println( "5" );             break;
    case 0xFF5AA5: Serial.println( "6" );             break;
    case 0xFF42BD: Serial.println( "7" );             break;
    case 0xFF4AB5: Serial.println( "8" );             break;
    case 0xFF52AD: Serial.println( "9" );             break;
    case 0xFFFFFFFF: Serial.println( 
      "You're holding the button down too long..." );    break;
      "Cannot translate: You're pressing two-or-more buttons" );
  }                                             // end switch()
  delay( REPEAT_READ_DELAY );                   // delay for the REPEAT_READ_DELAY amount of time #defined above
}                                               // end method translateIR()


void setup() {                                  // begin setup()
  Serial.begin( 0x2580 );                       // start the serial communications ( com3 on my UNO board ) at a baud rate of 9600 ( 0x2580 )
  while ( !Serial );                            // wait for the USB cable to be connected
    "Serial connection established..." );       // report serial connections were established
  pinMode( receiver, INPUT );                   // set the Arduino digital-pin-11 mode to INPUT 
    "IR Remote Control Button Decoder");        // print the report title
  irrecv.enableIRIn();                          // enable the IR receiver for input
}                                               // end setup()


void loop() {                                   // begin loop()
  if ( irrecv.decode( &results ) ) {            // begin if()...if we received an IR signal from the remote control...
    translateIR();                              // translate the IR signal, then...
    irrecv.resume();                            // resume receiving the next IR signal from the remote control
  }                                             // end if()
}                                               // end loop()


                                                // end IR_remote_control_decoder_v0.2_FINAL.ino file
1 Like