Electronic – what is the easiest way to make a gate that detects if something passes through a gap

sensor

I have a home project with a device with an opening that is about 20cm (8 inches) wide. I want to attach two sensors on the sides of the opening, such that if an object passes between them, a switch is shorted (either momentarily and then disconnected, or as long as the object stays in between).

What is the easiest way to do this?

I am a software engineer but I work "close to the metal" – I am reasonably good with EE: I can solder, use meters, put together my own computers from parts. If you tell me what the method is and what the required parts are, I can probably figure out the connections required.


The objects I want to detect passing, are big, at least a quarter of the size of the opening – 5 cm, and they do not move quickly – they may spend at least half a second moving through the opening.

False positives – I can have them occasionally, say once an hour. False negatives are less OK – I would like to have, say, less than 10% chance of non-detection.

The thing is on a balcony shielded from rain, sometimes it is very dark, sometimes it is sunlight.


The objects are cats 🙂 The device is a litter robot, which, while otherwise a perfect device, suffers from one stupid design choice, where a cat depresses a spring upon entering, which is highly unreliable – sometimes the spring gets "stuck" and won't depress, sometimes it stays depressed all the time, and this varies even if the spring is not adjusted and is kept clean. Detection of cat passing through the opening by means of tripping an electronics sensor would be far preferable.


I guess a single "Proximity sensor" that detects a moving object within 20cm or 8 inches, that was not there before, would be good.

Best Answer

The objects are cats :) The device is a litter robot, which, while otherwise a perfect device

If you constrain the opening at least vertically, it should be possible to arrange an optical path across the opening such that the cat's body must entirely block it at some point in the entrance. Cats will actually fit through quite small openings (if they want to) so you could even constrain the opening in width as well as height, but there's no real need to, since a break-beam system can easily cover far more distance than you need. Even with the existing opening you can probably just put the beam at a height to be broken by the center of the cats body during normal walking... they're clever creatures but they probably haven't paid enough attention that time you streamed "Mission Impossible" to hit on trying to slither underneath it in order to stealth a stinker. If there's any aversion to the "robot" give it a ten minute delay so it doesn't activate while the cat is still nearby.

In terms of actual components, you'll want to use an IR LED toggled on and off at 38 KHz, and a matching receiver which looks only for that, and ignores ambient light. Typical receiver modules also include an AGC as they are looking for bursts of pulses (eg from a TV remote) so you'll either need to get a receiver without AGC, or else have your transmitter output a series of 38 KHz pulses, give a gap, then another series so that it looks not unlike a TV remote control signal - try something like 5-10 pulses, then a gap of the same amount of time. Such a pattern is easily implemented in a small MCU, which can also help with the detection rules. So basically you have something along the lines of an "Arduino project" (/ATtiny, Cortex M0, MSP430, whatever) to pulse the LED, monitor the receiver, and then probably activate a small relay to trigger the mechanism (unless you can reverse engineer its circuitry enough to drive directly).

You'll also want to build a sort of tubular shield around the emitter and detector to make sure they only see each other directly through the a narrow region of the center of the path to be occupied by the cat.

where a cat depresses a spring upon entering, which is highly unreliable - sometimes the spring gets "stuck" and won't depress, sometimes it stays depressed all the time, and this varies even if the spring is not adjusted and is kept clean.

You could also consider some sort of flap, and detect movement of the flap optically or magnetically rather than by means of electrical contact to avoid the flaws of the present "spring"

There is another option overlooked, of detecting the cat inside the litter box. If the box is tall enough, that is the place you could potentially put an ultrasonic sensor, by having it inside looking down, but due to ringing issues these have a minimum detection distance which you may or may not be able to achieve. Such a method would definitely point to software interpretation - you need software range-gating to ignore the floor of mounded litter, and see the cat as a closer reflection; then you probably also need to entirely ignore the situation for a bit after triggering the cleaning mechanism, so you don't re-trigger off that. As mentioned in comments, the response of the cat to an ultrasonic system should be evaluated before committing to such a path. At the cost of higher power, identifying a cat inside the litter box (or at least a "blob") should also be well within the capability of computer vision algorithms watching a webcam given suitable IR illumination.

If you had an ultrasonic system with direct software signal interpretation of the received signal, then you could fire it out the door and look for a reflection from an approaching cat in addition to the spurious one from the door aperture. But the cheap "Arduino project" modules just give you the output of the first strong reflection, and you may have a lot of trouble making the door aperture not be that. Doppler ultrasound could work, too, but again points to having a far more custom circuit where you can actually see the analog response, and not just get an pre-(mis)interpreted output as from a little HC-SR04 module. One advantage of detecting the cat inside the box is that you have longer to do it, so you could have a battery powered system which polled at a much lower rate to preserve battery life, but designing systems which are truly low power without unintended power drain when they are supposed to be asleep is practically far more tricky than it first looks.

Microwave doppler motion detects exist, too. Getting one to see the cat would be easy; the problem would be having it not see far beyond the enclosure to say tree branches swaying in the wind. And doppler radar just loves fans of any sort... was testing a module and couldn't figure out why the output was incessant, until I looked up at the slowly rotating ceiling fan.