Pages: [1]   Go Down
Author Topic: How to wire two push buttons  (Read 4547 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 42
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

0
Offline Offline
Faraday Member
**
Karma: 8
Posts: 2526
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You need another resistor - one per switch.

-j

Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 13
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Here is a great method:

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

-TC
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 42
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

London
Offline Offline
Tesla Member
***
Karma: 10
Posts: 6255
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
« Last Edit: September 18, 2008, 02:18:20 pm by mem » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 42
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

London
Offline Offline
Tesla Member
***
Karma: 10
Posts: 6255
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Sydney, AUS
Offline Offline
Newbie
*
Karma: 0
Posts: 2
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Could you please post your code? Cheers!
Logged

What goes up doesn't necessarily have to come down.

Sussex UK / CT USA
Offline Offline
Edison Member
*
Karma: 0
Posts: 1028
Forums forever
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 10
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 smiley-sad???.
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 634
Posts: 50226
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

0
Offline Offline
Newbie
*
Karma: 0
Posts: 10
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

But...They don't disturb each other if connected on the same line? Thanks for the fast reply! smiley-grin
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 634
Posts: 50226
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 10
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

No NO I meant the line of the breadboard..Sorry I'm still ignorant about electronic... smiley-sad
Logged

Pages: [1]   Go Up
Jump to: