micro switch

Hi everyone,

I was wondering if someone could please help me on how to use an spdt switch with my arduino uno. I want to have the switch turn on an led after being pressed three times. I have no clue how to hook up the switch so a very descriptive response will be greatly appreciated. I think the thing really throwing me off is that ive never used something with terminals like the ones on the switch I have. I don’t know if I’m suppose to run a wire through the loop on the terminal or what. The pictures I attached will give a better visual of what I mean. The terminals are labeled NO, NC, and C. Thanks in advance for any help!

Do you know how to read a switch with two contacts that often times come in Arduino starter packages, and it fits in a breadboard? If not, you probably want to start here: http://arduino.cc/en/Tutorial/DigitalReadSerial.

The micro switch is like the switch with two contacts, except it doesn't fit in a standard breadboard and it has 3 contacts. Instead you connect a wire to two of the contact legs. Initially you can just twist the wire to your switch, but eventually you will probably want to solder wires to the switch. If you want the switch to return HIGH when it is normally closed, you would connect the wires to the legs with NC and C labels on them. If you want the switch to return HIGH when it is normally open, you would connect the wires to the legs with NO and C labels on them.

Wow, thanks for the quick response! Do you know if I would need a denounce circuit for my particular use for the switch?

Typically, you solder wires (and then usually insulate with heat-shrink tubing) or use [u]Quick Disconnects[/u], which crimp to wires. Quick disconnects come in a couple of different sizes and you can get them (and the crimper) at electronics stores, in the electrical department at hardware stores, or at auto parts stores.

It's quite common to use only 2 of the 3 switch terminals, depending on how you want it to function. In most applications, you'll probably use the Common and Normally Open terminals.

C = Common.

NO = Normally Open. There is no connection "normally" (when the button/lever is not pushed). When you push the button, NO is connected to common. ( i.e. The switch is OFF 'till you push the button.... This is probably how you expect a "regular" pushbutton switch to work.)

NC = Normally Closed. When the button is not pushed, NC is connected to C. (i.e. The switch is ON.) When you push the button, the switch turns OFF and there is no connection to NC.

There is NEVER a connection between NC and NO unless you make an external connection for some reason. (There are special "make before break" switches thatconnect all three terminals while being switched, but they are very rare and we'll leave that for later).

If electronics is going to be a hobby, I recommend that you get a multimeter. You can get a meter as low as about $10 USD. Using the resistance (Ohms) setting on the meter, you could check how switches work, and they are very handy for checking connections and voltages, etc., when something doesn't work as expected.

Do you know if I would need a denounce circuit for my particular use for the switch?

Usually not. You didn't tell us your particular application. :wink:

If you have a program (sketch) that counts how many times the switch gets turned-on, or a program that does something the 1st time you push the switch and something else the 2nd time you push the switch, then you need be concerned with bouncing. Another example would be a keypad where if you push "1" and the switch bounces you could get "1111".

DVDdoug:

Do you know if I would need a denounce circuit for my particular use for the switch?

Usually not. You didn't tell us your particular application. :wink:

If you have a program (sketch) that counts how many times the switch gets turned-on, or a program that does something the 1st time you push the switch and something else the 2nd time you push the switch, then you need be concerned with bouncing. Another example would be a keypad where if you push "1" and the switch bounces you could get "1111".

Well I want to put it on a rc car, there would be three LEDs, initial state would be all three green, press the switch once and two will be blue, press it twice one will be yellow, press it three times and they will all be red

Also if I’m not going to use the normally closed terminal will I have to ground it? Or is there anything in the switch I would have to ground?

turkeyvulture4550:
Also if I'm not going to use the normally closed terminal will I have to ground it? Or is there anything in the switch I would have to ground?

A switch is just a connection between two wires. One of the wires needs to connect to ground, and the other needs to be connected to the pin you are reading from. If you wire it up the way mentioned in the FAQ I posted earlier, you will need a resistor (usually 10k) in the circuit path. If you use internal pull ups (http://arduino.cc/en/Tutorial/InputPullupSerial) you do not need the resistor, but you need to invert the sense of the test (i.e. digitalRead returns LOW if the connection is made, and HIGH if it is not made).

In terms of your application, you will need a static or global variable to keep track of the button state (connected, not connected), and a separate variable to keep track of the number of times the button has been pushed.

MichaelMeissner:

turkeyvulture4550:
Also if I'm not going to use the normally closed terminal will I have to ground it? Or is there anything in the switch I would have to ground?

A switch is just a connection between two wires. One of the wires needs to connect to ground, and the other needs to be connected to the pin you are reading from. If you wire it up the way mentioned in the FAQ I posted earlier, you will need a resistor (usually 10k) in the circuit path. If you use internal pull ups (http://arduino.cc/en/Tutorial/InputPullupSerial) you do not need the resistor, but you need to invert the sense of the test (i.e. digitalRead returns LOW if the connection is made, and HIGH if it is not made).

In terms of your application, you will need a static or global variable to keep track of the button state (connected, not connected), and a separate variable to keep track of the number of times the button has been pushed.

Ah ok. Thank you for the links. So from what I understand from reading them is that I can either hookup the voltage supply to one leg and a resistor to ground and the digital pin to the other leg (having a 0 when the switch is not pressed) or hoopkup ground to one leg and the digital pin to the other (having a 1 when the switch is not pressed). And from what I understand since the switch is just a connection between two wires, it doesn't matter in which order I hook up the legs, just so long I don't use both NC and NO together. Also would that means since the method with no resistor reverses the signal and using the normally closed terminal does the same, I could use both and still have a 0 signal when the switch is not pressed?

turkeyvulture4550:
Ah ok. Thank you for the links. So from what I understand from reading them is that I can either hookup the voltage supply to one leg and a resistor to ground and the digital pin to the other leg (having a 0 when the switch is not pressed) or hoopkup ground to one leg and the digital pin to the other (having a 1 when the switch is not pressed). And from what I understand since the switch is just a connection between two wires, it doesn't matter in which order I hook up the legs, just so long I don't use both NC and NO together. Also would that means since the method with no resistor reverses the signal and using the normally closed terminal does the same, I could use both and still have a 0 signal when the switch is not pressed?

I believe you are correct.

Alright, thanks for the help :slight_smile: