IR is widely used in the remote control. With this IR receiver, the Arduino project is able to receive a command from any IR remoter controller if you have the right decoder. Well, it will be also easy to make your own IR controller using an IR transmitter.
- Based on the 38KHz IR Receiver Sensor
- Can be used for remote control
- Apply to a variety of platforms including Arduino/51/AVR/ARM/Pi
- Power Supply : 5V DC
- Current: 3 - 5mA
- Interface : Digital
- Modulated Frequency : 38Khz Carrier IR code
- Transmission distance: 1~8m (Depends on transmit terminal)
- Transmission Angle : 60 Degree
To connect a stand-alone receiver diode, wire it like this:
PROGRAMMING THE IR RECEIVER
Once you have the receiver connected, we can install the Arduino library and start programming. In the examples below, I’ll show you how to find the codes sent by your remote, how to find the IR protocol used by your remote, how to print key presses to the serial monitor or an LCD, and finally, how to control the Arduino’s output pins with a remote.
INSTALL THE IRREMOTE LIBRARY
We’ll be using the IRremote library for all of the code examples below. You can download a ZIP file of the library from here.
To install the library from the ZIP file, open up the Arduino IDE, then go to Sketch > Include Library > Add .ZIP Library, then select the IRremote ZIP file that you downloaded from the link above.
FIND THE CODES FOR YOUR REMOTE
To find the key codes for your remote control, upload this code to your Arduino and open the serial monitor:
Now press each key on your remote and record the hexadecimal code printed for each key press.
FIND THE PROTOCOL USED BY YOUR REMOTE
Knowing which protocol your remote uses can be useful if you want to work on some more advanced projects. Or you might just be curious. The program below will identify the protocol used by your remote. It even works on most remote controls around your house.
PRINT KEYS TO THE SERIAL MONITOR
We extended the code above to print the key-value instead of the hexadecimal code:
If your remote sends different codes than the ones in the table above, just replace the hex code in each line where it says:
In these lines, when the hex code 0xFFA25D is received, the Arduino prints “CH-“.
HOW THE CODE WORKS
For any IR communication using the IRremote library, first we need to create an object called irrecv and specify the pin number where the IR receiver is connected (line 3). This object will take care of the protocol and processing of the information from the receiver.
The next step is to create an object called results , from the decode_results class, which will be used by the irrecv object to share the decoded information with our application (line 5).
In the void setup() block, first we configure the serial monitor baud rate. Next we start the IR receiver by calling the IRrecv member function enableIRIn() (line 10).
The irrecv.blink13(true) function on line 11 will blink the Arduino’s on board LED every time the receiver gets a signal from the remote control, which is useful for debugging.
In the void loop() block, the function irrecv.decode will return true if a code is received and the program will execute the code in the if statement. The received code is stored in results.value. Then I used a switch to handle each IR code and print the corresponding key value.
Before the switch block starts there is a conditional block:
if (results.value == 0XFFFFFFFF)
results.value = key_value;
If we receive 0XFFFFFFFF from the remote, it means a repetition of the previous key. So in order to handle the repeat key pat