TinyCircuits Forum

TinyCircuits Products => Wirelings => Topic started by: lcpalm on May 06, 2022, 06:55:25 PM

Title: Using Wireling IR-Emitter and Receiver to detect beam breaks?
Post by: lcpalm on May 06, 2022, 06:55:25 PM
Hi TinyCircuits,

Question: Is it possible to use the Wireling IR-Emitter and Wireling IR-Receiver to detect simple beam breaks using a TinyZero?

I'm trying to convert a circuit I built using a TinyZero, to Wirelings. This had used a simple non-wireling IR-emitter LED and IR-detector pair  (https://www.sparkfun.com/products/retired/241), soldered in to a tiny shield with appropriate resistors; the IRD required a 10kOhm  pull-up resistor. (It reports a beam break when you block a porthole with an IR illuminator-detector pair on either side, at a sample rate of about 20ms, and writes to microSD.)

I was able to get this working with the same resistors by cutting a Wireling cable and soldering the old IR-emitter and detector up with their same appropriate resistors inline (including the 10k Ohm pullup for the IRD and a 220ohm resistor for the IRE) to the Wireling cable. This uses the Wireling library, but doesn't use the IRremote library.

But it would be much nicer to use the actual Wireling IR Emitter and Wireling IR Receiver and avoid the need to solder in resistors!

I've gotten the Wireling IRE and IRD to send and receive "IR codes" from your tutorial examples on my TinyZero (although the interrupts were a bit of a mystery),  but can't seem to get the IRD to recognize the mere presence or absence of a signal from the IRE  - and am not even sure if have managed to send the signal in that mode.

 I'm attempting to adapt this code :
http://www.righto.com/2010/03/detecting-ir-beam-break-with-arduino-ir.html

One problem : The Wireling IRD TSOP572 datasheet says it suppresses "Continuous signals at any frequency", which that page says will prevent the code from working -- There's some workarounds for this in some comments on that page but I have not been able to get them to work. I don't have a good enough understanding of how the IRremote library and Wirelings work together to adapt them to get the IR-emitter to simply send a continuous signal and the IR-detector to simply detect its presence or absence.

I'd be grateful for any suggestions!

(edit: had another question about pull-up resistor use, posted that separately).


Title: Re: Using Wireling IR-Emitter and Receiver to detect beam breaks?
Post by: lennevia on May 10, 2022, 06:14:44 PM
Hiya,

I think I got the example working. It looks like the library changed the way it initiates the IRsend object since that blog was posted, so you would want to use:
Code: [Select]
IRsend irsend(PIN_IR);rather than:
Code: [Select]
IRsend irsend;
Here's the full modified example I got working with some comments. I uploaded this on a WirelingZero with ports 1 and 2. The status LED flashes when I move the Emitter away, so I believe it is working as expected, but I'm not exactly an expert on beam breaking, so let me know how it works for you!

Code: [Select]
#include <IRremote.h>

#define PIN_IR A1     // This is the IR Emitter on port 1 of the Wireling adapter
#define PIN_DETECT A2 // This is the IR Receiver on port 2 of the Wireling adapter
#define PIN_STATUS 13 // The status LED - normally pin 13 for the majority of Arduino boards

IRsend irsend(PIN_IR);
IRrecv irrecv(PIN_DETECT);

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 think this example could be improved with some output in the Serial Monitor so we know exactly what's happening since the status LED doesn't give me 100% confidence that I understand what signal's being picked up.

I hope that helps.

Cheers,
RĂ©na
Title: Re: Using Wireling IR-Emitter and Receiver to detect beam breaks?
Post by: lcpalm on May 16, 2022, 05:41:33 PM
Hi Rena,

Thanks again -- I was able to get the code you posted here working on my device, thank you.
It turns out it flashes only when the beam-break is ended (and only flashes the one time, at the end of each break, instead of giving a continuous on-or-off type signal).

It looks like this is how the IR Detector in the Wireling is designed to work. It's meant to receive IR codes, and it actually filters continuous inputs (according to the datasheet).

There are some workarounds on the link I posted for getting this kind of device to work as a beam-break but it looks like they require a delay of 60-90ms while I need less than 20ms data rate, so, I'll look for another IR-detector and hook it up to the Wireling.

Thanks very much again for your help!

(ps I deleted my comment here with a mess of code that wasn't working, hope that was OK to do - seemed better not to leave it as it was just confusing.)

Title: Re: Using Wireling IR-Emitter and Receiver to detect beam breaks?
Post by: lennevia on May 18, 2022, 11:13:44 AM
No problem! Thanks for the update!