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.
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.
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
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?
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.
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...
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 :(???.
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.