Some Decode Remote Control Buttons Not Working

Thread Starter

Lawrence H

Joined May 6, 2019
98
Hey!

(Never mind, I forgot to change something in the end of the code)

I have a TV, that rather annoyingly resets itself to the television stations after shut down, even though I only use it as a monitor for my PC. So I made a funny fix for it since I got the parts, that when I press one button on a separate remote controller, an IR transmitter will first output the turn on/off signal, then open the source menu, and go to the correct source, and then it should select it.

The issue is however, that it seems that some of the decoded buttons don't seem to work. The actual remote controller works just fine when I press these buttons, but simulated by my own transmitter, these buttons don't work. The ones that I tried and do not work are the Exit button, and the Enter button, both of which would be handy to turn off the source menu. All the other buttons needed do work. Those are the switch on button, source button, and press down button.

Here is the code I use. Don't worry about it being disorganized. It is evolved code for testing purposes, and not meant to be the final code.

Code:
//Choose Decoded Remote Type
//#define DECODE_DENON
//#define DECODE_SHARP        // the same as DECODE_DENON
//#define DECODE_JVC
//#define DECODE_KASEIKYO
//#define DECODE_PANASONIC    // the same as DECODE_KASEIKYO
//#define DECODE_LG
#define DECODE_NEC
#define DECODE_SAMSUNG
//#define DECODE_SONY
//#define DECODE_RC5
//#define DECODE_RC6

//#define DECODE_BOSEWAVE
//#define DECODE_LEGO_PF
//#define DECODE_MAGIQUEST
//#define DECODE_WHYNTER

//#define DECODE_HASH         // special decoder for all protocols

//Include
#include <Arduino.h>
#include <IRremote.h>

////Init
///Dynamic
byte analogValue = 0;

byte savedIRInput = "";
String savedIRInputHex = "";

///Static

//General
const byte analogIncrement = 20;
const byte analogMin = 25;
const byte analogMax = 225;

const byte byteMax = 255;
const byte byteMin = 0;

const unsigned int serial = 9600;
const byte wait = 100;
const unsigned int waitLong = 1000;

//Pins
const byte pinIRReceive = 11;
const byte pinIRTransmit = 3;
const byte pinLED = 13;
const byte pinAnalog = 9;

/*
//Arduino Remote
byte button0 = 0x16; //For some reason unsigned is better with hexadecimals, figure out why
byte button1 = 0xC;
byte button2 = 0x18;
byte button3 = 0x5E;
byte button4 = 0x8;
byte button5 = 0x1C;
byte button6 = 0x5A;
byte button7 = 0x42;
byte button8 = 0x52;
byte button9 = 0x4A;

byte button100 = 0x19;
byte button200 = 0xD;

byte buttonChDown = 0x45;
byte buttonCh = 0x46;
byte buttonChUp = 0x47;

byte buttonBack = 0x44;
byte buttonForward = 0x40;
byte buttonPlayPause = 0x43;

byte buttonMinus = 0x7;
byte buttonPlus = 0x15;
byte buttonEQ = 0x9;
*///Arduino Remote End

//Samsung Remote
const byte buttonPower = 0x2;
const byte buttonPowerDec = 2;
const byte buttonSource = 0x1;
const byte buttonSourceDec = 1;
const byte buttonDown = 0x61;
const byte buttonDownDec = 97;
const byte buttonEnter = 0x68; //Automatic channel is , power, source, down, down, enter - Start PC with Power button, so both start.
const byte buttonEnterDec = 104;
const byte buttonExit = 0x2D;
const byte buttonExitDec = 45;

const byte button0 = 0x16; //For some reason unsigned is better with hexadecimals, figure out why
const byte button1 = 0xC;
const byte button2 = 0x18;
const byte button3 = 0x5E;
const byte button4 = 0x8;
const byte button5 = 0x1C;
const byte button6 = 0x5A;
const byte button7 = 0x42;
const byte button8 = 0x52;
const byte button9 = 0x4A;

const byte button100 = 0x19;
const byte button200 = 0xD;

const byte buttonChDown = 0x45;
const byte buttonCh = 0x46;
const byte buttonChUp = 0x47;

const byte buttonBack = 0x44;
const byte buttonForward = 0x40;
const byte buttonPlayPause = 0x43;

const byte buttonMinus = 0x7;
const byte buttonPlus = 0x15;
const byte buttonEQ = 0x9;

void setup() {
    Serial.begin(serial);
    IrReceiver.begin(pinIRReceive);
    IrSender.begin(pinIRTransmit);
    Serial.print(F("Ready to receive IR signals at pin "));
    Serial.println(pinIRReceive);
   
    pinMode(pinLED,OUTPUT);
    pinMode(pinAnalog,OUTPUT);
}

void loop() {
    /*
     * Check if received data is available and if yes, try to decode it.
     * Decoded result is in the IrReceiver.decodedIRData structure.
     * E.g. command is in IrReceiver.decodedIRData.command
     * address is in command is in IrReceiver.decodedIRData.address
     * and up to 32 bit raw data in IrReceiver.decodedIRData.decodedRawData
     */
    if (IrReceiver.decode()) { // Check if received data is available and if yes, try to decode it.
        savedIRInput = IrReceiver.decodedIRData.command; //Save the input for later
        savedIRInputHex = String(savedIRInput, HEX);
        Serial.print("Hex: " + savedIRInputHex);
        Serial.println("");
        Serial.println(savedIRInput);
        // Print a short summary of received data
        //IrReceiver.printIRResultShort(&Serial); //This prints a "short" amount of data when pressed. If button is held, it will spasm
        IrReceiver.printIRResultShort(&Serial);
        //Serial.println(Serial); //This prints a number 1 if there is data being received
        // !!!Important!!! Enable receiving of the next value, since receiving has stopped after the end of the current received data packet.
       
        if (IrReceiver.decodedIRData.command == button1) { //button 1 is pressed
          digitalWrite(pinLED,HIGH); // turn on led
        }
        else if (IrReceiver.decodedIRData.command == button0) //button 0 pressed
        {
          digitalWrite(pinLED,LOW); //Turn off led
        }
        else if (IrReceiver.decodedIRData.command == buttonPlus) //button + pressed
        {
          if (analogValue > analogMax) //Limit analog value
          {
            analogValue = byteMax;
          }
          else
          {
            analogValue += analogIncrement;
          }
        }
        else if (IrReceiver.decodedIRData.command == buttonMinus) //button - pressed
        {
          if (analogValue < analogMin)
          {
            analogValue = byteMin;
          }
          else
          {
            analogValue -= analogIncrement;
          }
        }      
        //End of Buttons
        else
        {
          //Do nothing
        }

        //Write Results
        analogWrite(pinAnalog,analogValue); //Write the analog value
       
        //Finalize Receiver
        delay(wait); //Wait here before taking in more info so that the remote wont repeat button press
        IrReceiver.resume(); // Enable receiving of the next value

        // =============== Transmitter Begin

        if (savedIRInput = IrReceiver.decodedIRData.command == button9)
        {
          //IrSender.sendNEC(0xA8, 0x19, 2); //Guidance
          IrSender.sendSamsung(0x707, buttonPowerDec, true, 0);
          digitalWrite(pinLED,HIGH);
          delay(10000);
          digitalWrite(pinLED,LOW);
         
          IrSender.sendSamsung(0x707, buttonSourceDec, true, 0);
          digitalWrite(pinLED,HIGH);
          delay(waitLong);
          digitalWrite(pinLED,LOW);
         
          IrSender.sendSamsung(0x707, buttonDownDec, true, 0);
          digitalWrite(pinLED,HIGH);
          delay(waitLong);
          digitalWrite(pinLED,LOW);

          IrSender.sendSamsung(0x707, buttonDownDec, true, 0);
          digitalWrite(pinLED,HIGH);
          delay(waitLong);
          digitalWrite(pinLED,LOW);
         
          IrSender.sendSamsung(0x707, buttonDownDec, true, 0);
          digitalWrite(pinLED,HIGH);
          delay(waitLong);
          digitalWrite(pinLED,LOW);
         
          IrSender.sendNEC(0x707, buttonExitDec, true, 0);
          digitalWrite(pinLED,HIGH);
          delay(waitLong);
          digitalWrite(pinLED,LOW);
        }
        else if (savedIRInput = IrReceiver.decodedIRData.command == button8)
        {
          IrSender.sendNEC(0x707,buttonExitDec, true, 0);
          digitalWrite(pinLED,HIGH);
          delay(waitLong);
          digitalWrite(pinLED,LOW);
        }
        //No Button Pressed
        else
        {
          //Do Nothing
        }
        //Finalize
        savedIRInput = ""; //Reset saved input
    }
}
Is there something about certain buttons that need to be handled differently, or did I miss something in the code?
 
Last edited:
Top