for some reason if I press button 1 I get 9.
If I press another button I get its code but then get 9 again?
AS if it isrepeating button 1?
How much time do you spend on a problem? It takes more than one minute, usually.
I have spent days on this and the period before I finally got a signal I just spent 2 hours trying stuff. I think I am nearly there but just need the final bit of help..
See reply #20
= is not the same as ==
Try these changes.
//Install IRremote Version 3.3.0
#include <IRremote.h> // Ver 3.3.0 <-------<<<<<<<
#define DECODE_NEC
const byte IR_RECEIVE_PIN = 5; //<-------<<<<< your receive pin
//******************************************************************************************
void setup()
{
Serial.begin(115200); //<-------<<<<< your baud rate
pinMode(LED_BUILTIN, OUTPUT);
pinMode(12, OUTPUT);
IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK);
} //END of setup()
//******************************************************************************************
void loop()
{
//*********************************
if (IrReceiver.decode())
{
if (IrReceiver.decodedIRData.protocol == UNKNOWN)
{
Serial.println(F("Received noise or an unknown (or not yet enabled) protocol"));
// We have an unknown protocol here, print more info
IrReceiver.printIRResultRawFormatted(&Serial, true);
}
if (IrReceiver.decodedIRData.command != 0)
{
Serial.print("Code: ");
Serial.println(IrReceiver.decodedIRData.command);
if (IrReceiver.decodedIRData.command == 9)
{
digitalWrite(12, HIGH);
Serial.println("HERE");
}
else if (IrReceiver.decodedIRData.command == 29)
{
digitalWrite(12, LOW);
}
//if we need to block repeat codes
IrReceiver.decodedIRData.command = 0;
}
IrReceiver.resume(); // Enable receiving of the next value
}
} //END of loop()
//******************************************************************************************
That's got it.
I had the debounce line in the wrong place.
I added
Serial.println("AND HERE");
to the second instruction and I get it showing on the monitor as well.
I am now going to bed but will look further at enhancing the sketch and get back to reporting on my progress and mark this as solved if I feel I understand it well enough tomorrow.
Thanks so much for the help.
Have a good one
![]()
I think this has done it.
I have posted the finished article in case someone else wants to try it.
//Install IRremote Version 3.3.0
//original taken from post 25 of
//https://forum.arduino.cc/t/problems-receiving-ir-signals-from-a-remote-unit/1109255/18
//thanks LarryD
#include <IRremote.h> // Ver 3.3.0 <-------<<<<<<<
//#define DECODE_NEC
#define DECODE_SAMSUNG
const byte IR_RECEIVE_PIN = 5; // receive pin
void setup()
{
Serial.begin(9600); // baud rate
pinMode(LED_BUILTIN, OUTPUT);
pinMode(12, OUTPUT);
IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK);//use pin 13
} //END of setup()
void loop()
{
if (IrReceiver.decode())
{
if (IrReceiver.decodedIRData.protocol == UNKNOWN)
{
Serial.println(F("Received noise or an unknown (or not yet enabled) protocol"));
// We have an unknown protocol here, print more info
IrReceiver.printIRResultRawFormatted(&Serial, true);
}
if (IrReceiver.decodedIRData.command != 0)
{
Serial.print("Code: ");
Serial.println(IrReceiver.decodedIRData.command);
if (IrReceiver.decodedIRData.command == 4)
{
Serial.println("HERE");
}
else if (IrReceiver.decodedIRData.command == 5)
{
Serial.println("AND HERE");
}
//if we need to block repeat codes
IrReceiver.decodedIRData.command = 0;
}
IrReceiver.resume(); // Enable receiving of the next value
}
} //END of loop()
Thanks LarryD and others.