wanna create IR remote control in 3.03 library

#include <IRremote.h>
int IR_RECEIVE_PIN = 8;

const unsigned long BUTTON1 0xF30CFF00
const unsigned long BUTTON2 0xE718FF00
const unsigned long BUTTON3 0xC7E1D232
const unsigned long BUTTON4 0xF708FF00
const unsigned long BUTTON5 0xE31CFF00
const unsigned long BUTTON6 0xA55AFF00
const unsigned long BUTTON7 0xBD42FF00
const unsigned long BUTTON8 0xAD52FF00
const unsigned long BUTTON9 0xB54AFF00

void setup()
{
Serial.begin(9600);
IrReceiver.begin(IR_RECEIVE_PIN, true);
Serial.print(F("Ready to receive IR signals at pin "));
Serial.println(IR_RECEIVE_PIN);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
pinMode(6,OUTPUT);
pinMode(7,OUTPUT);
}
void loop()
{
if (IrReceiver.decode()){
if (IrReceiver.decodedIRData.decodedRawData==BUTTON1){
digitalWrite(4,HIGH);
digitalWrite(5,LOW);
digitalWrite(6,LOW);
digitalWrite(7,LOW);
}
if (IrReceiver.decodedIRData.decodedRawData==BUTTON2){
digitalWrite(4,LOW);
digitalWrite(5,HIGH);
digitalWrite(6,LOW);
digitalWrite(7,LOW);
}
if (IrReceiver.decodedIRData.decodedRawData==BUTTON3){
digitalWrite(4,HIGH);
digitalWrite(5,HIGH);
digitalWrite(6,LOW);
digitalWrite(7,LOW);
}
if (IrReceiver.decodedIRData.decodedRawData==BUTTON4){
digitalWrite(4,LOW);
digitalWrite(5,LOW);
digitalWrite(6,HIGH);
digitalWrite(7,LOW);
}
if (IrReceiver.decodedIRData.decodedRawData==BUTTON5){
digitalWrite(4,HIGH);
digitalWrite(5,LOW);
digitalWrite(6,HIGH);
digitalWrite(7,LOW);
}
if (IrReceiver.decodedIRData.decodedRawData==BUTTON6){
digitalWrite(4,LOW);
digitalWrite(5,HIGH);
digitalWrite(6,HIGH);
digitalWrite(7,LOW);
}
if (IrReceiver.decodedIRData.decodedRawData==BUTTON7){
digitalWrite(4,HIGH);
digitalWrite(5,HIGH);
digitalWrite(6,HIGH);
digitalWrite(7,LOW);
}
if (IrReceiver.decodedIRData.decodedRawData==BUTTON8){
digitalWrite(4,LOW);
digitalWrite(5,LOW);
digitalWrite(6,LOW);
digitalWrite(7,HIGH);
}
if (IrReceiver.decodedIRData.decodedRawData==BUTTON9){
digitalWrite(4,HIGH);
digitalWrite(5,LOW);
digitalWrite(6,LOW);
digitalWrite(7,HIGH);
}
IrReceiver.resume();
}}

cant seem to work. how to get the hexadecimal than compare it in if statement?

Since our improperly posted code will not compile, I don't see how you can get any result.

Read the how get the most out of this forum sticky to see how to properly post code. Remove useless white space and format the code with the IDE autoformat tool (crtl-t or Tools, Auto Format) before posting code in code tags.

Why don't you print the output from the IrReceiver.decodedIRData.decodedRawData instruction?

I got your code to compile and added some print statements to see what is being returned and the flow of the code. The serial port is your best and, almost, only troubleshooting tool. This is tested and works fine on my Uno and remote decoder. You will have to change the BUTTON constants to match your remote.

#include <IRremote.h>
int IR_RECEIVE_PIN = 8;

const unsigned long BUTTON1 = 0xFE01C738; // 1
const unsigned long BUTTON2 = 0xFD02C738; // 2
const unsigned long BUTTON3 = 0xFC03C738; // 3
const unsigned long BUTTON4 = 0xFB04C738; // 4
const unsigned long BUTTON5 = 0xFA05C738; // 5
const unsigned long BUTTON6 = 0xF906C738; // 6
const unsigned long BUTTON7 = 0xF807C738; // 7
const unsigned long BUTTON8 = 0xF708C738; // 8
const unsigned long BUTTON9 = 0xF609C738; // 9

void setup()
{
   Serial.begin(9600);
   IrReceiver.begin(IR_RECEIVE_PIN, true);
   Serial.print(F("Ready to receive IR signals at pin "));
   Serial.println(IR_RECEIVE_PIN);
   pinMode(4, OUTPUT);
   pinMode(5, OUTPUT);
   pinMode(6, OUTPUT);
   pinMode(7, OUTPUT);
}
void loop()
{
   if (IrReceiver.decode())
   {
      
      // ignore repeat codes
      if ((IrReceiver.decodedIRData.flags & IRDATA_FLAGS_IS_REPEAT))
      {
         IrReceiver.resume();
         return;
      }
      else  // print code if not repeat
      {
         Serial.println(IrReceiver.decodedIRData.decodedRawData, HEX);
      }
      
      if (IrReceiver.decodedIRData.decodedRawData == BUTTON1)
      {
         Serial.println("1");
         digitalWrite(4, HIGH);
         digitalWrite(5, LOW);
         digitalWrite(6, LOW);
         digitalWrite(7, LOW);
      }
      else if (IrReceiver.decodedIRData.decodedRawData == BUTTON2)
      {

         Serial.println("2")
         ; digitalWrite(4, LOW);
         digitalWrite(5, HIGH);
         digitalWrite(6, LOW);
         digitalWrite(7, LOW);
      }
      else  if (IrReceiver.decodedIRData.decodedRawData == BUTTON3)
      {
         Serial.println("3");
         digitalWrite(4, HIGH);
         digitalWrite(5, HIGH);
         digitalWrite(6, LOW);
         digitalWrite(7, LOW);
      }
      else if (IrReceiver.decodedIRData.decodedRawData == BUTTON4)
      {
         Serial.println("4");
         digitalWrite(4, LOW);
         digitalWrite(5, LOW);
         digitalWrite(6, HIGH);
         digitalWrite(7, LOW);
      }
      else if (IrReceiver.decodedIRData.decodedRawData == BUTTON5)
      {
         Serial.println("5");
         digitalWrite(4, HIGH);
         digitalWrite(5, LOW);
         digitalWrite(6, HIGH);
         digitalWrite(7, LOW);
      }
      else if (IrReceiver.decodedIRData.decodedRawData == BUTTON6)
      {
         Serial.println("6");
         digitalWrite(4, LOW);
         digitalWrite(5, HIGH);
         digitalWrite(6, HIGH);
         digitalWrite(7, LOW);
      }
      else if (IrReceiver.decodedIRData.decodedRawData == BUTTON7)
      {
         Serial.println("7");
         digitalWrite(4, HIGH);
         digitalWrite(5, HIGH);
         digitalWrite(6, HIGH);
         digitalWrite(7, LOW);
      }
      else if (IrReceiver.decodedIRData.decodedRawData == BUTTON8)
      {
         Serial.println("8");
         digitalWrite(4, LOW);
         digitalWrite(5, LOW);
         digitalWrite(6, LOW);
         digitalWrite(7, HIGH);
      }
      else if (IrReceiver.decodedIRData.decodedRawData == BUTTON9)
      {
         Serial.println("9");
         digitalWrite(4, HIGH);
         digitalWrite(5, LOW);
         digitalWrite(6, LOW);
         digitalWrite(7, HIGH);
      }
      else
      {
         Serial.println("invalid entry");
      }
      IrReceiver.resume();
   }
}

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