help with ir receiver output

Hello,

I have a dfrobot 38khz ir receiver module and I am having trouble using the output with any other code. When I use this code, check the serial monitor I get the correct value when I press button 3 on the remote "219E708F".

Now my problem is I cannot seem to do anything with that value. Its like it shows correctly in the serial monitor, but in reality its not the actual value. The problem lies somewhere in the if statement for the digital pin 7.

/*
 * IRremote: IRrecvDemo - demonstrates receiving IR codes with IRrecv
 * An IR detector/demodulator must be connected to the input RECV_PIN.
 * Version 0.1 July, 2009
 * Copyright 2009 Ken Shirriff
 * http://arcfn.com
 */
 
#include <IRremote.h>
int RECV_PIN = 11;

IRrecv irrecv(RECV_PIN);
 
decode_results results;
 
void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
  pinMode(7, OUTPUT);
  digitalWrite(7, LOW);
}
 
void loop() {

  if (irrecv.decode(&results)) {
    Serial.print(results.value, HEX);
    Serial.println(" ");
    Serial.println(" ");   
    irrecv.resume(); // Receive the next value
  }

  if ((results.value, HEX) == 219E708F) {
    digitalWrite(7, HIGH);
    delay(1000);
    digitalWrite(7, LOW);
  }

 
}
  if ((results.value, HEX) == 219E708F)

Try this instead

    if (results.value == 0x219E708F)

You cannot invent arbitrary format specifiers for results.value just because you can use that format in Serial.print(). The 0x on the start of the value to be compared indicates that it is a hex number.

That does make sense. Also explains some of the errors I was getting.

Unfortunately it still results in nothing happening on pin 7. I am not sure what I could do to troubleshoot this.

You could post your revised code and a sample of your debug output.

I actually found some different code that works for my scenario.

Dan.

#include <IRremote.h>

#define button1 564009191
#define button2 564041831
#define button3 564031631
#define button4 16716015
#define button5 16726215
#define button6 16734885
#define button7 16728765
#define button8 16730805
#define LED1  11
#define LED2  12
#define LED3  9
#define RECV_PIN  10
#define del 50
#define flashNumber 100



int times ;
IRrecv irrecv(RECV_PIN);
decode_results results;
long lReceived = 0 ;

void setup()
{
  pinMode(LED1, OUTPUT);
  pinMode(LED2, OUTPUT);
  pinMode(LED3, OUTPUT);
  pinMode(RECV_PIN , INPUT);

  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
 
}

void loop() {
  if (irrecv.decode(&results)) {
    lReceived = results.value ;
    Serial.println(results.value);
      switch (lReceived) {
    case button1:
      digitalWrite (LED1, HIGH);
      delay(200);
      digitalWrite (LED1, LOW);
      Serial.println(LED1);
      break;
    case button4:
       digitalWrite(LED1, LOW);
       Serial.println(LED1);
      break;
    case button2:
      digitalWrite( LED2, HIGH);
      Serial.println(LED2);
      break;
    case button5:
       digitalWrite(LED2, LOW);
       Serial.println(LED2);
      break;
    case button3:
      digitalWrite (LED3, HIGH);
      delay(200);
      digitalWrite (LED3, LOW);
      Serial.println(LED3);
      break;
    case button6:
       digitalWrite(LED3, LOW);
       Serial.println(LED3);
      break;
     case button7:
       times = flashNumber;
flash :
     
       digitalWrite (LED1, LOW);
       digitalWrite (LED2, LOW);
       digitalWrite (LED3, LOW);
        if (!(times--))
       {
         goto brk ;
       }
       
       //delay(del);
       digitalWrite (LED1, HIGH);
       delay(del);
       digitalWrite (LED1, LOW);
       digitalWrite (LED2, HIGH);
       delay(del);
       digitalWrite (LED2, LOW);
       digitalWrite (LED3, HIGH);
       delay(del);
       goto flash ;
brk:
       break;
   
     
    }
    irrecv.resume(); // Receive the next value
  }
}
//*****************Code Ends  Here***********************
         goto brk ;
       goto flash ;

No comment.......

Not using that part, and its not my code...

UKHeliBob:

         goto brk ;
       goto flash ;

No comment.......

Is this more to your liking king UKHeliBob!

#include <IRremote.h>

#define button1 564009191
#define button2 564041831
#define button3 564031631
#define LED1  11
#define RELAY1  9
#define RECV_PIN  10
#define del 50
#define flashNumber 100

int times ;
IRrecv irrecv(RECV_PIN);
decode_results results;
long lReceived = 0 ;
long relaystatus = 0;

void setup()
{
  pinMode(LED1, OUTPUT);
  pinMode(RELAY1, OUTPUT);
  pinMode(RECV_PIN , INPUT);
  digitalWrite(RELAY1, HIGH);
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
}

void loop() {
  if (irrecv.decode(&results)) {
    lReceived = results.value ;
    Serial.println(results.value);
    if (results.value == button1) {
      Serial.print("button1");
      Serial.println(" ");
      digitalWrite (LED1, HIGH);
      digitalWrite (RELAY1, LOW);
      delay(200);
      digitalWrite (LED1, LOW);
      digitalWrite (RELAY1, HIGH);
    }
    if (results.value == button2){
      Serial.print("button2");
      Serial.println(" ");
      if (relaystatus == 1){
        Serial.println("relay was already on, turning off");
        Serial.println(" ");
        digitalWrite(LED1, LOW);
        digitalWrite(RELAY1, HIGH);
        relaystatus = 0;
      }
      else {
      Serial.println("relay was off, turning on");
      Serial.println(" ");
      digitalWrite(LED1, HIGH);
      digitalWrite(RELAY1, LOW);
      relaystatus = 1;
      
      }
    }
 
    irrecv.resume(); // Receive the next value
  }
}

Much better.
Did I mention that another rule of my kingdom is that each brace goes on its own line so that code blocks are more obvious :slight_smile:

      Serial.println(" ");Why ?

UKHeliBob:
Much better.
Did I mention that another rule of my kingdom is that each brace goes on its own line so that code blocks are more obvious :slight_smile:

      Serial.println(" ");Why ?

Really, I have to explain that?

Really, I have to explain that?

Probably - it seems to me fairly unusual to print a space on its own line, but you may have a good reason we can't see.

Back in The Bad Old Days of mechanical Teletypes, after sending a carriage-return, you had to send a few padding characters or pause to allow the head to move to the start of the line, before sending any new data.
Perhaps you have a similar situation?