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

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.


I would put the whole litter box on a scale (ie, weight sensor). When the cat gets in, it'll register heavier weight, and when the cat leaves, lower weight. You could even make statistics on how much "stuff" the cat left in the litterbox...

You can get a sensor for free in a busted kitchen scale. Or you could just use a switch under a spring, adjust spring strength so it doesn't switch with just the litterbox, but it does switch with a cat on top.

Note this doesn't detect movement (ie, cat goes through the opening), it detects a state (cat inside the box or not) which gives more information.

Unlike IR sensors, weight sensors consume very low power, which is an advantage if the thing is battery powered.

Failing that, you can get readymade IR trip sensors for so cheap that it isn't worth rolling your own. These things are commonly mounted on shop doors to ring a bell when a customer enters.


I think you could use a set of IR receiver modules and LEDs opposite (typically you'd pulse them at something like 38kHz, a 555 would work, the frequency should match the receiver modules). Put the IR receivers and transmitters in black tubes (rectangular or round) to limit their field of view.

The modulated light and optical filtering greatly reduces the sensitivity to ambient light.

If any of the receivers are obstructed then that would be interpreted as an object in the way. Since the module linked above has a low output when the modulated light is detected, you would want an 'n' input "AND" gate to detect the loss of any signal.

Edit: As @Chris mentions in a comment, should pulse the modulated light so the on-chip AGC can do its magic. So you may as well use something like a $2 Arduino Nano to generate the pulses, do the AND gate and do whatever other logic makes sense. You would want to use a 5V module in that case.

Tags:

Sensor