Bit Banging an IR Receiver

I am upgrading a dumb device to a smart device but unfortunately the device in question does not have any physical buttons, only an infrared remote, therefore I am attempting to use an Arduino to bit bang the raw NEC output of the IR codes directly but I am a bit lost in the actual transmission.

I have a digital PWM pin connected directly to the signal line where the IR receiver was desoldered from, and the following function to send the command, but when i send the hex code 0xB34C4BBA, I receive 0x43B2AC74 . Is anyone able to guide me in where i went wrong?

void simulateIRSignal(unsigned long code) {
  const unsigned int headerMark = 9000;    // Header mark duration in microseconds
  const unsigned int headerSpace = 4500;   // Header space duration in microseconds
  const unsigned int bitMark = 562;        // Bit mark duration in microseconds
  const unsigned int oneSpace = 1687;      // Space duration for a logical 1 in microseconds
  const unsigned int zeroSpace = 562;      // Space duration for a logical 0 in microseconds
  const unsigned int gap = 562;            // Gap duration between transmissions in microseconds

  // Send the header mark and space
  digitalWrite(IR_LINE, HIGH);
  delayMicroseconds(headerMark);
  digitalWrite(IR_LINE, LOW);
  delayMicroseconds(headerSpace);

  // Send the 32 bits of the code
  for (int i = 0; i < 32; i++) {
    // Get the current bit value
    unsigned long bitValue = (code & (1UL << i)) != 0;

    // Send the bit mark
    digitalWrite(IR_LINE, HIGH);
    delayMicroseconds(bitMark);
    digitalWrite(IR_LINE, LOW);

    // Send the corresponding space
    if (bitValue) {
      delayMicroseconds(oneSpace);  // Logical 1 space
    } else {
      delayMicroseconds(zeroSpace); // Logical 0 space
    }
  }

  // Send the trailing gap
  digitalWrite(IR_LINE, LOW);
  delayMicroseconds(gap);
}

To follow along, take two Arduinos, flash one with the RecieveDump example sketch for the IRremote Library, and connect pin 2 of that Arduino to a PWM pin on the other. Upload this function to the second Arduino, and send an IR code using the above code. Sending an IR code through this function will result in a dump on the console of the second Arduino. Don't forget to connect the two grounds as I had done at first.

The IR receiver device inverts the signal so, for example, the first 9000us of the NEC header is LOW, the next 4500us is HIGH etc. You appear to have this the wrong way around in your emulation. Also ensure grounds are common between your two arduinos.

I think that you missed the carrier frequency of typically 38 kHz. This is what the IR receiver expects and decodes. You are better off using the IRremote library that handles all that bit banging.

I was assuming this was a TSOP type device but maybe only a photo transistor?

it is a tsop device yes.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.