Log in

View Full Version : Micro Switch Wiring & Programming


Team 4939
09-02-2015, 20:24
Greetings from Team 4939,

Hopefully everybody is having a great final week of building. We were just in the phase of finishing some things up on our robot, and we decided that if we added a micro switch to the robot that would help us in the functionality of our platform. We are hoping that the micro switch will basically let the program know to stop the platform when it reaches to high or to low on or elevator system. We have never used this type of thing on our team, so we are looking for some help on this.

Any input in the programming or electrical wiring of the Micro switch would be greatly appreciated.

Thanks

Ether
09-02-2015, 20:42
Any input in the programming...

You neglected to mention what programming language.

While you're waiting for responses, this might be helpful:

https://wpilib.screenstepslive.com/s/4485/m/13810/l/241867-switches-using-limit-switches-to-control-behavior

pastelpony
09-02-2015, 21:11
We're using these things for the same purpose of stopping a potentially-dangerous component of the robot.

What we did was saw off the male end of a PWM cable and solder the signal and ground to NO and COM respectively. The female side of the PWM then goes into the DIO breakout of the roboRIO. You'd treat it as a digital input in your code and look for a boolean value to decide what would happen if pressed/not pressed.

GeeTwo
09-02-2015, 22:51
Sorry about this - the NI specifications document for the roboRIO (https://decibel.ni.com/content/servlet/JiveServlet/download/30419-60-90613/roboRIO+Specifications.pdf) do NOT mention the pullup resistors. You have to go to the RoboRIO User Manual (https://decibel.ni.com/content/servlet/JiveServlet/download/30419-60-90614/roboRIO+User+Manual.pdf) to find this info. I'll leave the post below here alone, as a reference for anyone who wants to wire a board that does not have pullup resistors built in.

As this was posted on the electrical forum, I'll describe how to wire them.

First of all, I'll assume that you're using a standard PWM color-coded cable, black is ground, red is 5V, and white is signal. Crimp a female Dupont (0.1" header-style) connector at one end, red wire in the middle.

I will refer to a setup where the return value is 0V normally and 5V when the switch is engaged as "normal" logic, and the reverse (5V normally, 0V when engaged) as "reverse" logic.

To get normal logic for double-throw switches (those with three terminals) such as those shown in the pictures referenced by Ether, wire the white wire to the pole (common), black to the normally closed terminal, and white to the normally open terminal.
For a single-pole switch (two terminals), you need to add a resistor. We're using 2K this year based on the numbers I looked up online, but we haven't gotten any answers back to confirm this is the right value.

To get normal logic with a normally open switch: Connect the red wire to one terminal on the switch and the white wire to the other terminal. This gives you 5V when the switch is engaged. However, it is "floating" when it is not, so you need to ground it. However, you need to limit the amount of current that will flow through the switch when the switch is closed. This is where the resistor comes in. Connect the black wire to one lead of the resistor, and the other lead of the resistor to the same terminal as the white wire.
If your switch is normally closed, wiring it as described above will give "reverse" logic.


For any of these setups, if you want the opposite logic from the one described, swap the black and red wires. Leave the white wire, switch, and resistor (if any) in the same configuration otherwise.


Finally, for any of these setups, plug this into one of the DIO ports, black at ground, white at signal.

Alan Anderson
09-02-2015, 23:54
For a single-pole switch (two terminals), you need to add a resistor.

You don't need to add a resistor to sense a contact closure. The roboRIO digital inputs already have one. Just connect the switch between the GND (black) and SIG (white) wires.

Programming depends on the language you're using.

SousVide
10-02-2015, 01:30
Suggestion for this use would be to wire these micro-switches as NC for failsafe. If the wiring or the switch somehow fails - the usually mode is a break in the line, then it will act as if the switch is depressed and disallow movement. If you wire it up as NO, you will have no way to know that there is a break in the line until the device crashes or hits a hardstop.

See:
http://www.allaboutcircuits.com/vol_4/chpt_6/5.html

We're using these things for the same purpose of stopping a potentially-dangerous component of the robot.

What we did was saw off the male end of a PWM cable and solder the signal and ground to NO and COM respectively. The female side of the PWM then goes into the DIO breakout of the roboRIO. You'd treat it as a digital input in your code and look for a boolean value to decide what would happen if pressed/not pressed.

Team 4939
10-02-2015, 15:53
So sorry for forgetting to mention the programming language. The programming language that we use is JAVA.

Thanks once again.

Alan Anderson
10-02-2015, 16:09
In a procedural language like C++ or Java, the programming for a limit switch is simple. Just before you call the motor.Set() method, test to see whether the value to send to the motor is forward while the forward limit switch is active, and set the value to zero if so. If you also have a reverse limit switch, add another test to see whether the motor value is reverse while the reverse switch is active, and zero the value if so. Only then do you actually set the motor to that value.

Team 4939
10-02-2015, 21:30
In a procedural language like C++ or Java, the programming for a limit switch is simple. Just before you call the motor.Set() method, test to see whether the value to send to the motor is forward while the forward limit switch is active, and set the value to zero if so. If you also have a reverse limit switch, add another test to see whether the motor value is reverse while the reverse switch is active, and zero the value if so. Only then do you actually set the motor to that value.

What is the name of the object when introducing the limit switch to the program?

Alan Anderson
10-02-2015, 21:44
Switches are read using DigitalInput objects.