is 1 pull down resistor enough for many push buttons ?

hello guys,
i need to know please if i have 3 or 4 or more pushbuttons, is 1 pull down resistor enough for all of them or not ?

and i need to know the theory behind it please which means if 1 is not enough why ? what will happen ?

thanks in advance and happy new year :slight_smile:

Basically no.

Draw the diagram and you will see it involves joining all the inputs together so then they do not work inderpendantly.

There is no need for any external resistor, connect the button between input and ground and enable the internal pull up resistors. Using pull down resistors is not the correct way to do inputs.

aha great so no resistors, just the buttons directly to arduino and pull up :slight_smile:

btw i was searching on google and found this method of connecting all buttons to 1 analogue input of arduino, do u think it's a good method ?

here is the link : http://www.instructables.com/id/How-to-access-5-buttons-through-1-Arduino-input/?ALLSTEPS

firashelou:
btw i was searching on google and found this method of connecting all buttons to 1 analogue input of arduino, do u think it’s a good method ?

here is the link : http://www.instructables.com/id/How-to-access-5-buttons-through-1-Arduino-input/?ALLSTEPS

The method is fine, whether it is suitable for your particular application is up to you to decide.

Happy New Year.

Regards,

Graham

ghlawrence2000:
The method is fine, whether it is suitable for your particular application is up to you to decide.

Happy New Year.

Regards,

Graham

aha ok thanks, and one more thing the pull up resistor is on the arduino board of on the atmega chip itself ?

Yes

As of Arduino 1.0.1, it is possible to enable the internal pullup resistors with the mode INPUT_PULLUP. Additionally, the INPUT mode explicitly disables the internal pullups.
Syntax

pinMode(pin, mode)
Parameters

pin: the number of the pin whose mode you wish to set
mode: INPUT, OUTPUT, or INPUT_PULLUP. (see the digital pins page for a more complete description of the functionality.)

Regards,

Graham

@firashelou : completely off topic, but I've been wondering for several days now..... why do you (almost) always start your answer by "aha" ? :grin:

aha...ppy new year :wink:

alnath:
@firashelou : completely off topic, but I've been wondering for several days now..... why do you (almost) always start your answer by "aha" ? :grin:

aha...ppy new year :wink:

hahahahaha ! just an expression means ah ok or ah right :stuck_out_tongue:

enjoy ur night :smiley:

I hope the following will be useful to people getting started with the "joys" of connecting switches for input... it includes the matter of the internal pull-ups...

This is my web page on the topic:-
http://www.thebox.myzen.co.uk/Tutorial/Inputs.html

Thanks a lot for the help :slight_smile:

firashelou:
I was searching on google and found this method of connecting all buttons to 1 analogue input of Arduino, do u think it's a good method ?

It is clever, and works to some extent.

Note that again, the article shows buttons connected to 5V whereas they should be connected to ground and you can use the internal pull-up with Analog inputs.

My experience is that it is used very commonly on the button interfaces for video monitors and MP3 players. What then goes wrong, especially for MP3 players kept in sweaty pockets - is that the switches (which sometimes contain lubricant) become contaminated with moisture and salt, and this produces a spurious parallel resistance which then causes the switch functions to mysteriously "migrate" from one to the other and eventually become "stuck" on.

If you are using top quality switches, it could be durable, but that is the risk.

Paul__B:
It is clever, and works to some extent.

Note that again, the article shows buttons connected to 5V whereas they should be connected to ground and you can use the internal pull-up with Analog inputs.

My experience is that it is used very commonly on the button interfaces for video monitors and MP3 players. What then goes wrong, especially for MP3 players kept in sweaty pockets - is that the switches (which sometimes contain lubricant) become contaminated with moisture and salt, and this produces a spurious parallel resistance which then causes the switch functions to mysteriously "migrate" from one to the other and eventually become "stuck" on.

If you are using top quality switches, it could be durable, but that is the risk.

ok so you saying about the guy's method, he should connect them to Gnd and use the pullup resistor but he must use resistors for every pushbutton to be able to get the right value on analog pin

firashelou:
ok so you saying about the guy's method, he should connect them to Gnd and use the pullup resistor but he must use resistors for every pushbutton to be able to get the right value on analog pin

That's about the size of it.

Now if the resistors are carefully selected, their values will progress in a binary sequence with equal steps according to how many buttons are pressed simultaneously and the analog value can be simply right-shifted to get a number from 0 to say, 7 which can be directly used in a "case" statement with the individual bits in the number representing particular buttons.

Paul__B:
That's about the size of it.

Now if the resistors are carefully selected, their values will progress in a binary sequence with equal steps according to how many buttons are pressed simultaneously and the analog value can be simply right-shifted to get a number from 0 to say, 7 which can be directly used in a "case" statement with the individual bits in the number representing particular buttons.

i didn't really understand what do you mean :frowning:

firashelou:
i didn’t really understand what do you mean :frowning:

Yes, I had the same feeling. In theory he is right, but I am struggling to figure out how to implement it.

So we define S1, S2, S3, S4 as bit 0, bit 1, bit 2, bit 3, we define R1 as 1k, R2 as 2k, R3 as 4k, R4 as 8k.

This would give equivalent resistances of

0 0 0 1 1000.00 
0 0 1 0 2000.00 
0 0 1 1 666.67 
0 1 0 0 4000.00 
0 1 0 1 800.00 
0 1 1 0 1333.33 
0 1 1 1 571.43 
1 0 0 0 8000.00 
1 0 0 1 888.89 
1 0 1 0 1600.00 
1 0 1 1 615.38 
1 1 0 0 2666.67 
1 1 0 1 727.27 
1 1 1 0 1142.86 
1 1 1 1 533.33

Which is clearly useless. So reversing the order of value for R1-R4 gives R1 as 8k, R2 as 4k, R3 as 2k, R4 as 1k and thus equivalents of :-

0 0 0 1 8000.00 
0 0 1 0 4000.00 
0 0 1 1 2666.67 
0 1 0 0 2000.00 
0 1 0 1 1600.00 
0 1 1 0 1333.33 
0 1 1 1 1142.86 
1 0 0 0 1000.00 
1 0 0 1 888.89 
1 0 1 0 800.00 
1 0 1 1 727.27 
1 1 0 0 666.67 
1 1 0 1 615.38 
1 1 1 0 571.43 
1 1 1 1 533.33

Which now at least runs in chronological order…

So now choosing an arbitrary value for R5 of 2k would give analogue values of :-

0 0 0 1 204 
0 0 1 0 341 
0 0 1 1 438 
0 1 0 0 511 
0 1 0 1 568 
0 1 1 0 613 
0 1 1 1 651 
1 0 0 0 682 
1 0 0 1 708 
1 0 1 0 730 
1 0 1 1 750 
1 1 0 0 767 
1 1 0 1 782 
1 1 1 0 795 
1 1 1 1 807

Maybe Paul__B can pick up from here… I can’t figure it out beyond here…

Regards,

Graham

Layout.JPG

OK, since you did the spreadsheet, do the calculation instead for R5 as 100 ohms. :smiley:

In practice, you would want the switches to ground and R5 to +5V. You then just subtract the number from 1023.

:astonished: :confused: :slightly_frowning_face: :kissing:

Thanks Paul.

Actually not a spreadsheet, easier to write a sketch…

double R1[4] = {8000.00, 4000.00, 2000.00, 1000.00};
double R2 = 100.00;
int total;
//int V = 5;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  int s1, s2, s3, s4;
  double effective;
  for (int n = 1; n < 16; n++) {
    effective = 0.00;
    s4 = (n & 0x08 ? 1 : 0);
    Serial.print(s4);
    Serial.print(" ");
    s3 = (n & 0x04 ? 1 : 0);
    Serial.print(s3);
    Serial.print(" ");
    s2 = (n & 0x02 ? 1 : 0);
    Serial.print(s2);
    Serial.print(" ");
    s1 = (n & 0x01 ? 1 : 0);
    Serial.print(s1);
    Serial.print(" ");
    if (s1) effective = effective + (1 / R1[0]);
    if (s2) effective = effective + (1 / R1[1]);
    if (s3) effective = effective + (1 / R1[2]);
    if (s4) effective = effective + (1 / R1[3]);
    effective = (1 / effective);
    //    Serial.print(effective);
    //    Serial.print(" ");
    total = 1023-((R2 / (R2 + effective)) * 1023);
    Serial.print(total);
    Serial.println(" ");
  }
}

void loop() {
  // put your main code here, to run repeatedly:

}
0 0 0 1 1010 
0 0 1 0 998 
0 0 1 1 986 
0 1 0 0 974 
0 1 0 1 962 
0 1 1 0 951 
0 1 1 1 940 
1 0 0 0 930 
1 0 0 1 919 
1 0 1 0 909 
1 0 1 1 899 
1 1 0 0 889 
1 1 0 1 880 
1 1 1 0 870 
1 1 1 1 861

Now what do ‚Äėwe‚Äô do? :o You know here in UK is now 2am? I am too old/tired/drunk for this on a Friday night‚Ķ

Best wishes.

Graham

firashelou:
:astonished: :confused: :slightly_frowning_face: :kissing:

Stick with it...... we can't be far off!! :wink: :smiley:

Regards,

Graham