top of page

IR Communication using Arduino UNO

Updated: Mar 2

Overview of IR LEDs, IR Photodiodes, and TSOP1738




IR communication makes use of IR (Infrared) waves from the electromagnetic spectrum.


An IR LED is used to transmit data wirelessly in digital form (0 – LED OFF or 1 – LED ON).


An IR photodiode or IR phototransistor receives this data. The IR receiver (IR photodiode or IR phototransistor) gives different current values according to the intensity of light.


It is possible to modulate the data transmitted and there are special decoder IR receivers like TSOP1738 available that can receive the modulated data.


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

 

Connection Diagram for IR Communication using Photodiode and  Arduino



 

Note : In the diagram shown above, for the IR LED as well as IR photodiode, the longer lead is the Anode and the shorter lead is the Cathode.

Also, the Photodiode is used in the reverse biased mode (It is designed to operate in the reverse biased mode).

 

Connection Diagram for IR Communication using TSOP1738 and Arduino


 

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

The data from transmitter side is modulated at 38 kHz before transmission.


The TSOP1738 is an IR Receiver with the capability to demodulate signals that have been modulated at a frequency of 38 kHz.


Any other TSOP17xx receiver like the TSOP1730 can also be used instead of TSOP1738. The only difference is the carrier frequency that it can demodulate. For example, TSOP1730 can demodulate signals that have carrier frequency 30 kHz. Corresponding changes in the modulation scheme need to be made at the transmitter side if TSOP1730 or some other receiver is used.

 

Example


Wireless IR communication between two Arduino Uno boards.

 

Here, a simple count is transmitted from the transmitter using IR LED. This count is received at the receiver by an IR photodiode or a TSOP1738. The count is transmitted as it is when the receiver is using IR photodiode. The count is modulated at 38 kHz when the receiver is using TSOP1738.

 

Note : IR is used just as a medium of data transmission between the transmitter and receiver. Data is being sent using USART protocol.

 

Word of Caution : In these example sketches, the Rx and Tx serial communication pins are being used. Arduino uses these pins while programming. Hence, we need to make sure that there is no external circuitry connected to the Rx and Tx pins while uploading the sketch. Failing to do this may result in error messages popping up while uploading the sketch. Once the sketch is uploaded, we can connect the externals circuitry 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 */
  }
}

 


1 view0 comments

コメント


bottom of page