In this article, we are discussing the overall hardware, code and library we will need. This article is not about building one particular project. Infrared (IR) remote control technology is widely used in day to day used devices. IR remote control signals are a reliable resource to control nearby electrical appliances. With the development of ESP32 like cheaper system on chip and Internet of things (IoT) technology, there is wider chance to control the devices remotely supporting IR remote control without any manipulation on the existing consumer-centric appliance such as air conditioner, television and so on. There is a small potential risk that IoT devices can be exploited maliciously to leak sensitive data. As we are simply controlling the devices which supports a limited range and has limited function, the risk is lower.
The ESP32 has IrDA support, but there is no documentation of how to wire it or about hardware requirements. ESP32 can directly generate the IRTX and decode the IRRX so it is just about adding minimal hardware like an IR-LED and an IR-Phototransistor. Infrared has two different modes, for remotes of television and air-conditioners, the one-way with modulation of 35 or 38 kHz is used. So for them, just switching the IR-LED on and off will build the 38 kHz Packet. Driving an IR remote transmitter using an official Arduino is easy, as there is a library named IRremote.h
.
If you have an IR transmitter module, then attaching the signal pin to the appropriate Arduino pin with a current limiting resistor is all the wiring you need. KY-005 Infrared Transmitter Module (it is a transmitter module) emits infrared light at 38kHz. IR LEDs are usually made of gallium arsenide or aluminum gallium arsenide. KY-022 is the IR receiver module. This an example code for original Arduino boards :
---
1 2 3 4 5 6 7 8 9 10 11 12 13 | #include <IRremote.h> IRsend irsend; void setup() { Serial.begin(9600); } void loop() { for (int i = 0; i < 50; i++) { irsend.sendSony(0xa90, 12); // Sony TV power code delay(40); } } |
But, that IRRemote.h
Arduino library only supports receiving IR signals. To solve this issue, Andreas Spiess has a library to fully support ESP32 :
1 | https://github.com/SensorsIot/Definitive-Guide-to-IR |
The CIR (Commercial Infrared) Transmission Protocol cut-out the other sources of infrared radiation with a bandpass filter. The 940nm infrared transmitter is modulated by a carrier frequency in the 32-40 kHz range. This is how the receiver discriminates the IR signal and any unmodulated IR. So the IR receiver is tuned both to the wavelength and to the carrier frequency. The IR wavelength of the emitter and receiver should match.
The send-only code with infrared-LED and a resistor is this :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | //HardwareSerial Serial1(1); HardwareSerial Serial2(2); // GPIO 17: TXD U2 + GPIO 16: RXD U2 void setup() { Serial.begin (115200); // (USB + TX/RX) to check Serial2.begin(115200); // GPIO 17: TXD U2 + GPIO 16: RXD U2 //UART_CONF0_REG Configuration register 0 //UART0: 0x3FF40020 //UART1: 0x3FF50020 //UART2: 0x3FF6E020 WRITE_PERI_REG( 0x3FF6E020 , READ_PERI_REG(0x3FF6E020) | (1<<16 ) | (1<<10 ) ); //UART_IRDA_EN + UART_IRDA_TX_EN "Let there be light" //Serial.print("Reg: "); Serial.println(READ_PERI_REG(0x3FF6E020),BIN); //For Debug only }//setup void loop() { Serial.println("Hello"); Serial2.println("Hello"); delay(1000); } //loop |
The receive-only code with a phototransistor and a resistor is this :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | //HardwareSerial Serial1(1); HardwareSerial Serial2(2); // GPIO 17: TXD U2 + GPIO 16: RXD U2 void setup() { Serial.begin (115200); // (USB + TX/RX) to check Serial2.begin(115200); // GPIO 17: TXD U2 + GPIO 16: RXD U2 //UART_CONF0_REG Configuration register 0 //UART0: 0x3FF40020 //UART1: 0x3FF50020 //UART2: 0x3FF6E020 WRITE_PERI_REG( 0x3FF6E020 , READ_PERI_REG(0x3FF6E020) | (1<<16 ) | (1<<9 ) ); //UART_IRDA_EN + UART_IRDA_DPLX "Let there be light" //Serial.print("Reg: "); Serial.println(READ_PERI_REG(0x3FF6E020),BIN); //For Debug only }//setup void loop() { while (Serial2.available()) { Serial.print( (char) Serial2.read() ); delay(2); } //while } //loop |
We already have articles Controlling appliances with ESP32 and IBM Watson IoT and Android Apps to Control Devices Connected to IBM Watson IoT which will give a fair idea about how to send an HTTP request towards IBM’s server to get response on the connected remote ESP32. We have lot of example codes for IBM Watson Iot on our Github repository. The IoT part is just like switching a LED.
Probably you want to clone some brand’s remote. There are a lot of articles on the web on how to clone an IR remote for using with Arduino.
As for the Panasonic air-conditioners, this blog post will help.
Tagged With esp32 infrared , ir remote control esp32 , ir remote decoder using uart , ir sendor reat using esp32 relay control , ir transmitter esp32 , irremote esp32 , windows iot ir controller