Limit switch wiring

so for limit switches, I have mine set to normally open so when the button is clicked, in the code, it returns true. How should I wire the switch to the roborio, there are 3 pins on each DIO port on the rio and only 2 wires connecting them. the DIO ports have ground, 5V and signal pins. Anyone know what the right combination of these is?

Limit switches with 2 wires should connect to the ground and signal pins, you shouldn’t plug either wire into the 5V pin


The RoboRIO’s DIO ports have internal pull-up resistors, meaning that when nothing is connected to the pins, they will read true. So generally for Limit Switches, you wire the Ground to the common pin and then the Signal to either the NO or NC pin. Just note that depending on which you pick, the logic in your code will be reversed. If you select NO, then you will read true when the button is not pressed, and false when the button is being pressed. Inversely when you select the NC, you will read false when the button is not pressed, and true when the button is pressed.

The circuit diagram looking something like this except the R1 resistor is built into the RoboRIO.

It is worth noting that in whichever state you are reading false, aka when the switch is closed, there is some small amount of current passing, from the 5v line through the pull-up resistor and to ground, so people generally make the true state whichever the switch is expected to be in the majority of the time. So for arm limit switches, you generally expect them to not be pressed most of the time, so you actually put the ground connection on the NO, meaning that when the switch is not being pressed it is reading true so you must invert your logic. This is probably not too important for FRC where we have lots of high power actuators and short matches, but in low-power embedded systems it can matter.

It is also worth noting that if you are wiring your limit switches into your motor controller (ie the SparkMax, Talon SRX, or Falcon) inputs, you need to check what state they expect. IIRC both the SparkMax and Talon/Falcon also have pull-up resistors and expect normally high/true input, so the input goes low/false when the switch is pressed. I realize you are not doing this in this scenario, but others who are may see this topic as well so including for completeness.

Consider wiring the switches NC (normally closed).

Not to contradict what @ExploitSage is saying but in FRC, parasitic current draw from the pullups is below our ability to really measure or care. Having spent a number of years in low power, multi-year battery life, wireless devices, pull ups can indeed be the silent battery killer for sure but we’ve got juice to spare and matches that last minutes rather than years as @ExploitSage pointed out.

The advantage in going NC is that it is a monitored circuit - any disconnection or break along the way can be readily detected.

You can invert the logic as needed in your code but by going NC, you’ll be able to make sure the entire circuit is working as expected in the unactivated state before you need to count on it.

Limit switches connected directly to the controllers tend be configurable either way.

As a side note, someone once asked me, “So how do you get these things to run for years on a small battery?”

I told them, “You don’t do a lot and you don’t do it too often; any other questions?”

That’s not us here…

1 Like

I was browsing on my phone initially or I would have looked it up before posting, it does indeed appear it is configurable for the CAN controllers!

makes sense. Thanks so much for the feedback!

How do you wire the limit switch directly into the controllers? we have SparkMax’s.

Not much benefit to reviving a year-old thread as opposed to just creating your own, but since we’re here… this page is your friend

1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.