Hi All,
I know this has been done to death, but I have searched all over, and have not found a solution for my issue in the forums, or anywhere else for that matter.
My project is an infrared beam break counter. There is a bit more to my project, but for simplicities sake, I will focus on the part which is giving me trouble.
I am having some trouble with an infrared receiver. I am not sure the exact model, but they are something like the PNA4602.
When I illuminate the receiver with the 38khz IR signal, it goes high for about 3 or 4 seconds, after which it seems to go unstable and flicker. If I break the beam the receiver goes low. As soon as I unobstruct the beam, the receiver goes high for a few seconds then unstable again. Process repeats.
This was havoc on my counter, as when it went unstable, it would count 2 or 3 breaks per second, when no breaks were occurring.
At first I tried to put a capacitor between +5 and ground at the receiver pins, but this just seemed to slow the flicker somewhat.
The hoped for and expected outcome, was I would shine the IR light on the receiver, and it would stay high until the beam was broken. Any ideas on why it is not doing this?
Essentially, I have reworked the code below (thanks to Ken Shirriff), and for the purpose of trouble shooting, I have used this exact code to isolate my problem.
#include <IRremote.h>
#define PIN_IR 3
#define PIN_DETECT 2
#define PIN_STATUS 13
IRsend irsend;
void setup()
{
pinMode(PIN_DETECT, INPUT);
pinMode(PIN_STATUS, OUTPUT);
irsend.enableIROut(38);
irsend.mark(0);
}
void loop() {
digitalWrite(PIN_STATUS, !digitalRead(PIN_DETECT));
}
I have followed his exact hardware setup (http://arcfn.com/images/ir-schematic.png) to begin with, then I added a 47uF cap to the input pins of the receiver. (Does it matter if the cap is polarized in this DC application???)
Many thanks in advance to anyone who can point the way!
Mike