Reading two buttons on the same Analog pin

Is my schematic correct?

how do you know which value of resistor to choose?

If first button is pressed I should read 2.5V, if second is pressed - 4.18V.

Yes.

R2 and either R3 or R4 form voltage dividers when the button is pressed. For R4, the calculation you need to perform is:

V = VCC*R4/(R4+R2)

V = VCC * 5.1/(5.1+1)

V = VCC * 5.1/6.1

So, if VCC is 5.0 volts, then the resultant voltage at A0 is 4.18 volts.

How's that?

Thanks this is exactly what I'm reading.

I found it hard to read the state of the buttons.

I just want to report state of each of the button if pressed or released

this is the code claude made for me:

#define PIN_ANALOG      A0
#define PIN_BTN1        2
#define PIN_BTN2        3
#define ANALOG_DEBOUNCE 80
#define DEBOUNCE_MS     50

byte lastState = 0, pendingState = 0;
unsigned long analogTime = 0;

byte getState(int v) {
  if (v < 300) return 0;
  if (v < 680) return 1;  // SW1
  if (v < 950) return 2;  // SW2
  return 0;
}

const char* label[] = { "none", "SW1", "SW2" };

struct Btn {
  uint8_t pin;
  bool raw, stable;
  unsigned long t;
  const char* name;
};

Btn btns[] = {
  { PIN_BTN1, HIGH, HIGH, 0, "Button 1" },
  { PIN_BTN2, HIGH, HIGH, 0, "Button 2" }
};

void setup() {
  Serial.begin(9600);
  for (auto& b : btns) pinMode(b.pin, INPUT_PULLUP);
}

void loop() {
  unsigned long now = millis();

  // ── Analog ──
  byte s = getState(analogRead(PIN_ANALOG));
  if (s != pendingState) { pendingState = s; analogTime = now; }
  if ((now - analogTime) > ANALOG_DEBOUNCE && s != lastState) {
    if (lastState) { Serial.print(label[lastState]); Serial.println(" OFF"); }
    if (s)         { Serial.print(label[s]);         Serial.println(" ON");  }
    lastState = s;
  }

  // ── Buttons ──
  for (auto& b : btns) {
    bool r = digitalRead(b.pin);
    if (r != b.raw) { b.raw = r; b.t = now; }
    if ((now - b.t) > DEBOUNCE_MS && r != b.stable) {
      b.stable = r;
      Serial.print(b.name);
      Serial.println(b.stable == LOW ? " ON" : " OFF");
    }
  }
}

I've used this approach for up to 26 buttons on a single analog input, so it can be done. Since I don't play with AI, perhaps someone else will step in to assist.

You need to check if voltage is in range 4.0 till 4.2.
If so, the button is pressed.
You can add more buttons if you like.
But things may go wrong when you press 2 buttons at the same time...

Something like this could work.
I would add a dead band between 780 and 850 or so.
I did not check if these values match your voltage values.

Here is a link that may help: Pushing ADC limits with the perfect multi-button input resistor ladder – Ignorant of Things

What @build_1971 stated in Post #5 holds true here. With two buttons you can determine which of the two buttons is pressed or if both are pressed but going to three or more gets very difficult.

True N-key rollover is not practical with a simple resistor ladder when using more then two buttons.

Are you having problems actually reading the buttons or in acting on the values returned ?

WHat do you see if you print the value returned ?

So I read the value just fine with the buttons I then change the button to conductive copper tape and I am not able to read the values anymore:

I conneect one copper pad via wire -->1k resistor--> arduino GND

I connect another one coppe pad --> 5k resistor -- > arduino GND (not in picture)

one copper pad to A0 and via 1k resistor to Vcc. I accept to read 2.5V at A0 but reads nothing

Yellow wire connected from copper main pad to A0 and thr red wire on the pad is connected to Vcc via 1k resistor

Edit: It is working. I changed the Serial.monitor value therefore there was no printing

I don't recommend it. Cheap stereos in the nineties that were adopting this principle in the late eighties all failed within a decade because of oxidising button contacts.
You can only do this reliably with sealed switches, like reed switches.

Two buttons is OK. You don't need a resistor to ground for the second button.

Analog buttons need analog read to work. Just don't press

1 at a time unless your design uses that.

Note that when you switch analog pins there needs to be time for the ADC to settle (~55 micros) before you can get a good (~110 micros) read. AVR datasheets recommends to read twice and ignore the first one.

Digital is faster except for the bounce.

1.
Where is V in the schematic of post #1?

2.
V = VCC*R4/(R4+R2)
===>
VA0 = (VCC/(R4+R2)) * R4 //voltage divider rule;

Both analogRead and digitalRead need debouncing.

But... OP is not using switches. I see copper blobs.
@hk_jh Please state what your project actually is.

This was a test use of reading to contacts from two dolls on the same pin using copper tape as part of this project

This was a test for reading two contacts from two dolls on the same analog pin using copper tape, as part of this project.

The full project: a sealed box with one open side where a child inserts a doll horizontally until the head touches the far wall. The contact triggers a visual effect on a web page.

The detection is done via a voltage ladder β€” each doll has a copper patch on its head, and two pogo pins on the inner wall connect to different points in the resistor divider, giving distinct analog readings for each doll.

I decided to use a Raspberry Pi Pico as the microcontroller, because it supports USB HID β€” so it appears as a keyboard to any computer without drivers, and can send keystrokes directly to a web page in any browser. No Web Serial API, no special setup needed.

The copper blobs in the photo are prototype contact pads I made for testing before finalizing the design.

To be honest, I’d prolly use hall-effect & magnets. or optical sensors to address this requirement.