4 Buttons on 1 analog pin - analogRead shows no real difference in output

Hi All,

I have 4 Buttons which are connected to one analog input of my Arduino UNO. All Buttons receive the positive input from the +5V line of the Arduino but each has a different resistor before it

Button 1 --> 33 KOhm
Button 2 --> 47 KOhm
Button 3 --> 56 KOhm
Button 4 --> 68 KOhm

They all connect to the same analog input pin of the Arduino - here A0.

I have also brought the output to GND with a 10 KOhm resistor.

You may see my wiring in the attached picture.

My program is also vey very simple and it's supposed to show the readings when each button is pressed.

unsigned long btnVal;
void setup() {
  Serial.begin(38400);
}

void loop() {
  btnVal = analogRead(A0);
  if (btnVal > 10) { Serial.print(F("VALUE IS: "));Serial.println(btnVal); }
  
  delay(100);
}

My issue is that the buttons do NOT provide really different readings.

Button 1 --> 1020
Button 2 --> 1019
Button 3 --> 1018
Button 4 --> 1017

Firstly I would have expected much higher differences in the readings, but the main issue is, that sometimes the values also do overlap. Button 1 may provide 1021 but also sometimes 1019, or Button 3 may provide 1019 or 1017 and this holds true for all 4 buttons, the may sometimes overlap :frowning:

In this state, I cannot make use of them.

I took the setup from here: MUltiple Buttons on one Analog Input

Can someone tell me what I did wrong???

Kind regards,

Chris

When I look at your resistors, they seem to look to be 33, 47, 56 and 68 ohm. The third band is black, meaning a zero amount of 0. Or your picture is very unclear. But I doubt that.

Please measure your resistors with a multimeter.

Sincerely yours,

Mike

OMG. So, basically I bought the wrong resistors Ohm, as opposed to KOhm? I will have to remove them and exchange them with others.

Would 33 O, 220 O, 330 O and 1 KO be different enough for my purpose?

I do think that you will see a bigger difference when using those. Don't worry about it, you learned something today, always check your components after buying them. When I was still in highschool I roasted 4 74 serie IC's because they dumped them in the wrong container at the store. I drove to the store 4 times (about 12 miles) before I had the sense to check them while in the store. My circuit design was ok.

Have fun,

Mike

Is it possible to use a few digital inputs ?
Most analog pins are digital pins as well, in case you don't have enough digital pins.
I never use such a circuit, because I don't like it. When two or more buttons are pressed, it can result into the detection of the wrong button.

Thanks for your advise, Mikeb1970. I will keep that in mind. As for the other comment, unfortunately I need to use this setup, as I only have this 1 analog input pin left :frowning: All other pins are occupied by SPI, 3 times CS, an IRQ Pin for a player and some LEDs.

You can work this out; change the 10k resistor to 100 ohms (or use 2 56ohms in series = 112, close enough).
How many of those low values did you buy?
If possible, work with what you have there.