I am trying to connect 2 IR receiver on 2 different data pins of esp32

I am trying to connect 2 IR receiver on 2 different data pins of esp32, but at a time receiving data only on 1 pin. Please help.

#include <IRremoteESP8266.h>
#include <IRrecv.h>
#include <IRutils.h>

#define IR_RECEIVER_PIN1 16
#define IR_RECEIVER_PIN2 17

IRrecv irrecv1(IR_RECEIVER_PIN1);
IRrecv irrecv2(IR_RECEIVER_PIN2);

decode_results results1;
decode_results results2;

void setup() {
  Serial.begin(115200);

  irrecv1.enableIRIn();  // Start the IR receiver on pin1
  irrecv2.enableIRIn();  // Start the IR receiver on pin2
}

void loop() {
  if (irrecv1.decode(&results1)) {
    Serial.print("IR Receiver 1 Value: ");
    Serial.println(results1.value, HEX);
    irrecv1.resume();  // Receive the next value
  }

  if (irrecv2.decode(&results2)) {
    Serial.print("IR Receiver 2 Value: ");
    Serial.println(results2.value, HEX);
    irrecv2.resume();  // Receive the next value
  }

  delay(100);  // Adjust the delay based on your requirements
}

Wiring is as below:
5v-VCC of ir of both receiver
GND-GND of both receiver
16- Data pin of receiver 1
17- data pin of receiver 2

Still not found any appropriate way to do this any kind of help will be appreciated.
Thanks in advance.

Welcome to the forum

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the < CODE/ > icon above the compose window) to make it easier to read and copy for examination

https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum

ok will do next time can you help me in this.

Please edit your first post and add the code tags. It makes it so much easier to examine it and copy it of required

Edited.

Thank you

i am making a system where i require 2 ir receiver one signifying back and other front, and i want to receive data from both receivers on pin 16 and 17 of esp32 . I tried with code but at a time only 1 which is defined last is receiving only.
below is my code

#include <IRremoteESP8266.h>
#include <IRrecv.h>
#include <IRutils.h>

#define IR_RECEIVER_PIN1 16
#define IR_RECEIVER_PIN2 17

IRrecv irrecv1(IR_RECEIVER_PIN1);
IRrecv irrecv2(IR_RECEIVER_PIN2);

decode_results results1;
decode_results results2;

void setup() {
  Serial.begin(115200);

  irrecv1.enableIRIn();  // Start the IR receiver on pin1
  irrecv2.enableIRIn();  // Start the IR receiver on pin2
}

void loop() {
  if (irrecv1.decode(&results1)) {
    Serial.print("IR Receiver 1 Value: ");
    Serial.println(results1.value, HEX);
    irrecv1.resume();  // Receive the next value
  }

  if (irrecv2.decode(&results2)) {
    Serial.print("IR Receiver 2 Value: ");
    Serial.println(results2.value, HEX);
    irrecv2.resume();  // Receive the next value
  }

  delay(100);  // Adjust the delay based on your requirements
}

Wiring is as below:
5v-VCC of ir of both receiver
GND-GND of both receiver
16- Data pin of receiver 1
17- data pin of receiver 2

any kind of lead on this project will be very helpful for me.
Thanks in advance

did you RTFineM ?

Does this library support multiple distinct IR capture sources?

Do you really need two ?

Hy,
thankyou for responding
but I didn't get what you are talking about? Can you please elaborate

did you read the doc ? the link says

Does this library support multiple distinct IR capture sources?

No. It only supports a single IR signal source in order to reduce IRAM/ICACHE_FLASH_ATTR and memory usage. IRAM is a very limited resource on the ESP8266. It is used by Interrupt routines, which the IR receiving routines are.

You can however, connect multiple hardware IR demodulator units together in a circuit, and use them via a single input GPIO on your ESP, and it will typically work. However, you will not be able tell which IR demodulator received the signal.

so you can't do

ok I read that, I saw similar projects online and many people are working on same thing and there it is working, and unfortunately I am not able to find code or any hardware references for the same.

share links to such projects (they must do something else)

of what?

Can you explain the purpose of this project?

can you confirm you want something to deal with an IR remote control?
image

and you are not confused because what you want is an Line Follower type of IR module?

i am trying to build a laser tag project

Yes i am working with an IR ren=mote control only I am using a transmitter led and receiving it using TSOP1738 and below are there images
trans
recv

One on the laser tag project

This is for an ESP32 and not the library you have been using.

They are using the RMT peripheral on ESP32 (initially designed for infrared communication but flexible enough to be repurposed for various signal types).

The ESP32 RMT has multiple channels available and each can operate independently as either a transmitter or a receiver. That’s how you can handle multiple receivers in parallel.

If you are not using an ESP32 this is not available to you, if you are using an ESP32 then use an RMT based library.

See Remote Control Transceiver (RMT) - ESP32 - — ESP-IDF Programming Guide v5.2.1 documentation

1 Like

ok i will check this and let you know the results.

Hy, I read this documentation and other articles as well. But i am not able to figure out how can i use this for receiving purpose, If you have any idea on this then Can you help me with this?