Wall's Corners Wall's Corners Author
Title: Using Arduino with Parts and Sensors Infrared Remote Control (First Part)
Author: Wall's Corners
Rating 5 of 5 Des:
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 infra...

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) http://ift.tt/1zFuYR3
  • Breadboard http://ift.tt/1z7Tzip
  • 5mm infrared LED OSI5LA5113A http://ift.tt/1r3ihhI
  • CDS sensor (light sensor) http://ift.tt/1XLTCbZ
  • Tact switch http://ift.tt/1r3ijpV
  • 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
    http://ift.tt/P0Xp3d

    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

    Code-Example
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    /*
    * 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)
    */
     
    #include <IRremote.h>
     
    int RECV_PIN = 11;
     
    IRrecv irrecv(RECV_PIN);
     
    decode_results results;
     
    void setup()
    {
    Serial.begin(9600);
    irrecv.enableIRIn(); // Start the receiver
    }
     
    // Dumps out the decode_results structure.
    // Call this after IRrecv::decode()
    // void * to work around compiler issue
    //void dump(void *v) {
    // decode_results *results = (decode_results *)v
    void dump(decode_results *results) {
    int count = results->rawlen;
    if (results->decode_type == UNKNOWN) {
    Serial.print("Unknown encoding: ");
    }
    else if (results->decode_type == NEC) {
    Serial.print("Decoded NEC: ");
    }
    else if (results->decode_type == SONY) {
    Serial.print("Decoded SONY: ");
    }
    else if (results->decode_type == RC5) {
    Serial.print("Decoded RC5: ");
    }
    else if (results->decode_type == RC6) {
    Serial.print("Decoded RC6: ");
    }
    else if (results->decode_type == PANASONIC) {
    Serial.print("Decoded PANASONIC - Address: ");
    Serial.print(results->panasonicAddress,HEX);
    Serial.print(" Value: ");
    }
    else if (results->decode_type == LG) {
    Serial.print("Decoded LG: ");
    }
    else if (results->decode_type == JVC) {
    Serial.print("Decoded JVC: ");
     
    }
    else if (results->decode_type == AIWA_RC_T501) {
    Serial.print("Decoded AIWA RC T501: ");
    }
    else if (results->decode_type == WHYNTER) {
    Serial.print("Decoded Whynter: ");
    }
    Serial.print(results->value, HEX);
    Serial.print(" (");
    Serial.print(results->bits, DEC);
    Serial.println(" bits)");
    Serial.print("Raw (");
    Serial.print(count, DEC);
    Serial.print("): ");
     
    for (int i = 0; i < count; i++) {
    if ((i % 2) == 1) {
    Serial.print(results->rawbuf[i]*USECPERTICK, DEC);
    }
    else {
    Serial.print(-(int)results->rawbuf[i]*USECPERTICK, DEC);
    }
    Serial.print(" ");
    }
    Serial.println("");
    }
     
    void loop() {
    if (irrecv.decode(&results)) {
    Serial.println(results.value, HEX);
    dump(&results);
    irrecv.resume(); // Receive the next value
    }
    }

    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

    Code-Example
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    #include <IRremote.h>
    IRsend irsend;
    int sensorPin = A0;
    void setup()
    {
    Serial.begin(9600);
    }
     
    void loop() {
    int sensorValue = analogRead(sensorPin);
    //Serial.println(sensorValue);
    if(sensorValue == 0){
    for (int i = 0; i < 3; i++) {
    irsend.sendSony(0xa90, 12); // Sony Signal of TV power ON in the format
    delay(40);
    }
    }
    }

    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.

Share This:

View more at: http://yoursmart.mobi

About Author

Advertisement

Post a Comment

 
Top