IR Remote Module

Last updated 12 days ago

This documentation includes hardware info, installation guidelines and sample code for your hardware.

Overall Info

Turta IR Remote Module carries 38kHz IR Receiver, and an IR Transmitter LED. You can control TVs, air conditioners or any compatible devices with this module. With the onboard IR Receiver your software can learn IR signals from a remote controller, or you can send commands to your software with a remote controller.

Illustration

Top
Bottom

Module Connections

  • IR Transmitter LED: PWM.

  • IR Receiver Output: INT.

  • Power: +3.3V, GND.

Specifications

IR Remote Module's technical specifications are as follows:

  • IR Receiver Model: Vishay TSOP75338W.

  • IR Receiver Frequency: 38kHz.

  • IR Transmitter LED Model: Vishay VSMB10940X01.

  • IR Transmitter LED Peak Wavelength: 940nm.

  • IR Transmitter LED Radiant Power: 35mW.

  • IR Transmitter LED Rise and Fall Times: 15ns.

Prerequisites

To get maximum performance from your hardware, please make sure you'll meet the following requirements.

Hardware

IR Remote Module is an add-in board for Turta Modular System. You'll need a compatible host device for your module. The following devices support IR Remote Module:

  • Turta IoT Node - ESP32

Software

For ESP32 based systems, we're currently supporting Arduino core. Please make sure you've installed the following:

  • Arduino IDE.

  • ESP32 Hardware libraries for the Arduino IDE.

  • Python for the compilation of Arduino projects.

  • Drivers for your host device, e.g., USB Virtual Serial Port driver.

Installation

You'll need to install a library to make Arduino IDE support the module. This library includes drivers for the transceiver and sample code for you to jumpstart your project.

Libraries

Please download the library archive from https://github.com/Turta-io/Modular

Then, copy its contents to your Arduino Libraries folder.

You can find the Arduino Libraries folder inside your Arduino sketch directory. It is generally located inside the My Documents folder.

Samples

The library comes with included samples. There is no need to download additional files for the examples.

Source Code

The hardware, its drivers and the sample code are open source. You can use them under the terms of the MIT license. Please feel free to customize and prototype them for your projects.

Arduino Library

Turta_IRRemote_Module library is responsible for encoding and decoding IR remote signals.

To use the library on Arduino IDE, add the following #include statement to the top of your sketch.

#include <Turta_IRRemote_Module.h>

Then, create an instance of the Turta_IRRemote_Module class.

Turta_IRRemote_Module ir

Now you're ready to access the library by calling the ir instance.

Initialization

To initialize the module, call the begin method.

begin()

This method configures the PWM and INT pins for IR communication.

Basic Members

Set Reception

Configures the driver to listen for incoming IR signals.

void setReception(bool enabled)
  • Parameters

    • Bool: enabled

  • Returns

    • None

Send NEC Command

Sends 4 Bytes long NEC protocol message.

void sendNECCommand(byte d0, byte d1, byte d2, byte d3)
  • Parameters

    • Byte: d0

    • Byte: d1

    • Byte: d2

    • Byte: d3

  • Returns

    • None

Check If Message Received

Returns true if any message is received and ready to be read.

bool isMessageReceived()
  • Parameters

    • None

  • Returns

    • Bool: Message Received State

Get Data

Reads NEC protocol IR message from the driver buffer.

void getData(byte d0, byte d1, byte d2, byte d3)
  • Parameters

    • Byte: d0 out

    • Byte: d1 out

    • Byte: d2 out

    • Byte: d3 out

  • Returns

    • None

Examples

You can open the example from Arduino IDE > File > Examples > Examples from Custom Libraries > Turta IRRemote Module. There are two examples of this sensor.

Remote Rx

This application demonstrates decoding NEC protocol IR messages and prints decoded messages to Arduino IDE's Serial Monitor.

To run the example:

  1. Open the IoT_Node_IRRemote_Rx sketch from the examples menu.

  2. Select Turta IoT Node from the Tools > Board menu.

  3. Select your device's COM port from Tools > Port menu.

  4. Open Serial Monitor from Tools > Serial Monitor.

  5. Select 115.200 baud from the Serial Monitor's status bar.

  6. Upload the code to your device.

Sample Code

IoT_Node_IRRemote_Rx.ino
#include <Turta_IRRemote_Module.h>
#define LED 13
// Create IR Remote Module instance.
Turta_IRRemote_Module ir;
void setup() {
// Initialize onboard LED.
pinMode(LED, OUTPUT);
// Initialize IR Remote Module.
ir.begin();
ir.setReception(true);
// Configure serial port.
Serial.begin(115200);
delay(200);
}
void loop() {
if (ir.isMessageReceived()) {
digitalWrite(LED, HIGH);
byte dt[4] = {0};
ir.getData(dt[0], dt[1], dt[2], dt[3]);
Serial.print(dt[0]);
Serial.print(" ");
Serial.print(dt[1]);
Serial.print(" ");
Serial.print(dt[2]);
Serial.print(" ");
Serial.println(dt[3]);
digitalWrite(LED, LOW);
}
// Delay 10ms.
delay(10);
}

Result

After the application is uploaded to the device, it listens for the NEC protocol IR messages. When a message is decoded, the application prints it "to the Serial Monitor, and blinks the onboard LED. The example output should be like this:

0x20 0x21 0x22 0x23

The application runs forever until you clear it from memory.IoT Node IRRemote Tx

This application demonstrates sending NEC protocol IR messages.

To run the example:

  1. Open the IoT_Node_IRRemote_Tx sketch from the examples menu.

  2. Select Turta IoT Node from the Tools > Board menu.

  3. Select your device's COM port from Tools > Port menu.

  4. Open Serial Monitor from Tools > Serial Monitor.

  5. Select 115.200 baud from the Serial Monitor's status bar.

  6. Upload the code to your device.

Sample Code

IoT_Node_IRRemote_Tx.ino
#include <Turta_IRRemote_Module.h>
#define LED 13
// Create IR Remote Module instance.
Turta_IRRemote_Module ir;
void setup() {
// Initialize onboard LED.
pinMode(LED, OUTPUT);
// Initialize IR Remote Module.
ir.begin();
ir.setReception(false);
// Configure serial port.
Serial.begin(115200);
delay(200);
}
void loop() {
digitalWrite(LED, HIGH);
ir.sendNECCommand(1, 2, 3, 252);
digitalWrite(LED, LOW);
// Delay 10000ms = 10 seconds.
delay(10000);
}

Result

After the application is uploaded to the device, it sends IR messages every 10 seconds and blinks the onboard LED while sending the message.

The application runs forever until you clear it from memory.

Troubleshooting

If you're experiencing difficulties while working with your device, please try the following steps.

Problem: The IR Module does not recognize NEC protocol messages. Cause: To capture IR messages, the software decoder should be activated. Solution: Please call setReception(true) method to activate software decoder.