Problems with digitalRead on analogPins

Hey Guys,
I have a problem.
if i read 2 digital signals on 2 analogpins (A6 and A7) on my Arduino Nano Every, i get every time both readouts 1! Where is my mistake? The circuit diagram is attached. The resistorvalues are 3,7M-Ohm. Sorry for my English.

int LINKS = A7;
int RECHTS = A6;

void setup(){
  pinMode (LINKS, INPUT);
  pinMode (RECHTS, INPUT);
Serial.begin(9600);
}

void loop(){
serial.print(digitalRead(LINKS));
serial.print("   ");
serial.println(digitalRead(RECHTS));}

regardless of the switch-position i get (if closed) every time :
1 1
1 1
1 1

Why? Thanks in advance.

There is no digital input on A6 or A7; they're analogue only.
Check here

Oops, sorry, missed the "Every" - not sure, don't have one.

Are you sure you are compiling the program for a Nano Every and NOT for the old Nano?

Steve

@OP - You do know that the code you posted doesn't compile?

Resistor values are ridiculously high for this application. 10k makes a lot more sense.

You probably have to wait longer to allow the 3M7 resistor to pull down the pin (takes a while - stray capacitance and so), and even then that pull-down is so weak the pin may be affected by stray electric fields.

Also, I'm quite sure you'll need to select Tools > Registers emulation: ATMEGA328
EDIT: Just tested with above and Tools > Registers emulation: None (ATMEGA4809)
Both work, so yep, just need to fix your code and resistor values.

What do you expect to read? Firstly a digital read will only ever give a 1 or zero;
secondly the inputs are effectively connected to +5V or floating.

A 3M7 is far too big a value to pull the pin voltage down - remember the recommended source impedance for an anlaog input is around 20k.

This is a strange circuit - what are you trying to achieve?

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.