Limit Switches and Beam Breaks
The humblest sensors are often the most reliable. Limit switches and beam breaks both answer a yes/no question and both plug into DIO.
Limit switches
Section titled “Limit switches”A limit switch is a mechanical switch that closes (or opens) when a mechanism physically pushes a lever or button. Teams use them to:
- Define a home/zero position for an arm or elevator so encoders can be reset reliably.
- Act as a safety hard stop so software can cut motor output before a mechanism crashes into its frame.
In WPILib you read one with DigitalInput:
DigitalInput topLimit = new DigitalInput(0); // DIO 0boolean atTop = !topLimit.get(); // invert: pull-up makes open == trueMany smart motor controllers also have dedicated limit-switch inputs. The REV Spark MAX/Flex has forward and reverse hardware limit inputs (normally-open by default, ground-to-trigger; configurable to normally-closed). The Falcon 500 (a Talon FX) has a 4-pin hardware limit-switch port a switch can wire directly into; the Kraken X60 has no hardware limit-switch pins. Either way, a Talon FX can also use a remote CAN sensor (a CANcoder, CANdi, or CANrange) as a limit switch over CAN. These can stop the motor in firmware faster than your robot code loop.
Beam breaks
Section titled “Beam breaks”A beam break uses an infrared emitter and a separate receiver. When something (a game piece) blocks the beam, the output changes state. Beam breaks are the standard way to detect that a ball, note, coral, or other game piece has entered an intake or indexer.
Wiring matters: beam-break emitters and receivers need power (commonly the regulated supply specified in their datasheet), so wiring only signal and ground to a DIO port can leave the sensor unpowered and reading nonsense. Always follow the manufacturer’s wiring diagram and confirm the output’s logic level is compatible with the roboRIO’s 5V DIO (use a voltage divider or level shifter if the datasheet calls for it).
Debouncing
Section titled “Debouncing”Mechanical switches can ‘bounce,’ producing several rapid transitions on one press. WPILib’s Debouncer class filters this:
Debouncer debouncer = new Debouncer(0.05, Debouncer.DebounceType.kBoth);boolean stable = debouncer.calculate(topLimit.get());Design tips
Section titled “Design tips”- Use a limit switch to reset an encoder rather than relying on it alone for position.
- Trigger commands on the edge (the moment a beam first breaks), not the level, to avoid re-triggering every loop.
- Mount switches where debris and game pieces will not falsely trip them.
Key takeaways
Section titled “Key takeaways”- Limit switches define home positions and act as safety stops; beam breaks detect game-piece presence.
- Smart controllers (Spark MAX, Talon FX) can act on limit switches in firmware, faster than robot code.
- Beam-break emitters/receivers need power — wire per the datasheet and match the DIO logic level — and debounce mechanical switches with WPILib’s Debouncer.
This lesson was adapted from learnfrc.com.
