Lesson 16 – IR Remote Control


  1. Before you start working with any of the tutorials in this series please make sure you have completed the following tasks –
    1. Downloaded and installed the Arduino IDE.
    2. Are able to connect to the Arduino IDE from your computer
    3. Have been successful in uploading a simple (e.g. Blink LED’s) example programs (that comes with the Arduino IDE) onto your Arduino UNO board
  2. If you haven’t installed the Arduino IDE please head back to the first tutorial and make sure you’ve gone through each of the steps involved.
  3. Once you’ve sorted all of the above you are ready to move onto the next tutorial.


What is an infrared receiver?  – The signal from the infrared remote controller is a series of binary pulse code. To avoid interference from other infrared signals during the wireless transmission, the signal is premodulate at a specific carrier frequency and then send out by an infrared emission diode.

The infrared receiving device needs to filter out other wave and receive signal at that specific frequency and modulate it back to binary pulse code, known as demodulation.

Working Principle:
The built-in receiver converts the light signal it received from the sender into feeble electrical signal. The signal will be amplified by the IC amplifier. After automatic gain control, band-pass filtering, demodulation, wave shaping, it returns to the original code. The code is then input to the code identification circuit by the receiver’s signal output pin. The pin and the connection of the infrared receiving head.

Pin and wiring of infrared receiver:

Here’s the hardware you will need for the tutorials –

  1. Arduino Board x1
  2. Infrared remote controller x1
  3. Infrared receiver x1
  4. LED x6
  5. 220Ω resistor x6
  6. Breadboard wire x 10

First, connect the controller board; then connect the infrared receiver as the above mentioned, connect VOUT to digital pin 11, connect the LEDs with resistors and connect the resistors to pin 2,3,4,5,6,7.

You will find fritzing diagrams below outlining circuit connections for both the Arduino Uno and the Arduino Mega 2560.


Here’s what your project should look like once it’s finished.

Open up the Arduino console and you should see the messages displayed as you press different keys on the remote control.


Let’s have a look at the code for the tutorial.

Please Note:

  1. You will need to add <IRremote.h> folder into installation directory \Arduino\compiler libraries (Eg. C:\Program Files\Arduino\libraries), or it will fail to compile.
  2. The first line below is displaying properly. The actual code for the first line is #include <IRremote.h>.

int RECV_PIN = 11;
int LED1 = 2;
int LED2 = 3;
int LED3 = 4;
int LED4 = 5;
int LED5 = 6;
int LED6 = 7;
long on1  = 0x00FF6897;
long off1 = 0x00FF9867;
long on2 = 0x00FFB04F;
long off2 = 0x00FF30CF;
long on3 = 0x00FF18E7;
long off3 = 0x00FF7A85;
long on4 = 0x00FF10EF;
long off4 = 0x00FF38C7;
long on5 = 0x00FF5AA5;
long off5 = 0x00FF42BD;
long on6 = 0x00FF4AB5;
long off6 = 0x00FF52AD;
IRrecv irrecv(RECV_PIN);
decode_results results;
// Dumps out the decode_results structure.
// Call this after IRrecv::decode()
// void * to work around compiler issue
//void dump(void *v) {
//  decode_results *results = (decode_results *)v
void dump(decode_results *results) {
  int count = results->rawlen;
  if (results->decode_type == UNKNOWN) 
     Serial.println("Could not decode message");
    if (results->decode_type == NEC) 
       Serial.print("Decoded NEC: ");
    else if (results->decode_type == SONY) 
       Serial.print("Decoded SONY: ");
    else if (results->decode_type == RC5) 
       Serial.print("Decoded RC5: ");
    else if (results->decode_type == RC6) 
       Serial.print("Decoded RC6: ");
     Serial.print(results->value, HEX);
     Serial.print(" (");
     Serial.print(results->bits, DEC);
     Serial.println(" bits)");
     Serial.print("Raw (");
     Serial.print(count, DEC);
     Serial.print("): ");
 for (int i = 0; i < count; i++) { if ((i % 2) == 1) { Serial.print(results->rawbuf[i]*USECPERTICK, DEC);
      Serial.print(-(int)results->rawbuf[i]*USECPERTICK, DEC);
    Serial.print(" ");
void setup()
  pinMode(RECV_PIN, INPUT);   
  pinMode(LED1, OUTPUT);
  pinMode(LED2, OUTPUT);
  pinMode(LED3, OUTPUT);
  pinMode(LED4, OUTPUT);
  pinMode(LED5, OUTPUT);
  pinMode(LED6, OUTPUT);  
  pinMode(13, OUTPUT);
   irrecv.enableIRIn(); // Start the receiver
int on = 0;
unsigned long last = millis();

void loop() 
  if (irrecv.decode(&results)) 
    // If it's been at least 1/4 second since the last
    // IR received, toggle the relay
    if (millis() - last > 250) 
       on = !on;
//       digitalWrite(8, on ? HIGH : LOW);
       digitalWrite(13, on ? HIGH : LOW);
    if (results.value == on1 )
       digitalWrite(LED1, HIGH);
    if (results.value == off1 )
       digitalWrite(LED1, LOW); 
    if (results.value == on2 )
       digitalWrite(LED2, HIGH);
    if (results.value == off2 )
       digitalWrite(LED2, LOW); 
    if (results.value == on3 )
       digitalWrite(LED3, HIGH);
    if (results.value == off3 )
       digitalWrite(LED3, LOW);
    if (results.value == on4 )
       digitalWrite(LED4, HIGH);
    if (results.value == off4 )
       digitalWrite(LED4, LOW); 
    if (results.value == on5 )
       digitalWrite(LED5, HIGH);
    if (results.value == off5 )
       digitalWrite(LED5, LOW); 
    if (results.value == on6 )
       digitalWrite(LED6, HIGH);
    if (results.value == off6 )
       digitalWrite(LED6, LOW);        
    last = millis();      
irrecv.resume(); // Receive the next value

Happy hacking!!!


This development track requires an investment a bit of hardware. See below for details –

  1. Arduino IDE –
    1. You will need to download and install the Arduino development IDE.
    2. The approach to installation, configuration, setup of the Arduino IDE is covered in our tutorials.
  2. Arduino Uno, Sensors, etc. –
    1. You will need to purchase the Super Learning Kit for Arduino from OzToyLib.
    2. The Arduino Advent kit has all the sensors you need to perform the tutorials covered in this development track.
    3. If you do not have an Arduino Uno or Arduino Mega 2560 you might want to head over to Arduino boards and pick one up now.

The Super Learning Kit for the Arduino kit has all the sensors you need to perform the tutorials covered in this development track.

About the Super Learning Kit for Arduino

The Super Learning Starter Kit for Arduino comes packed with ~35+ different electronic bits (Sensors, LEDs, switches, LCD, servo, etc.) and can be purchased with either the Keyestudio UNO R3 or the Keyestudio Mega 2560 board. The Keyestudio Arduino boards can be used to interface with the different electronic bits i.e. sensors, LED’s, switches, servos, etc. included in the starter kit. The starter kit for the Keyestudio Uno R3 offers a great opportunity to explore the world of electronics using the Arduino Development Platform. Interact with the real world through the various sensors, create innovative projects, learn how to program the micro:bit to read data from the sensors and perform certain actions. The starter kit for the Arduino is a great way to dive into the awesome world of electronics and get started with your own STEM (Science, Technology, Engineering, Math) learning journey.

The Arduino advanced study kit walks you through the basics of using the Arduino in a hands-on way. You’ll learn the fundamentals of electronics and working on the Arduino through building several creative projects. The kit includes a selection of the most common and useful electronic components with a book of 32 projects. Starting the basics of electronics, to more complex projects, the kit will get you interacting with the physical world using sensor and actuators. Along with the kit you get access to detailed tutorials and wiring diagrams.

You can purchase the Super Learning Kit for Arduino from OzToyLib.

About the Arduino UNO

The Arduino UNO is the most used and documented board of the whole Arduino family and very easy to setup, play with. The Arduino UNO is a microcontroller board based on the ATmega328 . The Arduino UNO has 14 digital input/output pins (of which 6 can be used as PWM outputs), 6 analog inputs, a 16 MHz ceramic resonator, a USB connection, a power jack, an ICSP header, and a reset button. Here’s a listing of the some of the features of the Arduino UNO –

  1. Microcontroller: ATmega328
  2. Operating Voltage: 5V
  3. Input Voltage (recommended): 7-12V
  4. Input Voltage (limits): 6-20V
  5. Digital I/O Pins: 14 (of which 6 provide PWM output)
  6. Analog Input Pins: 6
  7. DC Current per I/O Pin: 40 mA
  8. DC Current for 3.3V Pin: 50 mA
  9. Flash Memory: 32 KB of which 0.5 KB used by bootloader
  10. SRAM: 2 KB (ATmega328)
  11. EEPROM: 1 KB (ATmega328)
  12. Clock Speed: 16 MHz

Arduino is an open-source, prototyping platform and its simplicity makes it ideal for hobbyists to use as well as professionals. The Arduino UNO contains everything needed to support the microcontroller; simply connect it to a computer with a USB cable or power it with a AC-to-DC adapter or battery to get started. The Arduino UNO differs from all preceding boards in that it does not use the FTDI USB-to-serial driver chip. Instead, it features the Atmega8U2 microcontroller chip programmed as a USB-to-serial converter. “Uno” means one in Italian and is named to mark the upcoming release of Arduino 1.0. The Arduino Uno and version 1.0 will be the reference versions of Arduno, moving forward. The Uno is the latest in a series of USB Arduino boards, and the reference model for the Arduino platform.

You can read more about the Arduino here – www.arduino.cc.