0

THIS QUESTION ISN'T IN USE ANYMORE

Solved by using an other remote that is supported by the libary

====NEW CODE====

    #include <IRremote.h>

    int RECV_PIN = 11;
    int relay1 = 2;
    int relay2 = 3;
    int relay3 = 4;

    int on = 1;
    int on1 = 1;
    int on2 = 1;

    IRrecv irrecv(RECV_PIN);
    decode_results results;

    void setup()
    {
      digitalWrite(relay3, HIGH);
      pinMode(relay3, OUTPUT);
      digitalWrite(relay2, HIGH);
      pinMode(relay2, OUTPUT);
      digitalWrite(relay1, HIGH);
      pinMode(relay1, OUTPUT);
      pinMode(13, OUTPUT);
      irrecv.blink13(true);
      irrecv.enableIRIn();
    }

    unsigned long last = millis();

    void loop() {
      if (irrecv.decode(&results)){
        if (results.value == 0x36167A85) {
          if (millis() - last > 250) {
            on = !on;
            digitalWrite(relay1, on ? HIGH : LOW);
          }
          last = millis();
        } else if (results.value == 0x36161AE5) {
          if (millis() - last > 250) {
            on1 = !on1;
            digitalWrite(relay2, on1 ? HIGH : LOW);
          }
             last = millis();
        } else if (results.value == 0x3616FA05) {
         if (millis() - last > 250) {
            on2 = !on2;
            digitalWrite(relay3, on2 ? HIGH : LOW);
          }
            last = millis();
        }
        irrecv.resume();
      }  
    }

================

I'm working on this bit of arduino code for a while now but i can't get it to work. My circuit is wired up correctly, but it isn't returning any data in the serial prompt. Here is my code:

#include <IRremote.h>

int RECV_PIN = 11;

IRrecv irrecv(RECV_PIN);

decode_results results;

int main = 0;
int left = 0;
int right = 0;

void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn();
}

void loop() {
  if (irrecv.decode(&results)) {
    Serial.println(results.value, HEX);
    switch (results.value) {
      case 0x2E3A06C0:
        main = 1;
        Serial.println("MAIN: on");
        break;
      case 0x8C2921D6:
        left = 1;
        Serial.println("LEFT: on");
        break;
      case 0x226270DA:
        right = 1;
        Serial.println("RIGHT: on");
        break;
      case 0x4AC6E6A:
        main = 0;
        Serial.println("MAIN: off");
        break;
      case 0xDD5E26EF:
        left = 0;
        Serial.println("LEFT: off");
        break;
      case 0x3E5BEF99:
        right = 0;
        Serial.println("RIGHT: off");
        break;
    }
    irrecv.resume();
  }


  delay(100);
}

I'm using the libary Arduino-IRremote. When I try the demo "IRrecvDemo", it works fine. I have the hex codes from this demo. So can someone help me get this code working? It would be nice!

7
  • I'd start by troubleshooting at a hardware level first, e.g. checking with a logic analyser or oscilloscope if any 5V pulses are detected on pin 11.
    – Reezy
    May 5, 2015 at 10:34
  • I have checked it with an oscilloscope and it is working fine, but I still have the problem that it isn't returning any data into my serial prompt. Please help! May 6, 2015 at 7:04
  • My suspicion is that the IR library was unable to decode your IR signal. What kind of remote control are you using, and is it supported? Your code looks fine on face value (compared to the IR library example), so that's the only thing I can think of.
    – Reezy
    May 6, 2015 at 7:52
  • Try also the receive example from pjrc.com/teensy/td_libs_IRremote.html
    – Reezy
    May 6, 2015 at 7:55
  • This is working and it is returning data "UNKONWN: (hex code here)", when i try my code it isn´t returning data May 6, 2015 at 13:48

4 Answers 4

0

Try to put Quotation mark like this:

switch (results.value) {
  case "0x2E3A06C0":
    main = 1;
    Serial.println("MAIN: on");
    break;
  case "0x8C2921D6":
    left = 1;
    Serial.println("LEFT: on");
    break;
  case "0x226270DA":
    right = 1;
    Serial.println("RIGHT: on");
    break;
  case "0x4AC6E6A":
    main = 0;
    Serial.println("MAIN: off");
    break;

If this doesn't work too, maybe you've got a hardware problem

0

Did you try removing the 0x indicator? If I remember correctly the incoming signals are raw, e.g. 2E3A06C0, even though the script requires the 0x indicator on the send routines.

Alternatively, you'd need to rewrite, but you could try this IR Library and code, which I found has much better documentation and data analysis options on the receiving side: https://github.com/cyborg5/IRLib/

2
  • I need the 0x because it is hex, I tried the other lib but it is stil not working.... May 7, 2015 at 16:38
  • You're right. I tried to run your code without the 0x and it trips a type incompatibility error.
    – brianfit
    May 8, 2015 at 8:37
0

Well, found the problem but I don't know why. It was your variable declarations. The following code with "main, right, and left" integer variables commented out ran, the original didn't:

 #include <IRremote.h>

int RECV_PIN = 11;

IRrecv irrecv(RECV_PIN);

decode_results results;
//int main = 0;
//int left = 0;
//int right = 0;

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

void loop() {
  if (irrecv.decode(&results)) {
    Serial.println(results.value, HEX);
        switch (results.value) {
      case 0xB9F56762:
        Serial.println("MARNIX IS RIGHT");
        break;
        case 0x8C2921D6:
//        left = 1;
        Serial.println("LEFT: on");
        break;
      case 0x226270DA:
//        right = 1;
        Serial.println("RIGHT: on");
        break;
    }
    irrecv.resume();


  }
   delay(100);
}
2
  • I have it already working, but thanks! May 9, 2015 at 18:03
  • the answer is now inside the main post May 10, 2015 at 16:07
0

THIS QUESTION ISN'T IN USE ANYMORE

Solved by using an other remote that is supported by the libary and tweaking the code.

====NEW CODE====

    #include <IRremote.h>

    int RECV_PIN = 11;
    int relay1 = 2;
    int relay2 = 3;
    int relay3 = 4;

    int on = 1;
    int on1 = 1;
    int on2 = 1;

    IRrecv irrecv(RECV_PIN);
    decode_results results;

    void setup()
    {
      digitalWrite(relay3, HIGH);
      pinMode(relay3, OUTPUT);
      digitalWrite(relay2, HIGH);
      pinMode(relay2, OUTPUT);
      digitalWrite(relay1, HIGH);
      pinMode(relay1, OUTPUT);
      pinMode(13, OUTPUT);
      irrecv.blink13(true);
      irrecv.enableIRIn();
    }

    unsigned long last = millis();

    void loop() {
      if (irrecv.decode(&results)){
        if (results.value == 0x36167A85) {
          if (millis() - last > 250) {
            on = !on;
            digitalWrite(relay1, on ? HIGH : LOW);
          }
          last = millis();
        } else if (results.value == 0x36161AE5) {
          if (millis() - last > 250) {
            on1 = !on1;
            digitalWrite(relay2, on1 ? HIGH : LOW);
          }
             last = millis();
        } else if (results.value == 0x3616FA05) {
         if (millis() - last > 250) {
            on2 = !on2;
            digitalWrite(relay3, on2 ? HIGH : LOW);
          }
            last = millis();
        }
        irrecv.resume();
      }  
    }

================

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.