Table of Contents
Way back on our 2018 intake, we used an infrared break beam sensor to detect power cubes. Since we have a bunch of maller sensors left over, we wondered about using them to detect the orange cargo ball in Deep Space.
The large width of our cargo intake is too long a distance for even the larger adafruit break-beam sensor to be reliable. Give up? find an expensive industrial break-beam sensor?
Proximity sensors were suggested. But we'd need a bunch of those, since the ball can be in one of several positions across the intake. As of this writing, the rollers aren't succeeding in centering the cargo. Turns out we already have a bunch of infrared proximity sensors - the break-beam sensors can be used in reflective mode!
(drawing)
The adafruit sensors open-collector output is low when the beam is broken (not received), and high when the beam is received. Experimentally, we need 4 of them, spaced every 5 inches across the intake to sense the ball in any position. We could just run 4 cables to RoboRIO digital IO inputs, and call it good.
combining several signals into one
But can we do better and run fewer cables? Can't we wire things together somehow, and present just one signal to the RIO? Almost. Suppose we connect the 4 signal (white) wires together. What happens? The sensor's signal output is essentialy connected to ground by a transistor that turns on like a switch when the beam is broken. If we wire the signal pins together, those switches are essentially in parallel. If any one is closed, the combined signal will be low.
We can clarify this by writing out the truth table for all combinations of two sensors. Remember that the sensor output is low (closed, grounded, 0) when the beam is not recieved, and high (open, 1) when the beam is recieved.
| sensor A | Sensor B | Combined wire-AND output |
|---|---|---|
| 0 broken/dark | 0 broken/dark | 0 |
| 0 broken/dark | 1 light recieved | 0 |
| 1 light recieved | 0 broken/dark | 0 |
| 1 light received | 1 light recieved | 1 |
Unfortunately, this isn't what we want: we want to sense cargo when it is in front of any sensor - not only when it is in front of all sensors.
Exercise: write out the truth table for 4 sensors.
See https://en.wikipedia.org/wiki/Open_collector for a related explanation of open-collector outputs and wire-AND connections.
Inverting the sensor output
Wiring the signals together gives us an “AND” function: when all are 1, the result is 1. We need an OR. Turns out we can get there by creating intermediate signals, one for each sensor, that have the opposite sense:
| Original sensor output | New, inverted sensor signal |
|---|---|
| 0 broken/dark | 1 dark |
| 1 light received | 0 light |
Now, run these new, opposite signals through the same combination as above:
| inverted sensor A (“not A”) | inverted Sensor B (“not B”) | Combined wire-AND output | meaning |
|---|---|---|---|
| 0 (light) | 0 (light) | 0 | any sensor reciving light |
| 0 (light) | 1 (dark) | 0 | |
| 1 (dark) | 0 (light) | 0 | |
| 1 (dark) | 1 (dark) | 1 | all sensors dark |
By inverted the meaning of the inputs, we've arranged for the AND function to do what want: a 1 means that all sensors are dark - none are seeing reflected light from the cargo ball.
An inverter with one transistor
Here's the basic idea:
The 2n7000 is a “mosfet”, a type of transistor. It has three terminals:
- Source, (pin 1 above) which we connect to ground, or the most negative voltage.
- Gate (pin 2), an input. Voltage on the gate controls current flow between the other terminals
- Drain (3), into which current can flow
When the gate is connected to a positive voltage (with respect to the source) the source and drain are connected, and current flows from drain to source. This causes the output to be low, because any current flows to ground.
When the gate is low (near ground potential or zero volts) the transistor is off, and the pullup resistor provides a tiny bit of current to pull the output up to a 5 volts, representing a logic 1.
For a few more details on discrete mosfets for logic, see mosfet hints. For a lot more info, see https://en.wikipedia.org/wiki/MOSFET
combining open-drain outputs to make a logic gate
Finishing up:
Instead of pullup resistors, we can use a resistor in series with an LED. In fact, we can connect the output of this gate to one of our DIO tester and breakout boards.
If we build anything with mosfets as a standalone board, we never want to connect a mosfet gate only to an input connector (as drawn above for clarity). The input resistance of a fet gate is so high that can stay charged to either a logic high or low or somewhere in between. We always want to use either a pullup or pulldown resistor on a mosfet gate that would otherwise connect only to an off-board connector. Of course, if an LED is also connected to that input, it will serve to pull the mosfet gate to a defined value. Merging this gate circuit into the DIO tester board would also do that.


