0

I made wrote this fairly simple code which sets output on LED pin to some analog number

#include <Arduino.h>
#include <IRremote.hpp>

#define IR_RECEIVE_PIN 7
#define LED_PIN 11


uint16_t getCommand() {
    const IRData data = IrReceiver.decodedIRData;
    return data.flags == 1 ? 0 : data.command;
}

void setup() {
    pinMode(LED_PIN, OUTPUT);
    digitalWrite(LED_PIN, LOW);

    Serial.begin(9600);
    Serial.println(F("Running TestIRBlink"));
    IrReceiver.begin(IR_RECEIVE_PIN);
}

void loop() {
    if (!IrReceiver.decode()) {
        return;
    }
    const uint16_t cmd = getCommand();
    if (cmd != 0) {
        Serial.println(cmd);
    }
    if (cmd == 7) {
        analogWrite(LED_PIN, 120);
    } else if (cmd == 9) {
        analogWrite(LED_PIN, 230);
    }
    IrReceiver.resume();
}

IR receiver is able to receive all commands until I use 7 or 9. After that, LED does not light up, but IR stops recognizing commands as well. I have no idea why this happens.

Tested LED with PWM separately from IR receiver, it works. Also nothing breaks when using digitalWrite(). I assume PWM and receiver conflict in some way, but I couldn't find out how for 3 days now.

1 Answer 1

0

Resolved this by myself now. Turns out, IRremote uses Timer2, which made pins 3 and 11 unsuitable for PWM operations. Switching LED pin to any other PWM pin resolves the issue.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.