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.
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.inounder the path of
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.
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.
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.
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.
Restart for receiving an other value.