Using Arduino with Parts and Sensors – Infrared Remote Control (First Part)

Using Arduino with Parts and Sensors – Infrared Remote Control (First Part)

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.

Today’s Electronic Recipe

Expected time to complete: 90 minutes

Parts needed:

  • Arduino (Arduino Mini Pro) https://www.adafruit.com/products/2378
  • Breadboard https://www.adafruit.com/products/64
  • 5mm infrared LED OSI5LA5113A http://www.tme.eu/en/details/osi5la5113a/transmitting-and-receiving-ir-elements/optosupply/
  • CDS sensor (light sensor) http://wholesaler.alibaba.com/product-detail/Photoresistor-LDR-CDS-5mm-Light-Dependent_60255303495/showimage.html
  • Tact switch http://www.rapidonline.com/electronic-components/diptronics-dts-62n-tactile-switch-6-x-6mm-height-5mm-78-0621
  • Resistor (220Ω)

    What are Infrared Rays?

    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.

    23_01
    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.

    f864a09fae7df36ad384492abd392c391
    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.

    Typical formats

    • NEC format
    • Home Appliance Cooperation format
    • SONY format

    382f90b5faebff216ad2c328bc4bf3191Figure 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.

    P1190247
    Picture 1 Infrared receiver module

    P1190250
    Picture 2 Infrared LED

    The figure below shows the circuit to connect the infrared receiver module to Arduino.

    1151c1f36b5d43dfe57a0b3df9395e902-1024x451
    Figure 4 Infrared circuit

    P1190242-e1431400985470 (1)
    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.

    shirriff / Arduino-IRremote
    https://github.com/shirriff/Arduino-IRremote

    ee636fb40444ec960d5065834360b629-e1431401026822
    Figure 5 Download the library

    4eeb386d0ffbd8d19d7d4d2f2dc91928
    Picture 6 Adding the library

    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

    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.

    9d0fa55fb2923db858e37779ff101620-e1431401173602
    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.

    12bee60e66e26b3ab8ba511be3cad6ff
    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

    2555407a3aaf02a3cfdae941faa52e701-1024x483
    Figure 9 Infrared remote control circuit

    034fc1598df828f8d494d9562d24d06d
    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!

    Summary

    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.