Roboelectrixx

How to Interface TSOP38238 IR Receiver with Arduino

The TSOP38238 is a generic infrared (IR) receiver diode commonly use inside IR remotes to capture the IR signals and decode them into digital signals. This receiver diode is capable of capturing IR signals sent by remotes operating at a frequency of 38kHz. Many commonly used remotes in India, such as those for TVs and air conditioners (ACs), work at this frequency. The diode uses very low energy due to its design and is capable to filter out unwanted signals from sources like incandescent, halogen, fluorescent lights, and sunlight, ensuring reliable signal reception.

TSOP38238 IR Receiver Specifications

  • Supply Voltage Range: 2.5 V to 5.5 V
  • Required Low Power to operate about 3mA current.
  • Package supports Carrier Frequency 38KHz.
  • Photodetector, Internal Filter, and preamplifier are included in a single package.
  • Output voltage is -0.3 to (VS + 0.3) V.
  • Output current is 5 mA.

TSOP38238

The sensor comes with three pins for interfacing with the microcontroller boards which include:

  • Vs: Terminal used to provide external power supply pin whose range is 5 V to 5.5 V.
  • GND: It is the center pin that is connected to the ground.
  • OUT: Pin used to output the decoded signal which should be connected to a microcontroller.

Circuit Design for Interfacing TSOP38238 IR Receiver with Arduino

In this project, we will control LEDs using IR Remote by using the combination of the IR receiver and Arduino. Also, we will learn about decoding the IR remote codes.

Components Required

  1. TSOP38238 IR Receiver Diode (38kHz)
  2. Arduino Uno R3
  3. Small LEDs for five colors (Red, Green, Blue, White, Yellow)
  4. IR Remote

Circuit Diagram for Interfacing TSOP38238 IR Receiver with Arduino

For the circuit design, we will use Tinkercad Software. In previous article, we learned How to use TinkerCad to create circuit with Arduino.

Circuit Diagram for Interfacing TSOP38238 IR Receiver with Arduino

IR receiver module connection:

  • Connect the VCC pin to 5V on the Arduino.
  • Connect the GND pin to GND on the Arduino.
  • Connect the OUT pin to a digital pin (e.g., 11) on the Arduino.

LEDs connection:

  • Connect all ground terminals of LEDs to the ground of the Arduino.
  • Connect the +ve terminal of each LED to a digital pin (e.g., 9, 10, 13) on the Arduino through appropriate current-limiting resistors which are optional.
Circuit for Interfacing TSOP38238 IR Receiver with Arduino

Arduino Code for Interfacing TSOP38238 IR Receiver with Arduino

To control LEDs using an IR remote, firstly we need to decode the required buttons on the remote. The Below code will show you the required button Hex codes on the Serial Monitor when you press each button on the remote. Note all the codes, we will be using in the next program.

To successfully run the code, you need to install the IRremote library which you will find under the library manager of IDE.

Arduino Code For IR Extracter CodeCopy Code

1#include <IRremote.h>
2
3IRrecv irrecv(9);
4
5decode_results results;
6
7void setup(){
8
9Serial.begin(9600);
10
11irrecv.enableIRIn();
12
13irrecv.blink13(true);
14
15}
16
17void loop(){
18
19if (irrecv.decode(&results)){
20
21//Serial.print(results.value, DEC);
22
23//Serial.print(” “);
24
25Serial.println(results.value, HEX);
26
27irrecv.resume();
28
29}
30
31delay(100);
32
33}

The below Image of the Serial monitor shows the codes of each particular button on the IR Remote.

Arduino IDE Serial monitor window

Now the below code operates the functioning of the LEDs using the remote buttons including turning ON and Off.

The +ve pin of each Led is connected to the different digital pins of the Arduino. If you are using different pins, change the PIN Inside the code also.

Inside Switch Case, there will be a different Hex code, you have to replace them with your previously noted Hex codes.

Arduino Code For LED Blinking ControlCopy Code

1#include <IRremote.h>
2IRrecv irrecv(9);
3decode_results results;
4#define RED_LED_PIN 6
5#define GREEN_LED_PIN 5
6#define BLUE_LED_PIN 4
7#define WHITE_LED_PIN 3
8#define YELLOW_LED_PIN 2
9byte LedState = LOW;
10void setup(){
11Serial.begin(9600);
12irrecv.enableIRIn();
13irrecv.blink13(true);
14pinMode(RED_LED_PIN, OUTPUT);
15pinMode(GREEN_LED_PIN, OUTPUT);
16pinMode(BLUE_LED_PIN, OUTPUT);
17pinMode(WHITE_LED_PIN, OUTPUT);
18pinMode(YELLOW_LED_PIN, OUTPUT);
19}
20void loop()
21{ if (irrecv.decode(&results))
22{ switch(results.value)
23{ case 0xF720DF:
24LedState = (LedState == LOW) ? HIGH : LOW;
25digitalWrite(RED_LED_PIN, LedState);
26break;
27case 0xF7A05F:
28LedState = (LedState == LOW) ? HIGH : LOW;
29digitalWrite(GREEN_LED_PIN, LedState);
30break;
31case 0xF7609F:
32LedState = (LedState == LOW) ? HIGH : LOW;
33digitalWrite(BLUE_LED_PIN, LedState);
34break;
35case 0xF7E01F:
36LedState = (LedState == LOW) ? HIGH : LOW;
37digitalWrite(WHITE_LED_PIN, LedState);
38break;
39case 0xF728D7:
40LedState = (LedState == LOW) ? HIGH : LOW;
41digitalWrite(YELLOW_LED_PIN, LedState);
42break ;
43case 0xF7C03F: //All lights turned ON
44digitalWrite(RED_LED_PIN, HIGH);
45digitalWrite(GREEN_LED_PIN, HIGH);
46digitalWrite(BLUE_LED_PIN, HIGH);
47digitalWrite(WHITE_LED_PIN, HIGH);
48digitalWrite(YELLOW_LED_PIN, HIGH);
49break ;
50case 0xF740BF: //All lights turned OFF
51digitalWrite(RED_LED_PIN, LOW);
52digitalWrite(GREEN_LED_PIN, LOW);
53digitalWrite(BLUE_LED_PIN, LOW);
54digitalWrite(WHITE_LED_PIN, LOW);
55digitalWrite(YELLOW_LED_PIN, LOW);
56break ;
57}
58irrecv.resume();
59}
60delay(500);
61}

Demonstration of Controlling LEDs using IR Remote

After Successfully uploading the code, press the same buttons on the remote to glow the LEDs. Similarly, using the same button you can turn off them also.

TSOP38238 IR Receiver with Arduino Uno