Replacing a pushbutton with a on/off rocker switch

On my project I currently have a tiny pushbutton which my code waits for someone to press on. I then toggle the project on/off, in the loop() function, each time someone presses the button.

Currently my tiny pushbutton is connected using 2 of the 4 posts coming out of it: 1 post is connected to the Arduino Uno's 5V out and the other post is connected to pin 7 with a 1K resistor going to the GND pin.

My tiny pushbutton is this one:
http://snootlab.com/lang-en/parts/102-push-button-12mm.html

I realised that what I really wanted was a simple On/Off switch. So I went out and got this one:

My question therefore is how I plug this thing in to my project. It's the electronics (hardware) side where I am still flying blind or with really dark and foggy sunglasses.

I can see that this rocker switch is rated up to 16A at 125V from the sales sheet. I see numbers like that on the side of the switch as well as things like 1/3HP and 125/250VAC. I believe I know what the A (amps), V (volts) and VAC (volts alternating current?) stand for but I have no idea what the HP stands for. I assume horsepower doesn't fit in to this equation {vbg}.

I looked at the Mechanical Drawing (http://dlnmh9ip6v2uc.cloudfront.net/datasheets/Components/Switches/Rocker%20Switch%20Right%20Angle.pdf) naively thinking this might help me figure out how to wire this up. I know just about every word on that sheet of paper is in English. But it's like showing the Kama Sutra to a virgin. I just don't know what fits where...

Am I so lucky that I can just replace the 2 posts on my button with the 2 posts on this rocker switch (one going to 5V and the other going to pin 7 and GND with a 1K resistor)? Does it matter which post is which?

Or should I be looking at this switch totally differently than I would a pushbutton?

Thank you in advance both for any practical help you could provide and, if you have the time, any explanation you could add to let me know how I could have, and perhaps should have, figured this out for myself.

Make it simpler. Connect 1 post to Gnd, the other to your input pin, and enable its pullup resistor.
When the switch is open it will read high, when its closed it will read low.

Wire up pushbuttons the same way. Don't connect switches to +5V.

Thank you for your reply and explanation.

Do I use the same resistor? Is the 1K enough or too much?

Where do the 2 ends of the resistor go? One end goes to the wire going to Gnd right? Does the other end of the resistor go to the wire going to the input pin?

I thought the push button, and therefore switch, had to be connected to power (5v) and the input pin as in the tutorial I learned from : http://www.arduino.cc/en/Tutorial/Pushbutton

I wired up the rocker switch exactly as I had wired up the pushbutton and it worked!

One post goes to 5V. One post goes to one end of 1K resistor and pin 7 the other end of the 1K resistor goes to Gnd.

My code required very little modification, as I still get a 1 or a 0 from the switch, and it works even better than the push button did - for this project.

Thanks!

Even though it works I still have a question...

I just copied the resistor which had been used in the pushbutton tutorial. This 1K resistor seems to work fine at the moment.

But, normally, how would I have calculated what value resistor would have been right for this rocker switch?

Thanks!

My suggestion uses No resistor, just the internal pullup resistor

in void setup:

pinMode (pinX, INPUT_PULLUP); // use with button connected to pinX and to Gnd

in void loop:

if ( digitalRead(pinX) == 0) {
// button was pressed
//do whatever the action is
}

I know this post is 6 years old, but if any newbies (such as myself) are out there reading this now and wondering if crossRoads’s suggestion works, it does!
Thank you CrossRoads!

I see numbers like that on the side of the switch as well as things like 1/3HP and 125/250VAC. I believe I know what the A (amps), V (volts) and VAC (volts alternating current?) stand for but I have no idea what the HP stands for. I assume horsepower doesn't fit in to this equation {vbg}.

It is horsepower, actually. It's specifying that the switch is capable of handling a 1/3 HP motor, in addition to its other limitations. Big switches like that are designed to switch power, not just small microcontroller signals.

You obviously can still use them as small signal switches, they're just massively overqualified for the job.

But, normally, how would I have calculated what value resistor would have been right for this rocker switch?

The type of switch has absolutely no bearing on the size of the resistor. Resistor value is determined by the the electrical noise the project will be exposed to. Higher value resistors are more sensitive to electrical noise than lower value ones, so with large amounts of electrical noise nearby (such as a running DC motor), you need lower value resistors.

In general, somewhere between 1k - 100k is usually good enough.

1 electrical horsepower is equal to 746 watts. Now you can use this with ohms law.