Read button state (0mV - 190mV) - analog or digital read?

I want to read the on/off state of a button on an external device. I checked the two wires to the button with a multimeter and it reads 0mV for button-off, and 190mV for button-on.

I just need to reliably get the on/off state of the button and not the actual mV value. Should I use analogRead or digitalRead for this, and how?

Best regards

Should I use analogRead or digitalRead for this, and how?

It won't work using digitalRead() because the voltage never gets high enough. It may work using analogRead() but you won't know until you try it.

As to how to read it, connect a common GND and read the output from the external device on an analogue pin. What range of values do you get ?

Using the example Basics > AnalogReadSerial using A0 and GND, it shows values from 0 to 60-70 sometimes jumping to 700'ish and then back to 0-70. With nothing connected it shows random values from 0 to 1023, which I read is normal. Connecting GND and A0 yields 0.

With the multimeter it reads more or less stable around 190-192mV.

For the record, I use a Nano.

The jump to 700 is worrying, but 0 for off and 60-70 for on sounds useable. If the value is below, say, 30, the switch is off, otherwise it is on.

It actually shows values between 0 and 70 when the button is on, and plain 0 if it is off, so this fluctuation is a bit weird.

Sounds to me like it needs a pullup resistor.

tropicdome: It actually shows values between 0 and 70 when the button is on, and plain 0 if it is off, so this fluctuation is a bit weird.

Now that you have clarified the values that does not sound like such good news.

I will try with a pull-up. Can the internal pull-up be used for analog inputs?

Else I will have to try and find a different way to get the state of the button.

Seems like pinMode(analogInPin, INPUT_PULLUP); did the trick, the values are much more stable now.

Thank you!