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