Go Down

Topic: How to wire two push buttons (Read 4 times) previous topic - next topic

sta

This is probably very simply, but I just can't figure it out. I'm trying to wire two push buttons to an Arduino, so I can read the state. One push button works just fine, when I wire it like this:



I now try to hook up another push button like this:



But this is obviously wrong. When I now push the first push button, both Pin2 and Pin3 is HIGH.

Any tips on how to wire this?

kg4wsv

You need another resistor - one per switch.

-j


tcoop25

Here is a great method:

http://arduino.cc/en/Tutorial/TwoSwitchesOnePin

-TC

sta

Thank you for the answers. I have now added another resistor and it helped a bit. It's now wired like this:



Reading of Switch1 is working fine. However reading of Switch2 only works when Switch1 is on.

When Switch1 is off, nothing happends when the state of Switch2 is changed. If both Switch1 and Switch2 is on and Switch1 is turned off, Switch2 is also turned off.

Any tips on what I'm doing wrong?

mem

#4
Sep 18, 2008, 09:17 pm Last Edit: Sep 18, 2008, 09:18 pm by mem Reason: 1
The circuit looks ok. Check to see if the actual wiring has the ground from switch2 connected to pin2, it should be connected directly to ground as per the diagram

sta

Thank you for the reply. I forgot one important piece of information:

I'm using a common ground wire for the two switches. From the Arduino I have 3 wires running to the 2 switches. Is it possible that this is causing troubles?

mem

Simplify. Remove everything that is not essential and do some simple tests. For example you could remove the switches and just see if pin 3 changes when you connect and disconnect a wire from the pin to one of the resistors. If it doesn't then you should check your code. If it does then something is wrong with the switches or wiring.

Good luck.

tchiseen

Could you please post your code? Cheers!
What goes up doesn't necessarily have to come down.

tkbyd

Actually... all you need to connect to the Arduino is the switch... but... see the "but" in a minute...

I'm not good with the graphics, but it is so simple you can do it with text...

Wire from ground.
To switch.
To Arduino input/output pin, e.g. Pin2

You can do that over and over, lots of wires to ground, lots of switches, one wire from "other" side of each switch to a different input pin.

But! What about the resistor?!

There's one in the Arduino which can be "connected" (correctly!) by a little bit of code. Such resistors, be they discrete resistor outside the Arduino (as discussed in previous posts) or inside the Arduino are called "pull up" resistors.

Software, and a more lucid (I hope) explanation of all this is at...

http://sheepdogguides.com/arduino/aht0button.htm

Erika86

Hi guys,

I'm doing my first experiments with Arduino and I'm trying to use two buttons. I wanna my LED turns on when I press two buttons at the same time. With one button it works but I don't know how to wire the second one. Could you help me sending the fritzing scheme :(???.

PaulS

Wire both switches the same way. Then, read the state of each switch, and act only if both switches are pressed.

Erika86

But...They don't disturb each other if connected on the same line? Thanks for the fast reply! :D

PaulS

Quote
They don't disturb each other if connected on the same line?

Do you mean to the same pin? If so, then, yes, they disturb each other. The Arduino can not tell whether one or two switches connected to the same pin are pressed. HIGH is HIGH, after all.

The switches need to be connected to different pins.

Erika86

No NO I meant the line of the breadboard..Sorry I'm still ignorant about electronic... :(

Go Up