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
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 0
boolean atTop = !topLimit.get(); // invert: pull-up makes open == true
Many 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
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
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
- 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
- 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.
Keep going
Take the quiz · +10 XP with an accountMore in Sensing Fundamentals: Digital, Analog, and CAN Inputs
Sources & corrections
This lesson is AI-assisted: drafted from primary sources, then reviewed and edited by hand. Errors still get through. When one is reported we fix it and write down what changed — publicly, in the corrections log.
Sources and further reading
- WPILib: Digital Inputs (software)docs.wpilib.org
- REV: SPARK MAX Data Port (limit switches)docs.revrobotics.com
Read next
Articles on this, for competition day
The lesson covers how it works. These cover what to do when it breaks.
Lesson quiz
RequiredAll 3 right completes the lesson. Miss one and only that question comes back — anything you already answered correctly stays banked.
0 of 3 answered
01.A normally-open limit switch is wired between a roboRIO DIO signal pin and ground. Because the DIO has an internal pull-up resistor, what does DigitalInput.get() return when the switch is NOT pressed (open)?
02.When a limit switch is used to define a mechanism's home/zero position, what is that switch actually used to do in that role?
03.How does a photoelectric 'beam break' sensor detect a game piece?
Answer every question to submit.
All 51 lessons in Programming, Controls & Sensors
- Not started:Mini-Project: A Closed-Loop Elevator with Motion Magic
- Not started:Mini-Project: A Velocity-Controlled Shooter on REVLib
- Not started:Mini-Project: A Teleop Swerve Drive Subsystem
- Not started:Mini-Project: An Autonomous Routine with PathPlanner
- Not started:Mini-Project: Vision-Aligned Scoring with Limelight
- Not started:State-Space Control and Kalman Filtering
- Not started:Log Replay Architecture with AdvantageKit
- Not started:Advanced Pose Estimation: Multi-Tag Fusion and Standard Deviations
- Not started:Robot Coordination, Alerts, and Operator Feedback
- Not started:Case Study: Hardening Software Before an Event