Hooking a toogle switch

Sorry about this stupid question, I’m just starting and trying to read a toggle switch state.

In the tutorial http://arduino.cc/en/Tutorial/DigitalReadSerial

There are 3 connections

1- +5V
2- digital input
3- ground

But my swith has only 2 pins. :drooling_face:
Again, sorry about this, I’m trying to learn.

Jay98:
But my swith has only 2 pins.

So does the pushbutton.

The two pins on the right side of the button (toward the resistor) are the same “pin”, while the two on the left (one connected to 5V) are also connected together.

The resistor is set up to pull the input to ground (LOW) when the switch isn’t actuated (a pull-down resistor).

Hopefully you can figure out now how to hook up your switch…

Hi,

Think about the Arduino and switches and pullups and pulldowns and All That this way:

This is part of a good How-To on http://ArduinoInfo.Info

Go to "How-To and Starter Kits" and then the links to the HOW-TO pages for YourDuino Basic Starter Set. That has a comprehensive How-To that you can use with any parts you have available...

Thanks, got it working with your help guys. Now I'm wondering, how about if i need to have lot of push buttons? Can you please suggest me a library and a diagram on how to connect them in a productive way?

Now I'm wondering, how about if i need to have lot of push buttons?

You use one pin for each or something like a shift regiser to expand the numbers of pin. http://www.arduino.cc/en/Tutorial/ShiftIn

Can you please suggest me a library

Why do you want one, this is just trivial.

how to connect them in a productive way?

What do you mean by productive?

Another way of using multiple pushbutton on one pins is to connect them with a series of resistors and read them with an Analog input.

There's an example on the ArduinoInfo.Info WIKI HERE

terryking228: Another way of using multiple pushbutton on one pins is to connect them with a series of resistors and read them with an Analog input.

There;s and example on the ArduinoInfo.Info WIKI HERE

Thanks Terry, that should be really easy, however is not working properly for me. I only get reading from a button when the all the previous one are pressed, otherwise i get 0. What could be wrong?

It sounds like you have wired them in series rather than in parallel, I suggest you go back to Terry's diagram and compare your wiring. For simplicity, you might try getting it to work initially with fewer buttons.

wildbill: It sounds like you have wired them in series rather than in parallel, I suggest you go back to Terry's diagram and compare your wiring. For simplicity, you might try getting it to work initially with fewer buttons.

I suck interpreting diagrams, but I think i wired it correctly. Can the resistors be the problem? I used what i got

Right now looks like this: 5v-2k--------------220-440-660-1k-2k-10k

Can the resistors be the problem? I used what i got

Yes that will be a problem. It only works if you have the right resistors.

I see thank you.

Currently I have these resistors

56 120 220 1K 10K

Can I do anything with this? Or what sequence would I need to handle 7 push buttons?

PS: Code is not a problem, I understand I will have to modify it when using different resistors.

Do a serial print and see what values you do get.

Grumpy_Mike: Do a serial print and see what values you do get.

100 250 400 550 700

...

The problem is I get zero unless all previous buttons are pressed. I wired this exactly as it's showed in the image

I wired this exactly as it's showed in the image

Something's wired wrong or some resistor value is very hgih and now what you think.

Do you have a multimeter of some kind??

Check each point in that circuit.

UPDATE: [/b*]Sorry I was not clear:* First press the bottom button. The voltage at the bottom of the resistor network shoudl go to zero. Does it?? You should have 5V (close anyway) at the top, and progressively less as you go down the series resistors. If not, some resistor is bad/high resistance or something is wired wrong... Let us know....

I have 4.84 at the beggining and 4.79 at the end of the line, but when connect the buttons to the +5 rail, voltage drops to zero after the 2K resistor.

when connect the buttons to the +5 rail,

?? Buttons connect to GROUND in my example...

terryking228:

when connect the buttons to the +5 rail,

?? Buttons connect to GROUND in my example...

What about the other pin?

Ok, got it working with this one

Ty.

Hi Jay,

OKOK.. It's a voltage divider, no matter what side is to 5V and what side is to ground :)

Glad it's working for you..