Simple IR communication between Arduino's

Hello. This is my first post on this board.
First of all, I would like to say that I do not own a Arduino [yet]. Later this month I will probably have an UNO and a breaduino with ATMEGA328. I have written about 6 sketches in the past different from the basic examples, so this is not my first sketch. I don't want to annoy anyone with doubts about a product I don't have (if I do, my apologies), but my questions are on how to create a design rather than improve/ correct any errors in an existing design.

So, the basic idea is having an Arduino (UNO) communicating via IR with a breaduino (equal to UNO) in a simple way. And by simple, I do really mean simple - I just want to send a simple constant value from the original board to the breadboard one (at this point I will just want to send a unique value, in the future I plan to add 2 more). This value will activate a digitalWrite on the breaduino that will power a transistor with some resistors between that digital pin and the transistor base (but at this point, I want to light up just a led untill I don't understand the inner workings of the communication).

Essentially, the original UNO is a remote and the breadboard one a receiver.
From what I can tell, not having a protocol/ frequency defined is good in this case as I can create something simple - the only problem is that I am not sure on which IR to use and how to write the code so I can send a 5ms signal that can be understood at a distance of 5~10 meters.

I wrote this piece of code for both "remote" and receiver:

REMOTE

//Modulo Emissor
//ARDUINO UNO c/ ATMEGA328
//Ao pressionar de um botão é enviado um pulso de 5milisegundos para o emissor IR.

int IRout = 12;
int PULSE = 5;
int ChargingTIME = 1200;
int FIREpin = 11;
int FIREpinpressed = 0;

void setup()
{
  pinMode(IRout,OUTPUT);
  pinMode(FIREpin,INPUT);
}
void loop()
{
  if ('digitalRead(FIREpin) == HIGH')
     {
     FIREpinpressed = 1;
     }
     else
     {
     FIREpinpressed = 0;
     }
     
  if ('FIREpinpressed = 1')
     {
     digitalWrite(IRout,HIGH);
     delay(5);
     digitalWrite(IRout,LOW);
     delay(1200);
     FIREpinpressed = 0;
     }
     else
     {
     digitalWrite(IRout,LOW);
     }
}

I am portuguese, by the way, so I will just translate the comments/ explain the code.

-A pushbutton on digital port 11 (FIREpin), when pressed, will set FIREpinpressed to 1;
-When FIREpinpressed equals 1, a 2-pin Infrared emitter on digital port 12 (IRout) will be powered for 5ms (PULSE) and set FIREpinpressed to 0 when that 5ms period ends;
-chargingTIME is a variable not used at the moment, but it will disallow the setting of FIREpin to 1 for 1200ms after the end of the 5ms period.

RECEIVER

//Modulo Receptor
//ARDUINO UNO c/ ATMEGA328
//Ao receber o  pulso de 5milisegundos, serão emitidos 5V@40mAh através de uma 
//porta IO.

int IRin = 12;
int PULSE = 5;
int ChargingTIME = 1200;
int LEDpin = 13;
int STATUS;

void setup()
{
  pinMode(IRin,INPUT);
  pinMode(LEDpin,OUTPUT);
}
  
void loop()
{
  STATUS = digitalRead(IRin);
  if ('STATUS == HIGH')
  {
    digitalWrite(LEDpin,HIGH);
  }
  else
  {
    digitalWrite(LEDpin,LOW);
  }
}

-After receiving the 5ms pulse (PULSE) on digital pin 12 (IRpin) via Infrared receiver(2 legged IR), STATUS will be set to HIGH and digital port 13 will be activated and send 5V@40mAh to the transistor;
-If STATUS is equal to LOW, digital port will not be activated.

My understanding over this subject tells me some things that suggests me that this design (both code and hardware) will not work. That is somehow related to my lack of knowledge over this.
Firstly:
-Whats the difference between an IR LED with 2 and 3 legs? [I believe it's the frequency they work in, while 2 legged IR would require arduino/ 555 IC to modulate a frequency (commonly 38.4kHz), 3 legged IR would be capable to modulate that frequency];
-I know there are IR emitters with 3 and 2 legs (pins), but are there IR receivers with 3 legs?;
-Distance that IR beam can travel depends on its model, but would it be possible for a IR receiver to receive a 5ms beam at a 5meters distance from the emitter?;
-If I would like to modulate the beam at a 38.4kHz for 5ms, then 5/38 ~= 0.13 and 0.13/2 = 0.065ms = 65us. So, I would have to light up the IR emitter for 65us, power it down for another 65us and repeat that 38 times? [I believe I know how to write the code for emitting, but how should I proceed to only allow write on digital port 13 only if that sequence/ frequency (I'm not sure on what to call it)?;
-Would pulseIn work with 38.4kHz frequency? I have a doubt on using it because of the distance the beam can travel and, what if a infrared beam comming from some other place (just trying to prevent noise to trigger digital port) irradiated the IR receiver? I have no time limit on IR wave exposure, if that supposed unwanted IR beam was larger than 5ms, wouldn't it trigger the digital port?

I read many topics, codes and analysed circuit designs before coming here. I am not on my computer right now, but when I get there I will upload a circuit design just to make things clear. Until then,

Thanks in advance,
Nuno Garcia

Walk first.. then run...

It is very easy to get started. From the start I propose, you can go on, build up your application as far as you can be bothered, including to the destination I infer from your post....

Start:

Use your TV's remote control to send signals to....

An Arduino set up to read what the TV remote is sending.

The above is covered at the following site.

Thanks for the quick reply.

I could have been more clear on that matter, but I am somewhat confused.
I wrote "IR LED" because I believe that could apply to emitter or receiver or even a phototransistor.
For example, if I check Radioshack's website, i find these:

A phototransistor transforms received light into current or voltage, could it be used on a TV infrared receiver module?
A Infrared LED (2nd one), I don't believe it could be used in a TV remote.
Infrared emitter and phototransistor. An emitter and a phototransistor on the same package. That kinda confirms my doubts on phototransistor as TV receiver.
And lastly, 38kHz IR receiver module. This I can see it has 3 legs. I believe it does the reverse process of using an 555 IC and a IR emitter (for example, Arduino sends a 5ms beam and the IC converts it to a frequency and the 3 legged receiver does the reverse, sending a 5ms beam to Arduino receiver).
If there are receivers that "decript" that frequency, if my thoughts are correct, why aren't there 3-legged IR emitter modules? (I also do not believe I've seen any)

The use of this IR on the "remote" and receiver Arduino would be a hour before the sun goes down and 1 hour later after the sun rises. That way almost no sun light could interfere with the communication.
I do not know what IR's to buy, I'm delaying everything including the purchase of Arduino (which I will buy) to be sure from what I need to buy because I will not have much money after buying them (5~6€) and I would like to purchase everything from the same shops in order to reduce the shipping taxes. As result, I do not know the characteristics of the IR's I will use.
When I said receiving at a 5meter distance, I meant optimal communication and almost no interference. If I look to a TV remote it can, but...

If I would like to modulate the beam at a 38.4kHz for 5ms, then 5/38 ~= 0.13 and 0.13/2 = 0.065ms = 65us. So, I would have to light up the IR emitter for 65us, power it down for another 65us and repeat that 38 times?

I do not really know the road to follow. I read in other topic about sending a pulse like that. I understood what was done and tried to create something that might (probably not) be a solution to part of the problem. I believe it's the hard way, because I have no protocols established, but I am trying to save work to the people that would help me. :open_mouth:

It might, but why would you want to go to all that trouble when you can buy an IR receiver with the 38KHz discriminator built-in to the receiver? And available at a very low price (US$1~2)

I asked that because of my doubts on emitters and receivers... =/

IR transmission of files, like in cellphones, happens by sending all those 0 and 1. I'm rather more interested on the beam length than what it sends. And that's why I mean simple.
I will explain better:
-A 5ms beam from the "remote" Arduino to the receiver arduino would trigger digitalWrite on port 13. That would light up a white LED. But what if I would like to change the color (change digitalWrite to other pin with other LED and a different colour)? If I pressed button Y it would send a 20ms beam and change the IO port to 5, for example, and light up a red LED. If i clicked X button it would send a 40ms beam and change the IO port to 7 and light green LED.

Thats not the code I wrote in the sketch, but I believe that would help understanding better what I am trying to do here.

The design: (red LED = IR led)

REMOTE

RECEIVER

Thanks In advance,
~Nuno

I googled IR remote Arduino and I came up with some helpful things you should look at. You might fine exactly what you need.

http://www.arduino.cc/playground/Code/InfraredReceivers

nunogarcia:
If there are receivers that "decript" that frequency, if my thoughts are correct, why aren't there 3-legged IR emitter modules? (I also do not believe I've seen any)

I wish I knew why they didn't exist; would have certainly saved me a lot of time :). You can find "IrDA transceiver" modules that handle all of the 38Khz stuff for you and give you a TX and RX pin.

Be careful when selecting a (3 leg) IR receiver module; some enforce pauses in the data transmission (Sony, RC5, NEC protocol, etc.) as a method of eliminating noise.

LED = light EMITTING diode

I know what LED means, I really do. But I just spell LED and, speaking another language rather than english, I don't allways look at the meaning of the word. Still, embarrassing.

What do you mean by "used in a TV remote"? If you mean to build a sending unit (the thing you hold in your hand with all the buttons), then that kind of LED is exactly what those remotes use to SEND the IR signal. Why would you think it could not be used?

Yes, precisely, a sending unit. It's just because of the product names. LED emits light and an emitter does the same. I just tough because of the names being different they would not do the same thing (language problem, again).

What are you talking about? If you mean the third photo from Radio Shack, they are referring to two separate devices as shown in the photo. They sell them as a pair for convenience of the customer. They are presumably matched so that the phototransistor is matched to the emitter.

Forget what I just said. I did not thing they would come in a single "unit", if I can call it that way.

You seem very confused. That kind of phototransistor could be used for a TV receiver, but we have integrated receiver modules today, so we don't have to fool around with building our own 38KHz discriminator circuits.

Because, typically they design TV remote control senders for very low cost and they do the 38KHz modulation directly from the microcontroller.

With this said, many of my doubts have been clarified (on the hardware part, of course). Thanks =).
Those were my main concerns about IR LEDs and receivers.

I am very confused I don't know what you are trying to do if you say "communicating" but you aren't interested in what it sends.
If you are trying to "communicate", then what it sends (and receives) is the primary concern, I would think.

I've also though that, it is not a real "communication", but then what would I have written on the topic name?

Yes, you could use the length of the pulse to send different "messages" but that does not seem like a very reliable method.
Why would you not use a more conventional method like sending digital characters using the serial encoding/decoding UARTs built in to Arduino?

I will do a deeper search on UARTs, as I am not familiar with the meaning.

Note in your diagrams, connecting an LED directly to Arduino will risk burning out the Arduino. NOT recommended! Always use a series resistor to limit the LED current to a safe value.

I will explain why my circuit was not better conceived. I was travelling by train (with stops in the middle) and there was no internet connection. In one stop there was a free internet zone and I had to hurry and answer, so I did not spent many time on the circuit (you can see that). A 180Ohm resistor between the anode and the IO port will keep me out of trouble.

Sorry if I seem to know nothing or so, but this is my first time working around with microcontrollers. I deal with electronics since I was about 6 years old but I never done anything related to microcontrollers, just comparators, audio amplifiers and not much more besides that.
I am not blaming my language or so, but really, some of my doubts are about the terms used and how they relate with these specific parts.

@cyclegadget

I folowed up those links you gave me (I've checked the playground page before) and I've searched with the very same tags on google, so I ended up with a bunch of links that I already have visited. But thanks, still =)

I will try to create a code that is remote similiar to do this, but I do not master, by far, this languange. I'll keep posting details.

@Chagrin

Thanks for your reply.
I am not planning to buy a module. However, if I create a Sony/RC5/etc similar circuit, can I use RX and TX without a module?

~Nuno

I am not planning to use serial. Arduino will not be connected to the computer during this "communication".

What I am trying to do ism after pressing a button on the main (remote) Arduino, it will send a signal via IR emitter to the (receiver) breadboard Arduino IR receiver, and when it receives this signal it will do:

digitalWrite(13,HIGH)

and light up the on-board LED on that pin.
I first though the best way was to light up the IR emitter on the main Arduino for 5ms and the receiver Arduino should preform digitalWrite if a beam of IR light would "touch" (i can't remember a better word right now) it's IR receiver for a period of 5ms. For example, 5ms would have that function while 6ms, 1ms, 100ms or other values would not mean anything to the breadboard arduino. However, in the future, I might add more functions with different periods of beam, but for now I just want one function. I don't know how to write the sketch for the receiver arduino, but I think it will be based on pulseIn.
However, after writing this topic, I found new things about IR and I am not entirely sure on how to use it.
Would I be better off using a code similar to a TV remote (as there are sketches on how to read them and send them) rather than creating a new method, like I explained above?

~Nuno

  1. You seem to have invented a communication protocol where the length of the pulse indicates different things. The problem with that scheme is that if the beam is interrupted, it scrambles the "message" and delivers the wrong information.

Exactly. I am now beginning the code.

~Nuno