5mm IR Transmitter Receiver Pair Documentation
The 5mm IR Transmitter Receiver Pair is a popular module used in various IoT projects, robotics, and remote control systems. This module consists of an infrared transmitter (IR TX) and an infrared receiver (IR RX), which allow for wireless communication between devices using infrared light.
IR Transmitter (TX):
+ Wavelength: 940nm
+ Angle: 30
+ Power consumption: 20mA
IR Receiver (RX):
+ Wavelength: 940nm
+ Sensitivity: 15mV
+ Power consumption: 5mA
Operating voltage: 3.3V - 5.5V
Communication distance: up to 10 meters
### Example 1: Basic IR Communication using Arduino
In this example, we'll demonstrate how to use the 5mm IR Transmitter Receiver Pair to send and receive data between two Arduino boards.
Transmitter Code (Arduino)
```c++
const int irTxPin = 3; // define the IR transmitter pin
void setup() {
pinMode(irTxPin, OUTPUT);
}
void loop() {
// Send a simple "Hello, World!" message in IR
for (int i = 0; i < 13; i++) {
digitalWrite(irTxPin, HIGH);
delayMicroseconds(600);
digitalWrite(irTxPin, LOW);
delayMicroseconds(600);
}
delay(1000);
}
```
Receiver Code (Arduino)
```c++
const int irRxPin = 2; // define the IR receiver pin
void setup() {
pinMode(irRxPin, INPUT);
Serial.begin(9600);
}
void loop() {
if (digitalRead(irRxPin) == HIGH) {
// Receive and decode the IR signal
char receivedChar = decodeIRSignal();
Serial.print(receivedChar);
}
delay(50);
}
char decodeIRSignal() {
// Implement your own decoding logic or use an existing library
// For simplicity, we'll assume a simple 1-0 encoding scheme
char receivedChar = ' ';
for (int i = 0; i < 8; i++) {
if (digitalRead(irRxPin) == HIGH) {
receivedChar |= (1 << i);
}
}
return receivedChar;
}
```
### Example 2: IR Remote Control using Raspberry Pi (Python)
In this example, we'll demonstrate how to use the 5mm IR Transmitter Receiver Pair to send and receive IR commands using a Raspberry Pi.
Transmitter Code (Python)
```python
import RPi.GPIO as GPIO
import time
# Set up the IR transmitter pin
GPIO.setmode(GPIO.BCM)
irTxPin = 17
GPIO.setup(irTxPin, GPIO.OUT)
def send_IR_command(command):
# Send the IR command using a 38kHz carrier frequency
for i in range(command.bit_length()):
if command & (1 << i):
GPIO.output(irTxPin, GPIO.HIGH)
time.sleep(0.0000125) # 12.5us high
GPIO.output(irTxPin, GPIO.LOW)
time.sleep(0.0000125) # 12.5us low
else:
GPIO.output(irTxPin, GPIO.LOW)
time.sleep(0.000025) # 25us low
# Send a sample IR command
send_IR_command(0x12345678)
```
### Example 3: IR Obstacle Detection using ESP32 (C++)
In this example, we'll demonstrate how to use the 5mm IR Transmitter Receiver Pair to detect obstacles using an ESP32 board.
Obstacle Detection Code (C++)
```c++
#include <WiFi.h>
const int irTxPin = 18; // define the IR transmitter pin
const int irRxPin = 19; // define the IR receiver pin
void setup() {
pinMode(irTxPin, OUTPUT);
pinMode(irRxPin, INPUT);
}
void loop() {
// Send an IR pulse
digitalWrite(irTxPin, HIGH);
delayMicroseconds(600);
digitalWrite(irTxPin, LOW);
delayMicroseconds(600);
// Check if the IR signal is reflected back
if (digitalRead(irRxPin) == HIGH) {
// Obstacle detected!
Serial.println("Obstacle detected!");
} else {
Serial.println("No obstacle detected.");
}
delay(50);
}
```
Note: These code examples are for demonstration purposes only and may require modifications to work with your specific project requirements.