IR Receiver HEX code doesn't run if statement

Hi, i recently updated the IRRemote library and thought i edited the code to fit the new format but when it receives the HEX code it reads it correctly but does not run the if statement associated with the code. My coding knowledge is limited as i dropped out of school to be an electrician so i have basic first year engineering coding knowledge. The program is printing the HEX code but running the default case despite matching the correct code. I'm receiving this when pressing a button

F30CFF00
Protocol=NEC Address=0x0 Command=0xC Raw-Data=0xF30CFF00 32 bits LSB first
Send with: IrSender.sendNEC(0x0, 0xC, <numberOfRepeats>);
 other button  

This is an example of the if statement im trying to get to run with that input

case 0xF30CFF00:               //Margharita (1)
    if (sensorValue==0){
      Serial.println("Margharita"); 
      digitalWrite(relay1, HIGH);
      delay(two);
      digitalWrite(relay1,LOW);
      digitalWrite(relay2, HIGH);
      delay(one);
      digitalWrite(relay2, LOW);
      digitalWrite(relay3, HIGH);
      delay(one);
      digitalWrite(relay3, LOW);
      break;
    }

My best guess is i missed something when adjusting the code for the updated library
Here is the full program

#include <IRremote.hpp>


const int receiver = 3; 
const int relay1 = 12;    //tequila
const int relay2 = 11;    //lime juice
const int relay3 = 10;    //triple sec
const int relay4 = 9;    //vodka
const int relay5 = 8;     //cranberry juice
const int relay6 = 7;     //ginger beer
const int relay7 = 6;     //vermouth
const int relay8 = 5;     //grapefruit juice

int half = 1000;
int one = 2000;
int oneHalf = 3000;
int two = 4000;

//IRrecv ir_receiver(receiver);           
decode_results results;           

void setup()   
{
  Serial.begin(9600);
  IrReceiver.begin(receiver, ENABLE_LED_FEEDBACK);   
  pinMode(relay1, OUTPUT);  
  pinMode(relay2, OUTPUT); 
  pinMode(relay4, OUTPUT); 
  pinMode(relay5, OUTPUT); 
  pinMode(relay6, OUTPUT); 
  pinMode(relay7, OUTPUT); 
  pinMode(relay8, OUTPUT); 
}


void loop() 
{
  if (IrReceiver.decode())
   {
    Serial.println(IrReceiver.decodedIRData.decodedRawData, HEX); // Print "old" raw data
      IrReceiver.printIRResultShort(&Serial); // Print complete received data in one line
      IrReceiver.printIRSendUsage(&Serial);   // Print the statement required to send this data
      translateIR();
      IrReceiver.resume(); // Enable receiving of the next value
  } 
  /*
1 = FF30CF
2 = FF18E7
3 = FF7A85
4 = FF10EF
5 = FF38c7
6 = FF5AA5
7 = FF42BD
8 = FF4AB5
9 = FF52AD
  */

  /* NEW VALUES AFTER UPDATE
1 = F30CFF00
2 = E718FF00
3 = A15EFF00
4 = F708FF00
5 = E31CFF00
6 = A55AFF00
7 = BD42FF00
8 = AD52FF00
9 = B54AFF00
  */
}

void translateIR() 

{
   int sensorValue=0;
  sensorValue = digitalRead(relay1);
  
  switch(results.value){

   case 0xF30CFF00:               //Margharita (1)
    if (sensorValue==0){
      Serial.println("Margharita"); 
      digitalWrite(relay1, HIGH);
      delay(two);
      digitalWrite(relay1,LOW);
      digitalWrite(relay2, HIGH);
      delay(one);
      digitalWrite(relay2, LOW);
      digitalWrite(relay3, HIGH);
      delay(one);
      digitalWrite(relay3, LOW);
      break;
    }
   
    case 0xE718FF00:              //Cosmo (2)
    if (sensorValue==0){        
      Serial.println("Cosmo");
      digitalWrite(relay4, HIGH);
      delay(two);
      digitalWrite(relay4, LOW);
      digitalWrite(relay2, HIGH);
      delay(half);
      digitalWrite(relay2, LOW);
      digitalWrite(relay3, HIGH);
      delay(half);
      digitalWrite(relay3, LOW);
      digitalWrite(relay5, HIGH);
      delay(one);
      digitalWrite(relay5, LOW);
      break;
  }

    case 0xA15EFF00:              //Vodka Cran (3)
    if (sensorValue==0){
      Serial.println("VodkaCran");
      digitalWrite(relay4, HIGH);
      delay(oneHalf);
      digitalWrite(relay4, LOW);
      digitalWrite(relay5, HIGH);
      delay(two + two);
      digitalWrite(relay5, LOW);
      break;
    }

    case 0xF708FF00:              //Moscow Mule (4)
    if (sensorValue==0){
      Serial.println("Moscow Mule");
      digitalWrite(relay4, HIGH);
      delay(two);
      digitalWrite(relay4, LOW);
      digitalWrite(relay2, HIGH);
      delay(half);
      digitalWrite(relay2, LOW);
      digitalWrite(relay6, HIGH);
      delay(two + two);
      digitalWrite(relay6, LOW);
      break;
    }

    case 0xE31CFF00:                //Martini (5)
    if (sensorValue==0){
      Serial.println("Martini");
     digitalWrite(relay4, HIGH);
     delay(two + one);
     digitalWrite(relay4, LOW);
     digitalWrite(relay7, HIGH);
     delay(one);
     digitalWrite(relay7, LOW);
      break;
    }

    case 0xA55AFF00:                //Paloma (6)
    if (sensorValue==0){
      Serial.println("Paloma");
      digitalWrite(relay1, HIGH);
      delay(two);
      digitalWrite(relay1, LOW);
      digitalWrite(relay2, HIGH);
      delay(half);
      digitalWrite(relay2, LOW);
      digitalWrite(relay8, HIGH);
      delay(two);
      digitalWrite(relay8, LOW);
      break;
    }

  default:
    Serial.println(" other button    ");

  }
}

You did not update the code for the variable you test against

You printed IrReceiver.decodedIRData.decodedRawData not results.value which is the old stuff

Also don’t keep the break within the if for your cases it should read

case 0x…. : 
  if (condition) {
    …
  }
  break;
1 Like

Your topic has been moved as it does not seem to indicate a problem with IDE 2.x.

The commented lists of nine values are the same thing, but one is LSB first and the other is MSB first. Try:

case 00FF30CF

1 Like

Yes, thank you. I had a feeling i missed something when updating it to the new library.

Have fun !

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