ESP32 Tutorial 29/55 - Reading IR remote key press with ESP32| SunFounder's ESP32 IoT Learning kit

ESP32 Tutorial 29/55 - Reading IR remote key press with ESP32| SunFounder's ESP32 IoT Learning kit

In this tutorial, we will learn how to detect infrared (IR) signals using the ESP32 module and a compatible IR receiver. When we press a button on the remote, the ESP32 will recognize the signal and execute specific actions, such as sounding a buzzer for particular key presses. This project is ideal for those looking to integrate remote control capabilities into their ESP32 applications (in video at 02:15).

remote

The ESP32 is a powerful microcontroller that combines Wi-Fi and Bluetooth capabilities, making it suitable for a wide range of IoT applications. In this project, we will use an IR receiver to interpret signals from a remote control. The key presses will be processed in the code, allowing us to take actions based on the received commands.

Hardware Explained

The main components for this project include the ESP32 microcontroller, an IR receiver module, and a buzzer. The ESP32 serves as the brain of the operation, processing the signals received from the IR receiver. The IR receiver detects the infrared signals from the remote control and converts them into electrical signals that the ESP32 can understand.

ir_receiver_sl838

The IR receiver typically has three pins: VCC (power), GND (ground), and OUT (signal). The VCC pin is connected to a power source (3.3V or 5V), while the GND connects to the ground. The OUT pin sends the decoded signal to the ESP32, which can then be used to trigger various actions, such as activating a buzzer when a specific key is pressed.

Datasheet Details

Manufacturer Sharp
Part number GP1UXC41
Logic/IO voltage 3.3 - 5.0 V
Supply voltage 3.3 V (typ.)
Output current (per channel) 20 mA (max)
Peak current (per channel) 50 mA (max)
PWM frequency guidance 38 kHz
Input logic thresholds 0.3 Vcc (high), 0.2 Vcc (low)
Voltage drop / RDS(on) / saturation 0.5 V (max)
Thermal limits 85 °C (max)
Package TO-92
Notes / variants Available in multiple configurations

 

  • Ensure correct power supply to avoid damage.
  • Use short wires to minimize signal interference.
  • Check the orientation of the IR receiver before connecting.
  • Confirm that the remote control battery is functional.
  • Use pull-up resistors if necessary for stability.

Wiring Instructions

ESP32-29-IR-remote-wiring

To wire the IR receiver to the ESP32, start by identifying the three pins on the IR receiver: VCC, GND, and OUT. Connect the VCC pin to a 3.3V power source on the ESP32. Next, connect the GND pin to one of the ground (GND) pins on the ESP32. Finally, connect the OUT pin to GPIO pin 14 on the ESP32, which is designated for the IR receiver in the code.

ESP32-29-IR-remote-schematic

Once the connections are made, ensure that the wiring is secure. If you are using a breadboard, insert the IR receiver such that the flat side is facing you and the bump is on the opposite side. This orientation will help you correctly identify the pins. Make sure to verify the connections before powering up the ESP32.

Code Examples & Walkthrough

IR_receiver_lib

install the IRremoteESP8266library by David Conran, Sebastien.

In the code, we define the IR receiver pin using the constant IR_RECEIVE_PIN, which is set to 14. We also create an instance of IRrecv to handle the IR signals.

const uint16_t IR_RECEIVE_PIN = 14;
IRrecv irrecv(IR_RECEIVE_PIN);
decode_results results;

This setup allows us to receive signals from the IR remote. In the setup() function, we initialize the serial communication and enable the IR receiver.

void setup() {
  Serial.begin(115200);
  irrecv.enableIRIn();
}

Within the loop() function, we check if an IR signal has been received. If so, we decode the key value and print it to the serial monitor.

if (irrecv.decode(&results)) {
    String key = decodeKeyValue(results.value);
    Serial.println(key);
    irrecv.resume(); 
}

This code snippet shows how we decode the received signal and print the corresponding key value to the serial monitor. The decodeKeyValue() function maps the received signal to specific button values, such as "0", "1", "EQ", and others. You can find the complete code loaded below the article.

Demonstration / What to Expect

Once the wiring is complete and the code is uploaded, pressing a button on the remote should display the corresponding key value on the serial monitor. For example, pressing the "2" button will print "2" to the monitor. If the key is not recognized, it will return "ERROR". The buzzer will sound when the designated key (e.g., "EQ") is pressed, providing immediate feedback.

Be cautious of common pitfalls, such as reversed polarity in your connections or using incorrect voltage levels. Ensure that the remote control works properly and has a functioning battery before testing your setup (in video at 15:30).

Video Timestamps

  • 00:00 Start
  • 2:05 Introduction to IR receiver
  • 4:24 Wiring explained
  • 6:08 Arduino code for IR receiver explained
  • 10:06 Selecting ESP32 board and COM port in Arduino IDE
  • 11:48 Project Demonstration
  • 13:09 Active buzzer directly connected to ESP32
  • 14:40 taking action when a key is pressed
  • 15:30 Arduino code for taking action
  • 16:54 Key press and buzzer demo

图像

IR_receiver_lib
IR_receiver_lib
ir_receiver_sl838
ir_receiver_sl838
remote
remote
ESP32-29-IR-remote-schematic
ESP32-29-IR-remote-schematic
ESP32-29-IR-remote-wiring
ESP32-29-IR-remote-wiring
830-ESP32 Tutorial 29/55- Arduino code for fading Infrared remote
语言: C++
已复制!

|||您可能需要的东西

资源与参考

文件📁

数据手册 (pdf)