Wiring a limit switch.

Question - how to wire a limit switch to the robot.
Question - Is it wired with a spike relay, or a jaguar.

Were thinking about adding an arm to get across the bridge. But the only problem is were trying to figure out how to wire a limit switch to the robot. So some programming can be done to interact with it. Is it wired with a spike relay, or a jaguar. Any help is greatly appreciated, and thank you for your time.

You have two options with limit switches:

  1. Wire it into a Digital Input on the Digital Sidecar. This allows your software to read it and take appropriate action (such as turning off the motor). Doing this, you only need to wire it to signal and ground (there’s an internal pull-up resistor on the digital inputs).

  2. Wire it into a Jaguar that is using CAN (per R61, nothing else can be attached to a Jaguar using PWM except for the coast/break port). For these, there are 4 pins - two control forward direction, two reverse. There are jumpers in there when its shipped. If you go this route, make sure you wire the limit switch so it’s “Normally Closed” - in other words, you should be able to measure 0 (or near 0) resistance when the switch is NOT being pressed, and infinite resistance when it is. That way, the Jaguar will automatically stop when the switch is pressed.

Regardless of which way to wire it up, make sure you add some sort of mechanical stop to ensure the arm won’t go past the limit switch. Even with it turning off as soon as the switch is pressed, often an arm will continue moving a bit before it fully stops - a mechanical stop will prevent this.

Just one more option to consider:

If you’re out of Digital I/O ports (like I was this year), you can also wire to the analog breakout. Connect +5v and Signal when the limit switch is engaged, and then check in code whether the analog channel reads above or below 2.5V.

Something you have to remember about programming Jon’s first option: the channel will read 1 unless signal and ground are connected, in which case it would read zero. That confused me for a while when our limit switches did not work as programmed.

So in order to wire the limit switch to the Digital I/O who wire it to a PWM cable to only the signal and GND?

Exactly! Typically, people will cut the male header of a PWM cable off, tape off the end of the power wire (the middle wire), and then wire the switch to the outer two wires.

As mentioned by others, the limit switch may work opposite of what you expect! Switches can be wired up as “Normally Closed” or “Normally Open”. Depending on which way you wire it, you may read TRUE and FALSE either way. Looking at the case of the limit switch that came in the KoP, you’ll see the three ports are labeled “Com”, “NC”, and “NO”:

Hook up one wire to Com - it doesn’t matter which one.

If you hook the other one up to NC (Normally Closed), then you’ll read FALSE when the switch is not pressed, and TRUE when it is.

If you hook it up to NO (Normally Open), you’ll read TRUE when the switch is not pressed, and FALSE when it is.

Our programming team always writes a small test program for sensors - essentially, they just read the value and print it to the consol output. This lets them see which way its wired up, and adjust their code as needed.

If you are going to connect it using an analog channel, you need some simple circuit than just a switch. If I understand you correctly, you are connecting +5 and Signal to the “Normal Open” or “Normal Close” and “Common” contacts of the switch. In other words, when activated, you either short signal to +5 or leave signal floating. Leaving the signal pin unconnected will read random values. If you really want to use analog channel, you need to use at least one resistor (e.g. a 10K resistor connected between +5 and Signal), then connect the Normal Open to signal and Common to Gnd. When the switch is activated, the signal pin will give you 0V (shorted to Gnd). When the switch is not activated, the signal pin will give you approx. 5V (open).

Hmm, all I can say is that it worked fine for us. Our normally open switch reported 0 volts when open and 5 volts when closed, with a bit of noise. The 2.5V threshold accurately detects the two states.

Why would an unconnected pin report random values? Or do you just mean it would be a noisy zero?

Mostly, it would be a “noisy zero” as you put it. But, if the pin is floating, it could have residual charge trapped since the last closure of the switch. In other words, when the switch closes and you read 5V. Then the switch opens and it may take a period of time for the charge to drain internally from the signal pin. It depends on the analog bumper design, the period could be long since you did not provide a drain path. The best case is that it drained relatively quickly and you didn’t even notice it. The worst case is a delay before the signal pin reads 0. For a limit switch to stop something, a delay may or may not be acceptable. Certainly comparing it to 2.5V instead of 0 helps a lot because it is certainly reaching 2.5V a lot faster than 0. In general, it will probably work in your case but not a best practice to float a pin.

if the limit switch is a double throw (has common, NO and NC) then you could connect 5V to NO, Gnd to NC, and the signal to common. The switch would then either switch the signal to 5v or ground. Be careful not to put 5v or gnd on the common terminal, or one state will give you a short.

Reversing 5V and ground would change polarity or just change in software.

Get the analog port for greatere or less than 2.5 volts.

Genius. Now I have a use for that pesky black wire :stuck_out_tongue:

I think I’ll be wiring any analog limit switches this way in the future; thanks!

Oh no, I can smell the melting plastic :ahh:

As indicated here, it’s important to make sure your electrical set up ensures a definitive value regardless of the input form the sensor. The digital inputs have a pull up which accomplishes this for you, but the analog inputs do not. floating inputs are unreliable, and even if they seem to work in the pit, you know they’ll fail to work at the most critical time on the field, and be next to impossible to debug!

Normal open, red wire (end)

Middle leg, white wire (middle)

Normal Closed, black wire (end)

This will read false when not trigged in the code, true when pressed. If you don’t know which end leg is which, just look on the side of the limit switch. The diagram will show the middle leg connected to a side leg (normal closed)
Plug into a digital I/O, pay attention to the orientation on the digital side car.

The open input to the analog board is capable of receiving electrical noise interference from the environment, sparks generated in motors or other electronic signals within the robot. Best practice is to somehow limit analog inputs to prevent this noise intrusion. A limit switch between +5 and power common provides a very low impedance source in either case that minimizes noise pickup. Yes, noise can be picked up of sufficient amplitude that it could be interpreted as a valid signal.