ARDUINO: DECODING TV REMOTES INFRARED SIGNALS WITH AN IR RECEIVER
- Layout for this exercise:
- The TV remotes used in this exercise are of very common brands, like Samsung and Sony:
1 - Introduction
- Infrared (IR) radiation has slightly longer wavelength and shorter frequency than visible light, just next to the red color, but it is undetectable to the human eye.
- IR radiation can be used as a wireless communication technology.
- IR is used in so many environments, for instance for turning on/off TV with a remote, and for selecting different options like channels, brightness, volume, etc ...
- A TV remote uses an IR transmitter that sends information to an IR receiver on the TV device, with usually a modulated frequency of 38 KHz.
- About the schematics used in this exercise, the IR sensor has got three legs connected in this way:
- VCC = 5 V
- GND = GND
- Data = pin 11
2 - Decoding TV remotes with an IR receiver
- Before using the Arduino with an IR sensor the IRremote library must be installed:
- The Arduino sketch for decoding the TV remote signals:
- Once the TV remotes are pointed to the IR sensor and pressed some buttons the serial monitor outputs the hexadecimal values of the decoded signals:
- Actually, in this exercise just the two first values will be used, corresponding to the "power" buttons of the Samsung and Sony remotes:
- 0xA90 (three times)
- Testing the decoding process:
- Let's analyze the code of the Arduino sketch.
- First of all, the IRremote library is imported:
- The pin 11 is assigned to the receiving and the decoding process, because it is connected to the data leg of the IR sensor, and a receiver object is created:
- The serial monitor is set to 9600 bauds, and the receiving process is started:
- If a code is received True is returned, the value is stored in the variable "results", and the serial monitor prints that value. Finally, irrecv.resume() resets the receiver and prepares it to detect another code:
3 - Blinking LEDs with remotes
- Now, two LEDs are handled with the TV remotes, using the Sony remote to turn on the yellow LED and the Samsung remote to turn on the red LED.
- Code for the Arduino sketch:
- Let's analyze the code.
- First of all, the values achieved at the previous exercise are declared:
- The pins are assigned and a receiver object is created:
- The serial monitor is set to 9600 bauds, the receiving process is started, and also the LED pins are set to output mode:
- As explained before, if a code is received True is returned, the value is stored in the variable "results", and the serial monitor prints that value. Finally, irrecv.resume() resets the receiver and prepares it to detect another code:
- Now, depending on the value of the received code, either matching 0xE0E040BF or 0xA90, the yellow or red LEDs start blinking every half second:
- Testing the circuit, when the Samsung remote's "power" button is pressed the yellow LED blinks, and when the Sony remote's "power" button is pressed the red LED blinks: