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
- TSOP38238 IR Receiver Diode (38kHz)
- Arduino Uno R3
- Small LEDs for five colors (Red, Green, Blue, White, Yellow)
- 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.
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.
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 | |
3 | IRrecv irrecv(9); |
4 | |
5 | decode_results results; |
6 | |
7 | void setup(){ |
8 | |
9 | Serial.begin(9600); |
10 | |
11 | irrecv.enableIRIn(); |
12 | |
13 | irrecv.blink13(true); |
14 | |
15 | } |
16 | |
17 | void loop(){ |
18 | |
19 | if (irrecv.decode(&results)){ |
20 | |
21 | //Serial.print(results.value, DEC); |
22 | |
23 | //Serial.print(” “); |
24 | |
25 | Serial.println(results.value, HEX); |
26 | |
27 | irrecv.resume(); |
28 | |
29 | } |
30 | |
31 | delay(100); |
32 | |
33 | } |
The below Image of the Serial monitor shows the codes of each particular button on the IR Remote.
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> |
2 | IRrecv irrecv(9); |
3 | decode_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 |
9 | byte LedState = LOW; |
10 | void setup(){ |
11 | Serial.begin(9600); |
12 | irrecv.enableIRIn(); |
13 | irrecv.blink13(true); |
14 | pinMode(RED_LED_PIN, OUTPUT); |
15 | pinMode(GREEN_LED_PIN, OUTPUT); |
16 | pinMode(BLUE_LED_PIN, OUTPUT); |
17 | pinMode(WHITE_LED_PIN, OUTPUT); |
18 | pinMode(YELLOW_LED_PIN, OUTPUT); |
19 | } |
20 | void loop() |
21 | { if (irrecv.decode(&results)) |
22 | { switch(results.value) |
23 | { case 0xF720DF: |
24 | LedState = (LedState == LOW) ? HIGH : LOW; |
25 | digitalWrite(RED_LED_PIN, LedState); |
26 | break; |
27 | case 0xF7A05F: |
28 | LedState = (LedState == LOW) ? HIGH : LOW; |
29 | digitalWrite(GREEN_LED_PIN, LedState); |
30 | break; |
31 | case 0xF7609F: |
32 | LedState = (LedState == LOW) ? HIGH : LOW; |
33 | digitalWrite(BLUE_LED_PIN, LedState); |
34 | break; |
35 | case 0xF7E01F: |
36 | LedState = (LedState == LOW) ? HIGH : LOW; |
37 | digitalWrite(WHITE_LED_PIN, LedState); |
38 | break; |
39 | case 0xF728D7: |
40 | LedState = (LedState == LOW) ? HIGH : LOW; |
41 | digitalWrite(YELLOW_LED_PIN, LedState); |
42 | break ; |
43 | case 0xF7C03F: //All lights turned ON |
44 | digitalWrite(RED_LED_PIN, HIGH); |
45 | digitalWrite(GREEN_LED_PIN, HIGH); |
46 | digitalWrite(BLUE_LED_PIN, HIGH); |
47 | digitalWrite(WHITE_LED_PIN, HIGH); |
48 | digitalWrite(YELLOW_LED_PIN, HIGH); |
49 | break ; |
50 | case 0xF740BF: //All lights turned OFF |
51 | digitalWrite(RED_LED_PIN, LOW); |
52 | digitalWrite(GREEN_LED_PIN, LOW); |
53 | digitalWrite(BLUE_LED_PIN, LOW); |
54 | digitalWrite(WHITE_LED_PIN, LOW); |
55 | digitalWrite(YELLOW_LED_PIN, LOW); |
56 | break ; |
57 | } |
58 | irrecv.resume(); |
59 | } |
60 | delay(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.