Multiple pushbuttons (Note: Need reply ASAP)

For a project, I am planning to connect multiple solderless breadboards to an Arduino, one of which is going to contain LEDs and resistors and the other of which is going to contain two pushbuttons. I need to know if the Arduino can differentiate between the two pushbuttons and if this scheme would work. A reply as soon as possible would be greatly appreciated.

P.S. I am an Arduino newbie and would like an answer explained in non-technical terms.

Sure no problem. Just make sure all the ground lines of the breadboards are wired to the Arduino's ground pin. A switch would wire to a Arduino digital input pin, one pin for each switch. The LED/resistors would wire to Arduino digital output pins.

Lefty

Thanks for the answer. And one more thing: could the Arduino back send which pushbutton was pressed to my computer via serial? And are there any important things to consider when writing the code for this? Thanks again. :)

Its all in how you code it. But yes you could easly code it so when a button is pressed it sends a message to be displayed threw the serial monitor and light up an LED.

One way to think about an Arduino board, is to abstrate it as a ‘black box’ that has a certain number of digital inputs, digital outputs, analog inputs, analog outputs (real PWM outputs), serial data output and input. All these I/O pins can wire to anything that is electrically compatable with voltage level that your specific Arduino board uses, most are +5vdc but a few are 3.3vdc.

Now what relationships or actions that take place between all these I/O pins is totally dependent on the software program, called a sketch, that you develop. About the only restriction is that some signals (audio, video and very high speed digital may run too fast for the fundamental capabilities of the Arduino processor which runs at a 16mhz clock speed.

Lefty

The pushbuttons have (at least) two connections. Conventionally, you connect one contact to the Arduino input pin, and the other connects to Arduino ground. Set the pin to be an input, and enable the 'pullup' resistor by (for example)

push1Pin = 3; //arduino pin 3 has pushbutton 1
push2Pin = 4; //arduino pin 4 has pushbutton 2

setup() {
...
  pinMode(push1Pin, INPUT);
  pinMode(push2Pin, INPUT);
  digitalWrite(push1Pin, HIGH);
  digitalWrite(push2Pin, HIGH);
...
}

It doesn't matter which pins you use (3 and 4 were just examples).

You can read the pushbutton values with digitalRead, e.g.

i=digitalRead(push1Pin);

However, the pushbuttons will "bounce" when they go up and down: it may appear to go on and off really fast for a while, when in fact the button was pressed or released once. Your software must deal with that. Search "debounce" in the forum for ideas. The simplest is just to wait a while (with delay) after you detect the switch changed state.

Has anyone considered using resistors on the switches, you can have virtually as many switches as you want all read by just one analog input, as the switches are pushed the resistance changes and that can be read by the analog pin

Yes there is even a library available for working with buttons on an analog pin.

I've been playing with this recently. There are some obstacles in this. If the power supply to the arduino fluctuates the values reported will vary. This also happens as you add more to the arduino. So you have to compensate for that. Also temperature c an have an effect on the resistor's value. Have a look at my little project. http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1267115381

Thanks digimike i had a look at the link, good work, how about using a voltage ref chip or just a zenner diode set below 3.3 so no matter what the input voltage the ref should always be the same.

Thanks digimike i had a look at the link, good work, how about using a voltage ref chip or just a zenner diode set below 3.3 so no matter what the input voltage the ref should always be the same.

Should not really be nessary. It’s just that the library code (or your own code) reading the analog input needs to be aware that any given switch value can fall within a range of valid voltages, you can’t just depend on a single ‘correct’ analog input value as representing that switch being pressed. This would be a bad practive as there is some small A/D voltage conversion varitation on reading even a steady unchanging analog input voltage. Also a fundmental restriction of using a analog input ‘string of switches’ is that the user must never press more then one switch at a time as the resulting voltage will be invalid.

Lefty

Also a fundmental restriction of using a analog input 'string of switches' is that the user must never press more then one switch at a time as the resulting voltage will be invalid.

I wouldn't say that.

It all depends on the way the buttons and resistors are wired and how you code it. In my example i have it set up and coded to recognize 2 button combinations. Pushing 2 buttons causes the 2 resistors to be in parallel resulting in a different voltage going to the analog pin. So as long as you code it to recognize that value it will be fine. Otherwise if its not programed for it, a button combination would do nothing.