digitalRead() always low

Hi there,

I installed a switch with a 10K pull-down resistor on pin A7 of a Nano.

digitalRead(A7) always return 0, wethr the button is pressed or not.
analogRead(A7) returns 0 when the button is not pressed, but around 1012 when the button is pressed.

Does digitalRead() needs to see exactly +5V (1023) to report HIGH?

I worked around the problem with :
if (analogRead(A7) >=250) {…}

Thanks for your insights.

A7 is analog input only, digitalRead won’t work on it.
You have the switch connecting to 5V when pressed?

Did you set the pinMode of A7 as INPUT?

Why didn't you post your code?

If he's using an Arduino Uno/Pro Mini or other board based on the ATmega328p, digitalRead() does not work on pins A6 and A7 - those are analog only pins.

pinMode() doesn't work on A6 and A7 either - they're only inputs, and only readable via analogRead.

The other analog pins (A0~A5) do work with digitalRead()

The 48/88/168/328-series chips are the only AVRs I know of that have pins like that - it's weird, and I think it's the result of poor planning at Atmel during the development of the device (ie, that the extra two channels were added as an afterthought in the TQFP version of the chip, since they had extra pins "oh might as well hook them up to these two unused ADC channels we have").

Oops, I missed the Nano reference :frowning:

Thanks to all of you,

I Use D3 now and it works OK

Thanks again.