Function irrecv.decode(&results) returns always true

All hardware, but the Arduino UNO I am using, I got from https://www.casadarobotica.com/[](https://www.casadarobotica.com/kit-s-didaticos/outros/kit-infravermelho-controle-remoto-receptor-led-infravermelho)

I am using a control to turn the LED on and off using any button — if the LED is on and a button is pressed, the LED is turned off; if the LED is off and a button is pressed, the LED is turned on.

Sometimes after some buttons are pressed, usually when two or more buttons are presses simultaneously, the variable stateReceiver is always true and the results.value is always the same. When it happens, I disconnect the infrared receiver and the cables connecting to it, since the receiver's quality is questionable, but stateReceiver still is always true, so the LED is blinking every 0.1 second, even without the receiver.

#include <IRremote.h>
// Requirements
int ledPin = 3; // Led' pin
int receiverPin = 2; // Receiver's pin
// System
bool stateLED = false; // If the LED's on or off
bool stateReceiver = false; // if the receiver is on or off

IRrecv irrecv(receiverPin);
decode_results results;

void setup() {
  irrecv.enableIRIn(); // Turns the sensor on
  Serial.begin(9600); // Begins a serial connection
  pinMode(ledPin, OUTPUT); // Sets the LED's pin for output
}

void loop() {
  stateReceiver = irrecv.decode(&results); // If the receiver has received anything
  delay(100); // Waits 0.1 second to each signal durates 0.1 second. TEMPORARY
  Serial.println(results.value, HEX);
  if (stateReceiver) { // If the receiver is on
    if (stateLED) { // If the LED is on, it is turned off
      digitalWrite(ledPin, LOW);
      stateLED = false;
    }
    else { // If the receiver is off, it is turned on
      digitalWrite(ledPin, HIGH);
      stateLED = true;
    }
    irrecv.resume(); // Waits for the next message
  }
}
  delay(100); // Waits 0.1 second to each signal durates 0.1 second. TEMPORARY

Why? Have you tried removing this?

You have serial debug statements. What is the output from that?

Also, you said you disconnected the receiver. Aren't all bets off when you do that? In other words, isn't it normal to expect a broken input to produce broken values?

aarg:
You have serial debug statements. What is the output from that?

If you mean the output from the serial connection, it just repeats the same thing. But I've just seen that if you press button “cheese”, it'll be printed “cheese” even when stateReceiver is off.

'button "cheese" ' ?????

aarg:
'button "cheese" ' ?????

It is just an example-button. One of the buttons I pressed was 4AA6F810.

aarg:
'button "cheese" ' ?????

When I use the IRremote library in the version 2.6.1 or lower, it looks like there's no bug.

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