1

I have an Arduino Uno and 3 IR led's. Each of my IR led's works fine individually if I connect them to pin 11.

However I want to connect all 3 of the led's to the Uno and have them send different signals according to pin number.

e.g

IR LED 1 connected to pin 11 - send signal 0xABCDEFGH

IR LED 2 connected to pin 10 - send signal 0xSJKLMNOP

IR LED 3 connected to pin 09 - send signal 0xZXYRWVUG

I tried making my own code below but it does not work. If anyone has any pointers i'll be very happy.

//LED 1


    #include <IRremote.h>

    IRsend irsend;

    void setup()
    {
    }

    void loop() {
        for (int i = 0; i < 11; i++) {
            irsend.sendNEC(0xABCDEFGH, 32); //Settings Menu
            delay(1000);
        }
        delay(1000); //1 second delay 
    }

//LED 2


    #include <IRremote.h>

    IRsend irsend;

    void setup()
    {
    }

    void loop() {
        for (int i = 0; i < 10; i++) {
            irsend.sendNEC(0xSJKLMNOP, 32); //HDMI Port
            delay(1000);
        }
        delay(1000); //1 second delay 
    }

//LED3


    #include <IRremote.h>

    IRsend irsend;

    void setup()
    {
    }

    void loop() {
        for (int i = 0; i < 9; i++) {
            irsend.sendNEC(0xZXYRWVUG, 32); //Switch Off Monitor
            delay(1000);
        }
        delay(1000); //1 second delay 
    }
  • I don't have time to write a proper answer at the minute, but I hope this will get you started: break the problem down into parts. You have the first part working - you can send a code from one LED on pin 11. Now try to send a code from one LED on pin 12. You'll see that nothing in your code mentions the pin, so you need to understand how it's decided, or find another way to deal with using a different pin. Only THEN worry about using three LEDs at the same time. – Mark Smith Jan 18 '17 at 10:39
  • I suspect 0xABCDEFGH, 0xSJKLMNOP and 0xZXYRWVUG are replaced with some valid hexadecimal numbers. I cannot see how repeating the sent command 11 times, 10 times and 9 times (in a for-loop) correlates to the pin number each LED is connected. There is a setup missing that declares which pin irsend supposed to use. Also that code will not compile because you define irsend, setup and loop three times. You need to combine the functions and perhaps need three instances of irsend (but I don't know for sure about that because I haven't used IRsend, yet). – Kwasmich Jan 18 '17 at 10:41
  • I believe you don't understand what you are doing and you also don't tell us what you are trying to achieve. From your code I think you are trying to do a sequence of simulated IR remote presses. Why do you think you need 3 LEDs for that? Why can't you achieve that with only one LED? And why are you sending those commands every second unconditionally? – Kwasmich Jan 18 '17 at 10:45
  • Can you tell us which IR library exactly you are using? – jose can u c Jan 18 '17 at 15:16
  • I am using github.com/shirriff/Arduino-IRremote – MALKAVIAN Jan 19 '17 at 6:56
1

I think what you have done is a perfectly logical thing to do. You had three programs that worked and so you pasted them all into the same file and compiled it. The compiler spat its dummy out of the pram and you didn't understand what the h*ll went wrong. Is that about right?

// You only need to include each header file once
#include <IRremote.h>

// You need to define objects to represent the leds, we could use an array but for now we'll stick to the basics (makes the code a bit longer)
IRsend irsend_led1;
IRsend irsend_led2;
IRsend irsend_led3;

// This is where you do all the setup, it only gets executed once.
// You might need to assign the pin numbers to the irsend_ledX variables here.
void setup()
{
}

// This function is called repeatedly.  You can only have one of these.
void loop() {
    // I don't understand why you have this for loop, I think you think it may have something to do with pin numbers but I don't think it does.
    // I think the data is being sent multiple times, don't know why though
    for (int i = 0; i < 11; i++) {
        irsend_led1.sendNEC(0xABCDEFGH, 32); //Settings Menu
        delay(1000);
    }
    delay(1000); //1 second delay 
    for (int i = 0; i < 10; i++) {
        irsend_led2.sendNEC(0xSJKLMNOP, 32); //HDMI Port
        delay(1000);
    }
    delay(1000); //1 second delay 
    for (int i = 0; i < 9; i++) {
        irsend_led3.sendNEC(0xZXYRWVUG, 32); //Switch off monitor
        delay(1000);
    }
    delay(1000); //1 second delay 
}

Give that a try, it might not work, but it will be closer to what you need, I hope I have explained it well enough.

Read the manual for the IR library and find out how to set the port numbers and if you can find out what that loop is about that might help.

| improve this answer | |
  • I don't think he did have three programs which worked - I think he had one which worked. There's no clue in his code that he ever managed to get the second and third LEDs working, and yours won't either. – Mark Smith Jan 18 '17 at 14:39
  • No, because of the pin assignment, anything else? – Code Gorilla Jan 18 '17 at 14:47
  • That's the main one. It's also strange to be looping for a number of times equal to the pin number - probably a sign of not understanding something. – Mark Smith Jan 18 '17 at 15:16
  • 1
    The loop is there because I want the signal to continuously pulsate so I can test it without having to repeatedly upload code every time I want to send an IR signal. Obviously it's not perfect but I would like to keep the loop there and in any other code someone modifies and posts. That's why I included it in that format. – MALKAVIAN Jan 19 '17 at 7:05
  • That makes sense, when I read it I wasn't sure if it was a requirement of the library. There is no problem with it being there, if you can separate out the pins you might even be able to do all three signals in the one loop. However since loop() is a loop it could be that it is unnecessary, but that is up to you, you are testing it and know what is easiest. – Code Gorilla Jan 19 '17 at 8:50
1

@Matt has the main problem resolved, but I do want to add a note.

<IRremote.h> has the default IR led pin as pin 3 (last time I checked, maybe it has changed). I don't know how to change it, but if you are considering to use multiple IR leds, you might have to debug that problem!

So try to make 1 code work before you attempt to stick them togheter

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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