Teensy LC IR Receive and Transmit


TLDR; I have a Teensy LC and can receive IR, or transmit IR. But if I try them together, the receive only works once.

So I bought a couple of Teensy LCs, a couple of IR transmitters, and IR receivers. I'd like to wirelessly send IR from one to the other and vise versa but the first step is to just get IR transmitting and receiving on one Teensy. So I started with the code posted here, and combined the transmit and receive into a single project in the hopes that I can just make a repeater as a test where it looks for new messages and retransmits them. Here is my code:

#include <IRremote.h>

const int RECV_PIN = 6;

IRrecv irrecv(RECV_PIN);
IRsend irsend;

decode_results results;

void setup()
  irrecv.enableIRIn(); // Start the receiver

void loop() {
  if (irrecv.decode(&results)) {
    if (results.decode_type == NEC) {
      Serial.print("NEC: ");
      //irsend.sendNEC(results.value, results.bits);
    } else if (results.decode_type == SONY) {
      Serial.print("SONY: ");
      irsend.sendSony(results.value, results.bits);
    } else if (results.decode_type == RC5) {
      Serial.print("RC5: ");
      irsend.sendRC5(results.value, results.bits);
    } else if (results.decode_type == RC6) {
      Serial.print("RC6: ");
      irsend.sendRC6(results.value, results.bits);
    } else if (results.decode_type == UNKNOWN) {
      Serial.print("UNKNOWN: ");
    Serial.println(results.value, HEX);
    Serial.println(results.bits, DEC);
    irrecv.resume(); // Receive the next value
    irsend.sendNEC(results.value, results.bits);

The receive is wired to pin 6, and transmit is on pin 16. Both transmit and receive are powered by the 3.3V of the Teensy for now but was unsure if the 5V should be used. The kit I bought mentioned Arduino with little more documentation so I assume it is 5V tolerant.

So my problem is the decode only works once, if I am sending the received message out. If I just receive (by commenting out the irsend.sendNEC) then my receive works and I get the NEC message and the number of bits over serial, over and over. If I enable the send (the way the code is now) then the first time it sees a message it will receive it, put it on serial, and transmit it. But then decode will always return false.

Is the Teensy LC able to transmit and receive at once? Is there an issue with the library where a timer is used in sending that screws up the receive? I added code transmit data over serial periodically and the Teensy always sends data so I assume it isn't resetting. This is with Arduino 1.8.1 and Teensyduino 1.35, and the IRremote library it comes with. Any help is appreciated, thanks.
Last edited:
This is how the IRremote library works, on all boards (not just Teensy LC). It either transmits or receives, but never both at the same time.
Hey Paul thanks alot. What I needed (and what I thought I tried already) is after performing the sendNEC, reenable with irrecv.enableIRIn. This will mean there is a small window where new IR messages won't be seen, because IR is being sent out, but I think for my purposes it will work fine. Thanks again.
This is how the IRremote library works, on all boards (not just Teensy LC). It either transmits or receives, but never both at the same time.

I am confused with IRremote documentation. The functions listed in the Teensyduino documentation are different than those in the IRremote library. Is it just old docs? or do I have the wrong library? I removed all instances of IRremote from arduino libraries and re-install
Teensyduino 1.57(?) and am not sure if I have the right code to use. Have the functions just changed? Things like irrecv vs IrReceiver are what I'm talking about.
I've just used the example in IRremote/ReceiveDemo with Teensyduino 1.57_b4 on a Teensy-LC. It works with a Sony remote. I'm using a Vishay TSOP variant of some sort - I forgot the exact part number but looks like this one.
That example uses "IrReceiver.decode()" etc.