TSOP1738 Arduino Tutorial IR Sensor Control RGB LED

Posted on

IR Remote TSOP 1738 Arduino

Tutorial TSOP1738 Arduino Infrared Remote For Control LED – IR Remote is a short-range wireless communication that is very widely used. Apart from its low price, this remote IR protocol is excellent.

To be able to read incoming infrared data, we must know the protocol used. Protocol is like the language of communication used.

There are 4 IR Remote Protocols that are most commonly used, NEC, SONY, RC5 and RC6. One of the IR receiver is TSOP1738.

TSOP1738 Arduino Tutorial IR Sensor Control RGB LED


TSOP1738 IR Receiver

TSOP1738 is one of the IR receivers manufactured by VISHAY.

This component has a photo detector and preamplifier in one package, so it can be used directly on a microprocessor or microcontroller.

But in the remote ir application, it takes at least 3 additional components, like resistors (100, 10K) and Capasitor (4.7uF).

Features

  • Photo Detector and preamplifier in one package.
  • Internal filtering for PCM frequencies
  • Increased protection against electric field interference
  • TTL and CMOS compatibility
  • Active output low
  • Low power consumption
  • High immunity to ambient light
  • Continuous data transmission possible (up to 2400 bps)
  • Appropriate burst length ≥10 cycles / burst

Maximum Rating:

  • Supply Voltage up to 6V
  • Supply Current up to 5mA
  • Output Voltage up to 6V
  • Junction temperature 100 degrees C
  • Storage temperature up to +85 degrees C
  • Operating temperature up to +85 degrees C
  • Power up to 50mW
  • Soldering temperature up to 260 degrees C

Schematic

To be able to communicate between TSOP1738 and Arduino, connect them like the circuit below.

TSOP1738 Arduino Tutorial IR Sensor Control RGB LED

If you are a beginner and feel unfamiliar with the above schematic, you can try the ir receiver module which has been sold in the market.

TSOP1738 Arduino Library

Now, please download the library for Arduino IDE. This library will make it easier for us to convert the signal received by the photo detector into Hexadecimal data.

Download Library IRremote

After that, include the library that has been downloaded by:

  • Open the Arduino IDE
  • Click Sketch -> Include Library -> add .ZIP library
  • Navigate and select the library that you have downloaded
  • Click OK

In this library, there are basic commands that are very useful in implementing code. Here are the basic command.

Commands For Receiver:

  • IRrecv irrecv(receivePin)Create a recipient object, using a name of your choice.
  • irrecv.enableIRIn()Start the admissions process. This will activate a timer interrupt which consumes a small amount of CPU every 50 µs.
  • irrecv.decode(&results)Attempting to receive an IR code. Returns true if codes were received, or false if none were received. When the code is received, the information is stored in the “results”.results.decode_type: Will be one of the following: NEC, SONY, RC5, RC6, or UNKNOWN.results.value: Actual IR code (0 if type UNKNOWN)results.bits: The number of bits used by this coderesults.rawbuf: an array of IR pulse timingresults.rawlen: The number of items stored in the array
  • irrecv.resume()After receiving, it must be called to reset the receiver and prepare it to receive another code.
  • irrecv.blink13(true)Activate LED blinking during reception. Since you can’t see infrared light, flashing the LED can be useful when troubleshooting a problem, or just to provide visual feedback.

Command For Transmitter:

  • IRsend irsend;Create a transmission object. A fixed pin number is always used, depending on which timer the library is using.
  • irsend.sendNEC(IRcode, numBits);
    Send code in NEC format.
  • irsend.sendSony(IRcode, numBits);
    Send code in SONY format.
  • irsend.sendRC5(IRcode, numBits);
    Send code in RC5 format.
  • irsend.sendRC6(IRcode, numBits);
    Send code in RC6 format.
  • irsend.sendRaw(rawbuf, rawlen, frequency);
    Send raw code. Usually you will get rawbuf and rawlen content by using the receiver many times and averaging the results.

    Several adjustments may be required for best performance. Frequency is the expected bandpass filter frequency at the receiver, of which 38 is the most commonly used


TSOP1738 Program Code

Basic Program Receiving IR Remote Data

Okay … now that we’ve loaded the library, we’ll look at the basic program of receiving data. Here is the basic program. Please upload to Arduino.

#include <IRremote.h>
const int RECV_PIN = 2; 
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup()
{
Serial.begin(9600);
irrecv.enableIRIn();
}
void loop() {
if (irrecv.decode(&results)) {

Serial.println(results.value, HEX);
irrecv.resume();
}
}

After the upload is complete, open the Arduino IDE monitor serial. Make sure the baudrate is selected at 9600 (bottom right of the monitor serial).

Now press one of the remotes buttons. Then the serial monitor will display the address with a Hexadecimal value.

See the IR Remote Protocol Type

Now, we will try to see the protocol used by your remote. As explained above, there are 4 remote IR protocols used, namely NEC, SONY, RC5 and RC6.

The program below will read the protocol type on the remote you are using, then it will be displayed on the serial monitor. Please upload the following program.

#include <IRremote.h>
const int RECV_PIN = 2;
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup()
{
Serial.begin(9600);
irrecv.enableIRIn();
irrecv.blink13(true); 
}
void loop() {
if (irrecv.decode(&results)) {
if (results.decode_type == NEC) {
Serial.print("Protocol NEC: ");
} else if (results.decode_type == SONY) {
Serial.print("Protocol SONY: ");
} else if (results.decode_type == RC5) {
Serial.print("Protocol RC5: ");
} else if (results.decode_type == RC6) {
Serial.print("Protocol RC6: ");
} else if (results.decode_type == UNKNOWN) {
Serial.print("Protocol not known: ");
}
Serial.println(results.value, HEX);
irrecv.resume();
}
}

After the upload is complete, please press the button on the remote and point it to TSOP1738. You will see the type of protocol you are using on the serial monitor.

Turning on the RGB LED Using the Remote

After you understand the two programs above, we will try to turn on the 3 LEDs using the remote.

To turn on 3 Red Green and Blue LEDs we need three buttons. Let’s say we have defined 3 hex addresses for the remote:

  • 0xFF30CF hex data for red color
  • 0xFF18E7 hex data for green color
  • 0xFF7A85 hex data for blue color

For the circuit, please connect the:

  • Red LED to pin 12
  • Green LED to pin 11
  • Blue LED to pin 10.

Don’t forget to use a 330R resistor. Please upload the following program on your Arduino. Please press the button 1, 2, or 3 of your remote.

#include <IRremote.h>
const int RECV_PIN = 2; 
int ledRed = 12;
int ledGreen = 11;
int ledBlue = 10;
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup()
{
Serial.begin(9600);
irrecv.enableIRIn();
irrecv.blink13(true); 
pinMode(ledRed, OUTPUT);
pinMode(ledGreen, OUTPUT); 
pinMode(ledBlue, OUTPUT);
}
void loop() {
//Data hex 0xFF30CF for RED
//Data hex 0xFF18E7 for GREEN
//Data hex 0xFF7A85 for BLUE
 
if (irrecv.decode(&results)) {
Serial.println(results.value, HEX);
if (results.value == 0xFF30CF)
{
digitalWrite(ledRed, HIGH);
digitalWrite(ledGreen, LOW);
digitalWrite(ledBlue, LOW);
}
if (results.value == 0xFF18E7)
{
digitalWrite(ledRed, LOW);
digitalWrite(ledGreen, HIGH);
digitalWrite(ledBlue, LOW);
}
if (results.value == 0xFF7A85)
{
digitalWrite(ledRed, LOW);
digitalWrite(ledGreen, LOW);
digitalWrite(ledBlue, HIGH);
}
 
irrecv.resume(); 
}
}




TSOP1738 Datasheet

For more information about TSOP1738, you can see the TSOP1738 datasheet below.



Apart from TSOP1738, there is a component that is now widely used, namely VS1838B. You can read How to Use the TL1838 IR Remote.

Thank you for visiting the Piko Chip website. Hope this TSOP1738 Arduino is useful.

Read more…
> DHT11 Sensor Arduino Uno Code & Wiring
> Ultrasonic HC-SR04 Arduino Distance Sensor
> IR Remote Sensor 1838B Arduino Tutorial
> TTP223 Capacitive Touch Sensor Switch
> AMG8833 Arduino Buzzer Notification at Specific Temperature
> HC SR501 Arduino PIR  Basic Tutorial
> How to Find I2C Address Using Arduino