Skip to content
Programming, Controls & Sensors·Lesson 22 of 51

Limit Switches and Beam Breaks

Simple digital sensors that tell you when a mechanism reaches a hard stop or when a game piece is present.

Sign in to track progress, earn XP, and save lessons.

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 Talon FX has no hardware limit-switch pins, but it can use a remote sensor (a CANcoder, CANdi, or CANrange) as a remote 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.

Lesson quiz

Required

Answer all 3 questions correctly to complete this lesson.

1.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)?

2.Why is a normally-closed (NC) limit switch often considered the 'safer' wiring choice compared to a normally-open switch?

3.How does a photoelectric 'beam break' sensor detect a game piece?

Answer every question to submit.