Need help writing a code for IR beam break sensor project

Hi, everyone, I am real new to the Arduino platform and don't have any experience with writing codes at all. Ive read some tutorials and found some sample codes on Sparkfun but its so confusing that I just don't know where to even start. I guess Ill explain what it is I am tying to do.

I have this electronic dog door that opens with a sonic collar, the problem is when my beagle "Diesel" stands in the door to smell outside/check the back yard, the collars signal doesn't register on the inside or outside receiver. The door works when a pet is walking to the door on either side. But when a pet stands in the middle the door closes as the sonic signal doesn't reach the receiver. It has an auto retract so it doesn't pin the pet down, but as he stands there it goes up and down hitting his head/back like every second. So I want to use a beam break sensor on the sides of the door (arrows in fist pic). Space is super limited, so I got a Mini Leonardo Pro Micro with the atmega32u4 chip 5v/16mHz. Like this: https://www.sparkfun.com/products/12640 This is the Emitter I bought and this is the Receiver

The way I want this to function is when the beam from the Emitter to the Receiver is broke by "Diesel" standing in the door opening, for the Arduino to see this and in turn close the contacts/make continuity on the open button (shown in the second pic) which in turn will keep the door up as long as that beam is broke. When the IR beam is connected (Diesel goes forward through the door, or backs up) the Open button's contacts are "opened", and the door will lower and act as it does normally. I can psychically stand there and hold the button down and the door stays up, so I know that part will work. When the button is released the door lowers. I just need to duplicate the action of holding the button down with the Arduino. I hope this makes sense.

I plan on using a small SolidStateRelay like THIS, from a 5v output from the Pro Micro through a 820Ω resistor it should activate this SSR in turn closing the contacts on the tactile button.

So I have pretty much the entire setup figured out, I just need help with the code to make all this happen like I described. Ive read a number of guides on writing codes for several hours and I just don't get it. Its so freakin confusing.

Thanks for your time, and any info would be greatly appreciated.

Jeremy



[/quote]

The receiver you linked is for receiving IR codes from things like TV remotes etc.

.

The info says it can be used both ways. "The Infrared Receiver is used to receive infrared signals and also used for remote control detection" Can it not be used to sense when the Emitter beam is present and isn't?

``Here are a couple of ways to do this I was looking at. Detecting IR beam, IR beam break Are the Emitter and Receiver that different from the ones on the Adafruit site?

Just pointing out this is for IR remote controls applications.

Did you try those examples?

.

diebog:
The info says it can be used both ways. "The Infrared Receiver is used to receive infrared signals and also used for remote control detection" Can it not be used to sense when the Emitter beam is present and isn't?

Yes, but that beam needs to be a 38kHz carrier. So even when it's "on" it's actually blinking at 38kHz; when it's "off" it's really off.

I don't quite understand, but thats ok. I guess I bought the wrong sensors. I appreciate the info. So Ill just get a set of these. Is there any problems with this choice?

So with the new sensors can someone help me with a code for those?

diebog:
So with the new sensors can someone help me with a code for those?

There's a tutorial link on the page you linked to.

I saw that but its just a demo. Im not turning on an led, but need to make continuity across the switch contacts. And the demo is for the UNO not the pro Micro

The maximum range listed for that IR TX/RX sensor pair is 20”. Is that enough for your doggie door? Maybe look at this one of these two:

They both have analog outputs, so connect it to an ADC input on your mirco. Set a threshold on the ADC reading to hold the door open when object (dog) is standing in door. Add hysteresis so that it doesn’t "chatter" when ADC output is near the threshold.

gfvalvo:
The maximum range listed for that IR TX/RX sensor pair is 20”. Is that enough for your doggie door? Maybe look at this one of these two:
IR distance sensor includes cable (10cm-80cm) [GP2Y0A21YK0F] : ID 164 : $14.95 : Adafruit Industries, Unique & fun DIY electronics and kits
IR distance sensor includes cable (20cm-150cm) [GP2Y0A02YK] : ID 1031 : $15.95 : Adafruit Industries, Unique & fun DIY electronics and kits

They both have analog outputs, so connect it to an ADC input on your mirco. Set a threshold on the ADC reading to hold the door open when object (dog) is standing in door. Add hysteresis so that it doesn’t "chatter" when ADC output is near the threshold.

Thanks for the question. Ya 20" is plenty. Opening is like 12" If i were to use one of those you suggested, I don't quite understand how to do what you say. I get the concept, but how to make it do that is where I am lost.

So I tried ordering that IR beam break from Adafruit but 2 days after I placed order they messaged me that its out of stock (they were in stock when I placed the order). So I asked to have the other 2 sensors mentioned above in place of what I ordered. Instead of doing what I asked they decide on their own to cancel my entire order (I ordered a few other things at the same time). I was like what the heck? I sent a email asking why they did that and here is what they said: "We have refunded your order in full and canceled it". I responded "you didn't answer my question" they never replied back or explained why they chose to cancel my entire order when I did not request so. So that will be the LAST time I ever buy from Adafruit! If they cant do their job correctly and don't want my business then forget them! Ive never delt with such incompetence before. It was like I was buying from a foreign company and there was language barrier problems. I don't have the time or patience for that.

Anyway, I am back to the stuff I have. Is there anyway I can get this Emitter and Receiver I bought previously to work? I realize now it was intended for remote control applications, but isn't it based on the same technology? There has to be a way to get this to work. If I were to remove the LED off each board would that not act the same as the ones from Adafruit? If someone can help me with these I would really appreciate it allot!.

Thanks,

Jeremy

Hmmm, I’ve always had good experiences with Adafruit.

Regardless, it might be a little involved to get your Grove units to work for this application. The RX requires the light to be modulated at ~38kHz with pulse burst coding on top of that. You could probably modify their example sketches to accomplish this. Send continuous fixed codes or even incrementing packet sequence numbers. Assume the light is blocked when you stop receiving the packets after a predetermined time.

I sort of understand what your talking about, but actually doing it I am lost. In my head arent both the (datasheet for QT50CM sensor on Adafruit) and the Grooves emitters putting out the same thing when voltage is applied? Besides the extra components on the groove board aren't they basically the same thing? Both have IR LED emitters and Exactly the same looking Receivers. What I mean is the emitter is a blueish/clear 2 pin led and the emitter is a black colored 3 pin led. If I were to remove them from the groove board and wire them the same as in the Adafuits demo, they wouldn't work the same? Im guessing by everyone's response on these that the answer is no, I just don't understand. What makes the QT50CM emitter and receiver different from the emitter and receiver on the groove?

See data sheet for the actual IR receiver on the RX board:

It requires a modulated, burst pulse-coded signal.

So how is this done? This is what I just don't understand

diebog:
So how is this done? This is what I just don't understand

Start by trying out the Grove example sketches. Figure out how they work and then how they can be modified to do what you want. Post questions detailing what you've tried, how it behaved, and how that behavior was different than what you need it to do.

diebog:
So how is this done? This is what I just don't understand

This doesn't need to get too complicated. The main thing is you need a way to create a 38kHz carrier from the emitter so that the receiver can see the IR. Remember, that receiver doesn't see IR that's solid on, it only sees IR when it's blinking at 38k. These receivers are active low: that means the output is high in the absence of a 38k signal, and it goes low in the presence of one. If you simply hook that receiver up to 5V and gnd, you will read 5V across gnd and RX in the absence of a 38kHz carrier.

So, how to create a 38kHz output from your emitter, that's the question? I'v only ever done that with a 2 pin led but yours is on a module and has 3 pins. Seems to me, you provide it with 5V and gnd, then use the Tx pin to turn it on and off. You need to do that very quickly to get 38kHz.

One way, is to use the Arduino tone() function like this:

byte myPin = 2;
void setup()
{
tone(myPin, 38000);
}
void loop()
{
}

With the tone() output to the emitter Tx pin, it should blink at 38kHz and satisfy the receiver. (YMMV: I've never used that Grove emitter as I said, only the loose LED, but I think that's what the Tx pin is for.)

With the emitter sending its 38kHz beam at the receiver, which would have been showing 5V output in the absence of the 38kHz carrier, that output should drop to 0V (it's active low, remember). You can just measure that with a meter, or stick an LED/resistor over the pins, with the anode on Rx and cathode to gnd. (There might even be an indicator led on the module?)

You just need to connect the receiver Rx pin to an Arduino pin and digitalRead() it to see what it's doing.

Once you have that sorted, and only then ;), look at using that output to do what you actually need your project to do.

(A word on being active low: the Vishay part is active low, it says so in its datasheet. I assume the Grove output will be active low too, and that they didn't do anything in the electronics of the module to invert that. If they did, no matter: Rx will be low in the absence of the 38kHz signal, and high in its presence.)

Hope that helps?

Thanks for that in depth answer manor! I am sort of getting it now.

There is only a small resistor and cap to reduce supply ripple for VS.

In the photo bellow are some other receivers I have from various tear-downs as well as the 2 groove boards. Would any of them work?