AnalogRead issue

Hello,

I have an issue when reading a voltage on an attiny841 chip. To understand I wrote this minimal example:

const int vSensePin = A3;
int nUbat;
float Ubat;

void setup() {
// put your setup code here, to run once:
pinMode( 9, OUTPUT); // sets the digital pin as output
pinMode(10, OUTPUT); // sets the digital pin as output

}

void loop() {
// put your main code here, to run repeatedly:
nUbat = analogRead(vSensePin);
Ubat = float(nUbat) * (5.0 / 1023.0);
if(Ubat<=3.15)
{
digitalWrite(9,HIGH);
}
else
{
digitalWrite(9,LOW);
}
if(Ubat<=4)
{
digitalWrite(10,HIGH);
}
else
{
digitalWrite(10,LOW);
}

}

I read the voltage and compare it to two threshold. The higher value (4.0V) correctly work and the LED connected on output 10 bright below 4V on the analog pin, but the 9 stay desperately off even with voltage lower than 3V …

I checked two different chips.

I also inverted output 9 & 10 to check my two leds, they correctly work.

Do you have any idea of the issue ?

Post a wiring diagram of your setup!

I guess you use the board package from the board manager. Which board option did you select?