2.20 IR Receiver Module


In this lesson, you will learn to use IR Receiver Module. IR Receiver is a component with photocell that is tuned to receive to infrared light. It is almost always used for remote control detection - every TV and DVD player has one of these in the front to receive for the IR signal from the clicker. Inside the remote control is a matching IR LED, which emits IR pulses to tell the TV to turn on, off or change channels.

Schematic Diagram


Fritzing Circuit

In this example, we wire up the left pin (-) of IR Receiver Module to GND, the middle pin to 5V, and the right pin (S) to pin 11.




  • You can open the file 2.20_irReceiver.ino under the path of sunfounder_vincent_kit_for_arduino\code\2.20_irReceiver directly.

  • Or copy this code into Arduino IDE 1/2.

  • Then Upload the Code to the board.

  • Please make sure you have added the library called IRremote, detailed tutorials refer to Add Libraries.

After uploading the codes to the Mega2560 board, you can see that the current value of the pressed button of IR Remote Controller displays on the serial monitor.

Code Analysis

There are two important parts to notice in this program.

1. The code uses an extra file decodeKeyValue.ino to decode the values in class decode_result into key value.The file will be opened together with the main file.

2. IR Remote function is achieved by calling IRremote.h library related functions.

#include <IRremote.h>

Library Functions:

IRrecv(int recvpin)

Create IRrecv object to control a IR Receiver module.


In this kit, results are usually 8-digit hexadecimal numbers starting with 00FF. You can check decodeKeyValue.ino file in the sample file.

void enableIRIn()

Initialize the IR receiver module.

int decode(decode_results *results);

Decodes the received IR message. Returns 0 if no data ready, 1 if data ready. Results of decoding are stored in results.

void resume()

Restart for receiving an other value.

Phenomenon Picture