Last time, we learned how to use the SD card. This time, we will use the infrared remote control receiver module and an infrared LED to create an infrared remote control. Most of the TV and air conditioning remote control are using infrared rays. Let’s analyze the remote control signal, and control our electronic devices using Arduino as a remote control to transmit the signal.
We often see the word “infrared” in terms such as “Infrared data communication”, “infrared camera”, “far infrared rays heater”, and so on. But what is it exactly? Let’s have a look at Wikipedia.
Infrared – Wikipedia
Infrared (IR) is invisible radiant energy, electromagnetic radiation with longer wavelengths than those of visible light. Most of the thermal radiation emitted by objects near room temperature is infrared.
The below figure shows the electromagnetic waves classified by wavelength.
Figure 1 Electromagnetic spectrum
Infrared Communication Basic Mechanism
Let’s see how things like remote control use infrared for signal transmission.
Basically, it is sending a command to switch on/off the infrared LED.
Figure 2 Remote control signal basic
Usually, infrared remote controls used with consumer electronic appliances have a common format. Japanese consumer electronics infrared remote controls use the three below formats.
Home Appliance Cooperation format
Figure 3 NEC format schematic diagram
For example, the NEC format will send out the leader signal as a cue to send a command from the remote control. Next, it sends a data signal, then it sends a stop signal format. These three formats used this basic format. If you hold down the button of the remote control, the signal is sent repeatedly, but this differs depending on the consumer electronics manufacturers. If you want to make it, you need to analyze the signal directly read from a remote control, like a “learning remote”.
※ If you want to know more about the format analysis, you should be able to find a variety of code by searching for “infrared remote control code”, “infrared analysis” and such.
Remote Control Signal Frequency
Infrared is coming from everywhere, the sun, the light, and so on. To differentiate it from the light, most of the remote controls are set to a 38KHz frequency. This time, the infrared receiver module we will use also support the 38KHz frequency.
Try to Send and Receive Infrared with Arduino
Let’s try to receive infrared signals on the Arduino. We will use an infrared remote control receiver module SPS-440-1 which can used as a receiving part for TV too. The receiving frequency is 38kHz, and it can connect directly to the Arduino as the required circuit is already built. In addition, an infrared LED is used for the transmitter.
Picture 1 Infrared receiver module
Picture 2 Infrared LED
The figure below shows the circuit to connect the infrared receiver module to Arduino.
Figure 4 Infrared circuit
Picture 3 Infrared receiver module and the Arduino
The next step is about the program. Regarding the infrared analysis, we will use the Github public Arduino-IRremote library. You can download the source on the right sidebar at the bottom. Add the downloaded source by going to “Sketch”, “Include Library”, then “Add .ZIP Library”. If the files have been successfully added, you can see that “IRremote” library has been added in “Sketch”, “Include Library”. If you can’t find it, you can unzip the downloaded file, move the folder to the Arduino libraries directory, and restart it.
We will create a program to use this library. IRremote library includes a sample program that you can use to test the receiver. This program displays the format and the data analyzed of the infrared signal input from the pin 11.
Program: analysis of the infrared signal
* IRremote: IRrecvDump - dump details of IR codes with IRrecv
* An IR detector/demodulator must be connected to the input RECV_PIN.
* Version 0.1 July, 2009
* Copyright 2009 Ken Shirriff
* JVC and Panasonic protocol added by Kristian Lauszus (Thanks to zenwheel and other people at the original blog post)
* LG added by Darryl Smith (based on the JVC protocol)
After uploading the program to the Arduino, direct the remote control of a TV (for example) towards the infrared received, and press a button on the remote control. The data signal will be displayed in the serial monitor.
Figure 7 Infrared signal outputs from the remote control
Next, let’s try the sending program for the remote control signal. To use the sending program, we will need to use the source of the library. In Arduino’s “libraries” directory, open IRremote.h, add the source of the blue frame #define… (Below figure), and then save. Now, you can send signals in accordance with each format.
Figure 8 Editing IRremote.h
After completing the IRremote.h compilation, we will write an Arduino program. In the sample example, when pressing the tact switch, the program will send three times the signal to turn on the TV in the Sony format.
Program infrared transmitter circuit
irsend.sendSony(0xa90,12);// Sony Signal of TV power ON in the format
Figure 9 Infrared remote control circuit
Picture 4 Infrared transmitter circuit
I tried to transmit the signal to the TV (※ the program slightly changed. A repeated signal is sent every 5s to turn-on/turn-off the TV).
We can now turn a TV on/off with Arduino!
This time, we have been using the infrared receiver module and the infrared LED to send and received signals from an infrared remote control. Next time, we will try to combine the infrared sensor, the temperature sensor, the light sensor, and other sensors to make a smart controller for our electronic devices.