How to use two (2) or more infrared LEDs

Hi guys, i couldn't find any topic about my question, so i'm coming here... Really sorry for anything...

I need to use 2 independent IR LEDs controlling 2 different air conditioners (in different times). These air conditioners share the same remote control and i need to make an alternance between these equipments, so i just need to put 1 LED near to each of their infrared receivers and i'm done (this way the LEDs can control only the equipment nearby).

I already use 1 LED in one air conditioner, by the port 9 (default port for this) of an Arduino Mega 2560. I just can't find a way to use one more LED in the other, using the same arduino.

I didn't find a code declaring which port the LED will use, it's like something declared in the library, i don't know exactly yet. But even if i modify the library, telling the Arduino i'll use another port, how could i say "one Led will use port 9 and other Led will use port X"?

I'm using the example codes of the IR library for the testes.

Sorry for anything with the english, i speak portuguese and Google Translator sucks. hahaha.

Thank you for any help, guys! I'm really looking forward about this, i need to finish my project.

It you want to differentiate between the two of them you're going to need to pulse them at different frequencies. I would think there'd be another topic on IR LED emitting at a certain frequency using registers/interrupts.

I don't know why but i'm not finding anything in the forum now! No motter the words i use, i get no results.

I coudn't find the topic you said. =/

See the posts towards the end of this thread.

Something similar to this may help as well.

marcelino:
I'm using the example codes of the IR library for the testes.

You might want to look up testes in the dictionary :slight_smile:

Post your code.

...R

hahahaha!

Yeah Robin2, "testes" is wrong, fine, but you understood. I meant tests. (tests = testes in portuguese.. =P)

I'm using the example codes of Ken Shiriff's library, the sketch "SendDemo" (something like this, it's the one which only sends IR). I'm not at home now, so i can't confirm that to you. I'll post again later with the code.

DivinityArcane, i'll check it out! Thank you!!

Hugs.

marcelino:
but you understood. I meant tests.

I actually thought you meant "testers"

...R

Why not use a tiny85 for each AC unit?
http://www.hackster.io/rayburne/infrared-dedicated-decoderinfrared-dedicated-decoder

Ray

Hey, Robin, i'm back with the code (sketch from Ken Shiriff's library)... It's just to send the ir for tests.

/*
 * IRremote: IRsendDemo - demonstrates sending IR codes with IRsend
 * An IR LED must be connected to Arduino PWM pin 3.
 * Version 0.1 July, 2009
 * Copyright 2009 Ken Shirriff
 * http://arcfn.com
 */

#include <IRremote.h>

IRsend irsend;

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

void loop() {
  if (Serial.read() != -1) {
    for (int i = 0; i < 3; i++) {
      irsend.sendSony(0xa90, 12); // Sony TV power code
      delay(40);
    }
  }
}

DivinityArcane:
See the posts towards the end of this thread.

Something similar to this may help as well.

DivinityArcane, this apparently looks to be a solution! Unfortunately not so simple as it is when we use the default pin (9 on mega), because of the tons of work, but it might solve the problem, at least for now... Thanks!

I just consider unbelievable the fact that Arduino (or the libraries we have today? I guess this is the limitation) doesn't allow us to use more than one pin for the IR SENDING (not only pin 9).

Hugs, my friends!! And thank you one more time... let's see if this solution works... I'll post a feedback.

The examples you see are made to be simple. Any Arduino can do what you want, not just the expensive MEGA2560. Just about every pin is capable of running the led one way or another. Not all at the same moment but capable. The MEGA is overkill.

The ATtiny85 chip costs about US$1+change. It can run the IR led by itself and give you a few buttons or control wires. You would program the chip with your Arduino and keep your expensive MEGA2560 Development Board for the next thing. There are tutorials and videos on how to use stand-alone AVR chips to do these things, it is not major difficult. At the very least you can use a smaller, cheaper board like a Micro for the finished task.

I recommend getting each IR to air conditioner working separate. There will be time spent finding out which of many speeds and methods the air conditioners use. Not all IR is same speed and protocol so there will some trying even if just once.

There should be nothing special about digital pin 9 on the Arduino. Any of the other PWM capable pins should work just as well.

Just correcting my last post: it's not only the pin 9, it depends of the library. We can edit the ".h" library and change the default pin. The problem is to use only ONE pin to send the ir value.

GoForSmoke, actually i'm using the mega because the ir control is part of a long code i'm using to automate a data center of a company, with an online interface in html, buttons (control the two air conditioner - only one yet), data (temperature and humidity), GSM shield (to call someone when the room gets hot) and everything else. If i had two different equipment (using different remote controls) i wouldn't have a problem right now. As the air conditioner uses the same remote control (the same ir frequencies for the same functions), i need these "two ports" for two IR LEDs send the ir to each of the air conditioners.

I do believe that if the library had something to allow us to choose in our sketch which of those pins (two or more, defined in its program) we want to use, everything would be easier.
Unfortunatly i know nothing about how to write a library, so i couldn't help more than with my ideias...

The example codes are just to simplify the work while testing this function. When everything works fine i copy and paste the "example" in my code.

I'll study about this ATtiny85 anyway.

:smiley:

Can you link me this library? There's no reason for them to use a static pin. I'll rewrite the portion that needs it if it's not too convoluted.

Seeing as how there's a need for the MEGA, you might as well use it.

I don't know the IR library but it probably makes one IR emitter as a C++ object.
In your case, you need two of those, each with its own pin.
I don't know what you may need to do to get that but pretty sure you should be able.
Don't bother with the Tiny's unless you really want to.

DivinityArcane:
Can you link me this library? There's no reason for them to use a static pin. I'll rewrite the portion that needs it if it's not too convoluted.

Divinity, that would be just great! You are A+++++++! ;D ;D ;D
I attached the zip file with the library here.

I'll be looking foward!

GoForSmoke:
In your case, you need two of those, each with its own pin.

Duplicating the IR library (with different names) and use each of them with different "includes" inside my code? Huuuummmmm... I hadn't thought about that... It looks an excelent (and possible) ideia for me! It's at least worth the shot!

IRremote.zip (32.3 KB)

Don't duplicate the library. That's a waste of memory and not necessary. I'll take a look at it.

Edit: I see. It uses the chip timers of your Arduino, which do use specific pins. You're going to need to either create a copy after all or find a better library for IR functionality that provides you with a way to choose the timer upon initialization, rather than hard-coded variables.

DivinityArcane:
You're going to need to either create a copy after all

See? That's what i was talking about...

DivinityArcane:
or find a better library for IR functionality that provides you with a way to choose the timer upon initialization, rather than hard-coded variables.

The HUGE problem is that... finding another library to provide me this functionallity... That's why i got so excited when you said you were gonna try to write something for the library... hahaha

It's definitely possible to refactor the library. I would think there'd be better libraries out there, though.

marcelino:
Hey, Robin, i'm back with the code (sketch from Ken Shiriff's library)... It's just to send the ir for tests.

I don't know the Library you are using so I have not commented on it.

This a just an "outside the box" idea ...

If you want to send codes to two different LEDs using the same Library one way might be to control the LEDs through an external AND gate (eg 74HC08) and use a couple of other pins on the Arduino to select which LED is active. Then the same Library instance can control either LED and does not need to know which LED it is controlling.

...R

Robin2,
If i have to use external circuits, i'd rather using a relay module. But it's one more ideia to the folks...

I tried to use the intervalometer but at a first moment i couldn't decode the ir signal by this method... i didn't try a second time yet...

I'll post the results soon...

Divinity, have you discovered anything else?

:grinning: