Skip to content

Limit Switches

CoolProGamer edited this page Feb 6, 2025 · 6 revisions

What is a Limit Switch?

Limit switches are some of the simplest sensors used on the robot. They connect to the RIO as a digital input device, capable of transmitting a 'high' or 'low' signal (1 and 0, respectively). These signals correspond to the device being either in the open or closed state (when contacted or when exposed to open air). Thus, we can use these to determine if a mechanism has reached a 'maximum' or 'minimum' position based on if it contacts the switch. For example, we could use it to make sure an arm does not exceed a certain limit of extension.

Usage in WPILib

In WPILib, these switches are super easy to implement, with the DigitalInput class and constructor:

DigitalInput limitSwitch = new DigitalInput(port number);

...

// returns true if switch is tripped, false if not
if (limitSwitch.get()) {  
    arm.doThingOne(); // limit reached, arm will do something
}

Clone this wiki locally