Multiple buttons


I have to wire two push buttons to the Arduino. I am simply using the circuit from twice. I am using two digital pins, one for each button, but the issue is that when one button is pressed, the other buttons pin reads HIGH as well as it's connected to the same 5V/GND. Obviously I am doing something wrong in the circuit, so how am I actually supposed to set it up?

Thank you.

Post your code and a circuit diagram.

This is how the circuit looks now. It’s obvious that both pins will get 5v when one is triggered. I have no experience with circuits at all though.

Edit: The code just reads pin 11 and 12 for high/low. Sets them to input first.


OK, stop using external pull-down resistors that you have to pay for, and use the free built-in pull-up resistors.
All you need are some simple modifications to your code.

void setup ()
  pinMode (buttonPin0, INPUT);
  digitalWrite (buttonPin1, HIGH); // enable pullup.

You need a pair of instructions like this for each input pin.

And INVERT the logic of your main code, i.e., when a button is operated (closed), the associated pin will read LOW, and HIGH any other time.

I removed the resistor and enabled the internal pullup resistors. Now I can't get it to read anything but high. I will try measuring on the buttons, but they have worked when I only had one button.
Sadly I can't quite post the code as it's done in LabVIEW.

Edit: It actually seems that I am short circuiting the Arduino when a button is pressed.
The 5V and the GND are now connected directly when the button is pressed. There's no resistance between them at all.

I thought about what you said again, and changed the circuit to look like this (with internal pullup on pin 11-12).
Both pins still get pulled low when one is pressed.


Your diagram doesn’t make much sense - it appears your input pins are shorted together, so it isn’t surprising they both go low when a switch is operated

You’re right, I was a bit quick with that drawing. It really is like this, and both go to low when you press one of them.
I don’t see problems with the code, both pins are set to input, then I write high to them, and then I read the values in a loop.


I don’t see problems with the code,

I don’t see the code, so I can’t comment. (hint)

I found the error, it wasn't that obvious but I had soldered two other wires together than I hadn't noticed :slight_smile: Now that it's wired as in the last diagram I posted, it works perfectly. Thank you.