Using IR receiver TSOP series IR receivers

The TSOP family of IR receivers comes in different varieties, mainly based on the IR frequency that they can detect. Two of the most commonly used IR receivers are TSOP1738 and TSOP1838; both are sensitive to 38 KHz. They have all of the required internal circuitry to receive IR signals of 38 KHz. In this section, we will use an ordinary universal remote control and receive its transmitted signals using the TSOP1738 and TSOP1838.

Figure 7: TSOP1738/TSOP1838 pinout

The TSOP IR receivers shown in the preceding figure typically have a protruding front face. This protruding face of the IR receiver should be free of any obstruction so that it can receive the IR signals. Typically, the TSOP1738 comes without a metal casing, whereas the TSOP1838 models usually ship with a metallic casing.

The TSOP IR receivers shown in the preceding figure have three legs (from left to right when the protruding face is towards us):

  • Out: This is the output pin of the IR receiver. This pin is connected to a microcontroller unit. The IR receiver sends the decoded IR signal through this pin. In our case, this pin will be connected to the Arduino board. Our Arduino sketch will read the decoded IR signal from this pin.
  • GND: This pin will be connected to the ground pin of the Arduino board.
  • 5V: this pin will be connected to the 5 volt power supply pin of the Arduino.

The parts required for building the IR receiver prototype are listed as follows:

  • One consumer remote control set (a normal TV remote can be used)
  • One Arduino Uno R3
  • One USB A to USB B cable
  • One TSOP1738 IR receiver (you can substitute with TSOP1838 also)
  • One piece 1K Ohms resistor
  • Some male-to-male jumper wires

Once all the mentioned preceding parts have been assembled, go ahead and build the circuit shown in the following breadboard diagram:

Figure 8: IR receiver using TSOP1738 or TSOP1838

In the preceding diagram, the IR receiver's protruding face should face towards you in the circuit setup. TSOP1738 has been used in the preceding setup. However, we can simply substitute it with TSOP1838, without any change in connections.

The accompanying sketch for the IR receiver setup is provided below for reference. It is based on the sketch using the Arduino Infrared library written by Ken Shirriff. A similar sketch is available in the public domain:

Figure 9: Load IR receiver sketch shipped with Ken Shirriff library

The sketch used in this example can be loaded by simply navigating to the Arduino IDE menu File|Examples|IRRemote|IRRecvDemo (as depicted in the preceding figure). For our understanding, the above sketch has been slightly modified with some additional comments. All credits go to Ken Shirriff for the original code. You can download the sketch from the online location mentioned in Chapter 1, Boot Camp, of this book also:

// This sketch has been modified based on the original sketch 
// written by Ken Shirriff
//**********************************************************/
// Step-1: CONFIGURE VARIABLES
//**********************************************************/
#include <IRremote.h>
int RECV_PIN = 11; // Specify the pin to read the
// input from the IR Receiver OUT pin
IRrecv irrecv(RECV_PIN); // Define the object for the
// IR receiver
decode_results results; // Define an object to store results

//**********************************************************/
// Step-2: INITIALIZE I/O PARAMETERS
//**********************************************************/
void setup()
{
Serial.begin(9600); // Start serial communications
irrecv.enableIRIn(); // Start the receiver
Serial.println("Receiver Started...");
}

//**********************************************************/
// Step-3: MAIN PROGRAM
//**********************************************************/
void loop()
{
if (irrecv.decode(&results))
{
Serial.println(results.value, HEX);
irrecv.resume(); // Receive the next value
}
}

Now let us quickly understand the above sketch. To start with, we are using the IR library written by Ken Shirriff:

#include <IRremote.h> 

All the necessary functions to manage IR communications are already coded in the above library. The next step is to specify the Arduino pin that will read the decoded IR signals from the IR receiver's OUT pin and configure the variables for the IR receiver object:

int RECV_PIN = 11;        // Specify the pin to read the 
// input from the IR Receiver OUT pin
IRrecv irrecv(RECV_PIN); // Define the object for the
// IR receiver

In the setup() function, you will notice that the IR receiver software has been started by calling the appropriate function:

irrecv.enableIRIn();       // Start the receiver 

After the receiver object has been setup, the loop() function keeps sampling for incoming IR signals. As soon as an IR signal is received, the value of the decoded signal is stored in the results variable:

if (irrecv.decode(&results)) 

Thereafter, the value is printed to the Serial Monitor window. In the following line of code, we are printing the hexadecimal value corresponding to the decoded IR signal. It is worthwhile to note that we can also print the values of the decoded IR signals in other formats such as decimal, if needed.

Serial.println(results.value, HEX); 

After printing the value, the program immediately resumes listening to the next incoming IR signal from the IR receiver's OUT pin using the following statement:

irrecv.resume(); // Receive the next value 

Thus, the sketch keeps running. Load the sketch onto your Arduino board and launch the Serial Monitor window:

Figure 10: Reading the IR codes from a TV remote

Point a remote control at the IR receiver and press any button. As soon as any button is pressed, the corresponding IR signal code will get displayed on the screen. The above Serial Monitor window displays IR signal codes from a Panasonic TV remote. You can try this with multiple brands of remote controls.

Based on the above results captured in the Serial Monitor window, it seems the IR signal HEX codes for increasing the TV volume are:

  • E244
  • FFFFFFFF
  • FFFFFFFF

Whereas the IR signal HEX codes for decreasing the TV volume are:

  • E254
  • FFFFFFFF
  • FFFFFFFF

Later in this chapter, we will learn how to send these codes and control the TV unit using an Arduino board and an IR transmitter LED.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.129.247.196