Pantech.AI

How to Interface IR Communication using Arduino UNO

Overview of IR LEDs, IR Photodiodes, and TSOP1738

IR LEDs, IR Photodiodes, and TSOP1738

IR communication utilizes infrared (IR) waves from the electromagnetic spectrum.

An IR LED is used to transmit data wirelessly in digital form, where 0 represents the LED being OFF and 1 represents the LED being ON.

The data is received by an IR photodiode or IR phototransistor. These IR receivers produce different current values based on the intensity of the incoming light.

Data transmission can be modulated, and special decoder IR receivers, such as the TSOP1738, are available to receive modulated signals.

For more information on IR communication, refer to the IR Communication topic in the sensors and modules section.

Connection Diagram for IR Communication using Photodiode and  Arduino

IR Communication Between IR LED And TSOP1738 IR Receiver using Arduino

Note: In the diagram above, the longer lead of the IR LED is the Anode, and the shorter lead is the Cathode.

The data from the transmitter is modulated at a frequency of 38 kHz before transmission.

The TSOP1738 is an IR receiver capable of demodulating signals modulated at 38 kHz.

Other TSOP17xx series receivers, such as the TSOP1730, can also be used in place of the TSOP1738. The main difference lies in the carrier frequency they can demodulate. For example, the TSOP1730 can demodulate signals with a carrier frequency of 30 kHz. If using the TSOP1730 or another receiver, the modulation scheme at the transmitter must be adjusted accordingly.

Example

Wireless IR communication between two Arduino Uno boards can be set up as follows:

In this setup, a simple count is transmitted from the transmitter using an IR LED. The receiver, which uses either an IR photodiode or a TSOP1738, receives the count. If an IR photodiode is used, the count is transmitted as-is. If a TSOP1738 is used, the count is modulated at 38 kHz.

Note: IR is simply used as a medium for data transmission between the transmitter and receiver. The data is actually sent using the USART protocol.

Word of Caution: In these example sketches, the Rx and Tx serial communication pins are used. Arduino uses these pins for programming, so make sure no external circuitry is connected to the Rx and Tx pins while uploading the sketch. Failing to do this may cause error messages during the upload. Once the sketch is uploaded, external circuitry can be connected to the Rx and Tx pins.

Code for IR Communication between IR LED And IR Photodiode Using Arduino Uno

Sketch for Transmitter

void setup() {
  Serial.begin(9600);	/* Define baud rate for serial communication */
}

void loop() {
  int count;
  for(count = 0; count<100; count++)
  {
    Serial.println(count);
    delay(1000);
  }
}

Sketch For Receiver

void setup() {
  Serial.begin(9600);	/* Define baud rate for serial communication */
}

void loop() {
if(Serial.available())	/* If data is available on serial port */
  {
    Serial.print(char(Serial.read()));	/* Print character received on to the serial monitor */
  }
}

Code for IR Communication between IR LED And TSOP1738 using Arduino Uno

Sketch For Transmitter

#define cr_pin 9

void setup() {
  Serial.begin(1200);	/* Define baud rate for serial communication */
  tone(cr_pin, 38000);	/* For modulation at 38kHz */
}

void loop() {
  int count;
  for(count = 0; count<100; count++)
  {
    Serial.println(count);
    delay(1000);
  }
}

Sketch For Receiver

void setup() {
  Serial.begin(1200);	/* Define baud rate for serial communication */
}

void loop() {
if(Serial.available())	/* If data is available on serial port */
  {
    Serial.print(char(Serial.read()));	/* Print character received on to the serial monitor */
  }
}

Leave a Comment

Your email address will not be published. Required fields are marked *