Messed up my IR receiver wiring

Arduino UNO R3

Hi I was going to add a switch to my design but at the last minute I decided to fit a TL1838 IR sensor instead as I thought it would be a clever way to add multiple buttons. I foolishly failed to test my design and didn't realise the sensor had to be connected to an interrupt pin 2 or 3 and I wired it to pin 13.

I already had the shield made by a PCB firm and soldered on the components and I'd rather not have to redo it all.

Is there a timer interrupt I can use to read the sensor and try to manually decode the IR code? Or some other workaround for reading an IR sensor without triggering off an interrupt?

Can you publish your schematic and code so that we can understand your project, its difficulties and then be able to help you?

You don't need interrupts to receive ir, but depending what else your arduino is doing, can be difficult to guarantee that it's always ready to receive. For sure you cant have a sketch full of delays.

Hmm OK I can't seem to get any of the IR libraries to work but I figured out I can use pin 13 by using the pin change interrupts.


#define ENABLE_REMOTE

#include "remote.h"

#ifdef ENABLE_REMOTE
#include "Arduino.h"
#define RECV_PIN 13
static uint32_t nextCode = 0U;
#endif

void setupRemote() {
#ifdef ENABLE_REMOTE
  pinMode(RECV_PIN, INPUT);
  PCICR |= B00000001;
  PCMSK0 |= B00100000;
#endif
}

uint32_t readRemote() {
#ifdef ENABLE_REMOTE
  noInterrupts();
  uint32_t result = nextCode;
  nextCode = 0U;
  interrupts();
  return result;
#else
  return 0U;
#endif
}

#ifdef ENABLE_REMOTE
ISR(PCINT0_vect) {
#define IR_BUFF_SIZE 32U
  static uint32_t code = 0U;
  static uint8_t count = 0U;
  static uint32_t timeOfLast = 0U;
  static bool wasPressed = false;

  bool pressed = !digitalRead(RECV_PIN);

  // If pin changed state
  if (pressed != wasPressed) {
    // If pin pressed.
    if (pressed) {
      uint32_t now = micros();
      // Too long since last change, assume start of new code
      if ((now - timeOfLast) > 10000) {
        count = 0U;
        code = 0U;
      } else {
        if ((now - timeOfLast) > 1680) {
          code = code | (1L << count);
        }
        count++;
        // If buffer full..
        if (count >= IR_BUFF_SIZE) {

          noInterrupts();
          nextCode = code;
          interrupts();
          count = 0U;
          code = 0U;
        }
      }
      timeOfLast = now;
    }
    wasPressed = pressed;
  }
}
#endif

Get something like this which I can use to figure out what button was pressed:

Button 1:
00:44:56.187 -> 4127723023

00:44:56.280 -> 4127723023

00:44:56.372 -> 4127723023

Button 2:
00:44:56.731 -> 4094299663

00:44:56.825 -> 4094299663

00:44:56.917 -> 4094299663

00:44:57.041 -> 4094299663

00:44:57.180 -> 4094299663

00:44:57.275 -> 4094299663

00:44:57.394 -> 4094299663

Button 3:
00:44:58.249 -> 4060876303

00:44:58.343 -> 4060876303

00:44:58.484 -> 4060876303

00:44:58.577 -> 4060876303

00:44:58.701 -> 4060876303

00:44:58.793 -> 4060876303

00:44:58.886 -> 4060876303

00:44:58.980 -> 4060876303

That is not a valid sketch.

It's ok I figured out how to do it.

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