IR Transmitter/Reciever
Foozah
Posts: 2
https://www.parallax.com/StoreSearchResults/tabid/768/List/0/SortField/4/ProductID/178/Default.aspx?txtSearch=ir+transmitter
https://www.parallax.com/StoreSearchResults/tabid/768/List/0/SortField/4/ProductID/177/Default.aspx?txtSearch=ir+transmitter
Currently I am playing with these sensors using Arduino. I want to produce a steady beam and alert when that beam is broken.
[HTML]
#define PIN_IR 3 //analogue
#define PIN_DETECT 5 //analogue
#define PIN_STATUS 13 //digital LED
int curVal = 0; // variable to store the current value of IR sensor
int lastVal = 0; // variable to store the last value of IR sensor
int threshold = 300; // threshold to trigger alarm the bigger this is the easer it is
boolean alarm = false;
void setup()
{
Serial.begin(9600);
pinMode(PIN_DETECT, INPUT);
pinMode(PIN_IR, OUTPUT);
pinMode(PIN_STATUS, OUTPUT);
digitalWrite(PIN_STATUS, LOW);
digitalWrite(PIN_IR, HIGH);
}
void loop()
{
doWatch(); delay(20);
if(alarm) {
digitalWrite(PIN_STATUS, HIGH);
delay(10000);
digitalWrite(PIN_STATUS, LOW);
alarm = false;
}
}
void doWatch() {
curVal = analogRead(PIN_DETECT); // read the input pin
if (abs(curVal - lastVal) >= threshold) alarm = true;
Serial.println(curVal - lastVal); // debug value
lastVal = curVal;
}[/HTML]
I'm just getting constant values between like 10 and -10 no matter where I move the IR transmitter. Anyone have a clue what I am doing wrong here? It seems like the receiver doesn't recognize the transmitter. I'm a newbie so any help is appreciated!
https://www.parallax.com/StoreSearchResults/tabid/768/List/0/SortField/4/ProductID/177/Default.aspx?txtSearch=ir+transmitter
Currently I am playing with these sensors using Arduino. I want to produce a steady beam and alert when that beam is broken.
[HTML]
#define PIN_IR 3 //analogue
#define PIN_DETECT 5 //analogue
#define PIN_STATUS 13 //digital LED
int curVal = 0; // variable to store the current value of IR sensor
int lastVal = 0; // variable to store the last value of IR sensor
int threshold = 300; // threshold to trigger alarm the bigger this is the easer it is
boolean alarm = false;
void setup()
{
Serial.begin(9600);
pinMode(PIN_DETECT, INPUT);
pinMode(PIN_IR, OUTPUT);
pinMode(PIN_STATUS, OUTPUT);
digitalWrite(PIN_STATUS, LOW);
digitalWrite(PIN_IR, HIGH);
}
void loop()
{
doWatch(); delay(20);
if(alarm) {
digitalWrite(PIN_STATUS, HIGH);
delay(10000);
digitalWrite(PIN_STATUS, LOW);
alarm = false;
}
}
void doWatch() {
curVal = analogRead(PIN_DETECT); // read the input pin
if (abs(curVal - lastVal) >= threshold) alarm = true;
Serial.println(curVal - lastVal); // debug value
lastVal = curVal;
}[/HTML]
I'm just getting constant values between like 10 and -10 no matter where I move the IR transmitter. Anyone have a clue what I am doing wrong here? It seems like the receiver doesn't recognize the transmitter. I'm a newbie so any help is appreciated!
Comments
My C is very minimal, so I can't help much with code, but it appears that you are just simply lighting the IR LED. The IR receiver responds to a 38khz carrier and that may be why you are not seeing results you expect. While written for the Basic Stamp, you may want to look at the Infrared Decoding and Detection appnote that is on the LED and Receiver product pages. That may help you better understand the receiver so you can modify your code.
Good luck
I have a couple of nanos, but I'm not up to speed on your arduino deal yet.
Like WBA was getting at, you have to hit that 'receiver' with a 38kHz signal/emission, but not a constant transmission - it has to go out in bursts: several milliseconds of 38kHz, with a brief pause, repeat.
Though the receiver can be swamped by ambient IR, it's "looking" for a coherent signal
1/38000 = approx 26 usec (close enough, it doesn't have to be EXACT)
loop (infinite)
[several reps]: digitalwrite HI,
delaymicroseconds(13),
digitalwrite LO
delaymicroseconds(13)
delay(1) //
The output of the receiver will be digital 0 or 1 depending on presence of 38kHz (or not).
GASP!
PJ, does the dark side REALLY have free cookies?
All you can eat?
Previously, I was just turning to IR transmitter on and assuming the receiver would detect it. I can do the code fine once I understand how these IRs work. If you have any other thoughts, I would greatly appreciate it.
Basically with the Arduino, setup() executes once in the beginning, then loop() continues until you decide to end the program. I am assuming this syncing feature will have to happen in the loop() since it has to sync every so often.
A few years ago I made a youtube vid showing how to check a remote with one of these (similar) IR 'receivers'. It's a simple enough circuit (shown at the beginning.)
So -
I'm not advanced in the arduino drill, I only began last week. Its structure is similar to Spin (for our 'Propeller'), but you guys have to type a lot more.
Success!
With the programming below, this works with the IR_rcvr setup as noted (#6) in my youtube vid.
The confirmation LED is on till the beam is broken.
Please update (post) if you have success or need further assistance.
You've left me hangin', Bro.
I haven't looked into the "interrupt" feature, but I cranked out this much
I've stripped the comments from the above because the window blows the formatting, making it look like carp. The comments are in the PDE in the ZIP attached. The "Att.Mgr" doesn't allow PDEs, you have to ZIP them.
Anyway, seems to do the job, but I've only used/tested it on the bench.
Ought to shorten the IRED HIGH time a couple of usec - the IRED cycle time is 30usec (33kc), which is a bit (>10pct) "off freq", but still effective.
I see you guys do like place your open braces weird. It's hard for me to keep track of with your convention, but by placing them in the same column, my way, it's lots easier to see and register. It compiles just the same.
OS_IR_38kc_det.zip