Hello everyone,
I am working on a project that involves capturing an IR remote code and sending it back out using an Arduino. I am using the IRremote library and have successfully implemented the receive functionality. However, I am having trouble getting the send functionality to work.
I have verified that an IR signal is being sent through debug statements and by viewing the IR LED through a camera. However, the device I am trying to control does not respond when I send the IR code that was captured from its remote. The remote itself works correctly with the device, so I know that the received remote code is correct.
Here is the complete code relevant to the sending functionality of my sketch:
#include <IRremote.hpp>
#define IR_RECEIVE_PIN 2
#define IR_SEND_PIN 3
#define ENABLE_LED_FEEDBACK true
#define STATUS_LED 13
IRsend irsend(IR_SEND_PIN);
decode_type_t protocol = UNKNOWN;
uint16_t address = 0;
uint8_t inputCommand = 0;
uint32_t rawData = 0;
uint16_t bitCount = 0;
bool readIRFlag = false;
bool sendPowerOnFlag = false;
unsigned long sMillisOfFirstReceive;
bool sLongPressJustDetected;
void setup() {
Serial.begin(9600);
IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK, STATUS_LED);
pinMode(STATUS_LED, OUTPUT);
digitalWrite(STATUS_LED, LOW);
}
void loop() {
if (Serial.available()) {
String command = Serial.readStringUntil('\n');
if (command == "read ir") {
readIRFlag = true;
} else if (command == "stop") {
readIRFlag = false;
sendPowerOnFlag = false;
} else if (command == "send ir") {
// Send the last received IR code
if (protocol != UNKNOWN) {
switch (protocol) {
case NEC:
Serial.print("Sending NEC signal with rawData: ");
Serial.print(rawData, HEX);
Serial.print(", bitCount: ");
Serial.println(bitCount);
irsend.sendNEC(rawData, bitCount);
delay(5000);
Serial.print("Sending NEC signal with command: ");
Serial.print(inputCommand, HEX);
Serial.print(", address: ");
Serial.println(address, HEX);
irsend.sendNEC(inputCommand, address, 3);
break;
case SONY:
irsend.sendSony(rawData, bitCount);
break;
// Add more cases here for other protocols
}
Serial.println("Sent last received IR code");
} else {
Serial.println("No IR code received yet");
}
} else if (command == "send power on") {
sendPowerOnFlag = true;
}
}
if (sendPowerOnFlag) {
Serial.print("Sending NEC signal with command: ");
Serial.print(inputCommand, HEX);
Serial.print(", address: ");
Serial.println(address, HEX);
irsend.sendNEC(inputCommand, address, 3);
}
}
This code uses the IRremote library to capture and send IR signals using an Arduino. The IRsend object is created with the IR_SEND_PIN constant as an argument, which specifies the pin number to which the IR LED is connected. The loop() function checks for serial commands and performs different actions depending on the command received. If the send ir command is received, the sketch will send the last received IR code using the irsend.sendNEC() function.
I have used the circuit detailed in this tutorial to build my project: https://www.digikey.ca/en/maker/blogs/2021/how-to-send-and-receive-data-over-ir-signals-with-an-arduino.
I would appreciate any advice or suggestions on how to diagnose and fix this issue. Thank you in advance for your help!