Voltage Divider Issues with Analog Input (always reads 1023)

I am doing a basic voltage divider to read the voltage across a 12V NiMH battery.
A simple sketch of the circuit can be seen on the attached picture. As you can see it is nearly identical to many other posts on this forum. My particular values for resistances should be working for any input battery between 0 and 55V.

Additionally, the code I am running looks like this, I am running two methods at once.

int analogInput = 5; /*I have been iterating over all the analog input pins*/
float vout = 0.0;
float vin = 0.0;
float R1 = 98900.0;
float R2 =  9800.0;
int value = 0;

/*I use vin and voltage battery on two different methods*/
float voltage_battery;

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

void loop() {

 checkVoltage();
 read_voltage();
 delay(1000);
}

void checkVoltage(){
  value = analogRead(A5);
  vout = (value * 5.0)/1024.0;
  vin = vout / (R2/(R1+R2));
  if (vin < 0.09){
    vin = 0.0;
  }
  Serial.println("V = ");
  Serial.print(vin);
}

void read_voltage() {
  
  voltage_battery = analogRead(A5)*(98700+9790)/9790*5/1023;
  Serial.println("Other method reads:  ");
  Serial.print(voltage_battery);
}

With this, I consistently get voltage readings on my serial monitor of 55V. When checking through the code I noticed that the Analog was always reading a value of 1023. Shouldnt it be scaling down proportional to the range 0-55V? Any help is greatly appreciated on what I am doing wrong here. Have looked through several forums and no one seems to have quite the same problem as I

Where is the common GND connection in your circuit ?

UKHeliBob:
Where is the common GND connection in your circuit ?

It is connected to the GND pin on the Digital Side of the Arduino.

PaulRB:

Yeah, that attaches to one of the GND pins

What does your multimeter read for the voltage at the analog pin?

PaulRB:
What does your multimeter read for the voltage at the analog pin?

1.192V

Disconnect the analog pin from the circuit and connect it directly to ground. What value from analogRead() then?

run a test, modify your output to see the raw analog pin

===================

void checkVoltage(){
value = analogRead(A5);
vout = (value * 5.0)/1024.0;
vin = vout / (R2/(R1+R2));
if (vin < 0.09){
vin = 0.0;
}
Serial.print("V = “);
Serial.print(vin);
Serial.print(” - A5 = ");
Serial.println(value);

PaulRB:
Disconnect the analog pin from the circuit and connect it directly to ground. What value from analogRead() then?

Yeah, when it is connected to the circuit as shown in the schematic it reads 1023
When it is connected directly to ground, it reads 21

Disconnect the battery. Connect the 100K between 5V and the analog pin and the 10K between the analog pin and ground. What value from analogRead()? What reading on the analog pin from your multimeter?

PaulRB:
Disconnect the battery. Connect the 100K between 5V and the analog pin and the 10K between the analog pin and ground. What value from analog Read()? What reading on the analog pin from your multimeter?

With this, the reading on multimeter indicates .451 V
My code indicates that this reading is of 23V
and the Analog reading is 426 consistent

JosephMitty:
With this, the reading on multimeter indicates .451 V

I would expect 5 * 10 / (100+10) = 0.45V, so multimeter reading is correct.

JosephMitty:
and the Analog reading is 426 consistent

This is not as expected. Should be 1023 * 10 / (100 + 10) = 93

426 is too high. I suspect your Uno is damaged or faulty. Try another Arduino.

PaulRB:
426 is too high. I suspect your Uno is damaged or faulty. Try another Arduino.

The same happens with another Arduino, Im afraid. I checked on all of the Analog pins of this other Arduino. Unfortunately, this one was in my lab for some time before I arrived so I have no way of assuring whether this one is damaged.

Could it be something with the code?

I know this is a far stretch given that all other circuits attached to this arduino are isolated from the voltage divider circuit (Im moving a relay based on the voltage I read) but could this also affect?The other circuit is just the Relay connected to the 2 digital pin.

JosephMitty:
Could it be something with the code?

If you have shown us all the code, not just the parts you think might be important, and the raw values from analogRead() as are you reported and no other calculations have been done to the results, then no, it can’t be the code.

JosephMitty:
…all other circuits attached to this arduino…

So your schematic was incomplete. Remove all other components other than what you show in your schematic and repeat the measurements.

Yeah, this just confirmed my previous guess that the circuit could not be it. When disconnecting the other components and leaving only what is shown in the schematic I still get the same result.

I get analog readouts between 428 and 429 with little noise. Voltage is .45V which by a previous post is in the range of what is expected.

Given that I just went through two UNO boards I was beginning to doubt that it could have been my wiring but it is reassuring that at least I was not that careless on the other, additional circuit.

UPDATE: Got a third UNO and ran the same round of tests(up to connecting to 5V), still have the same result.

Well, this is really odd.

Can you post some properly lit and focussed pictures?

Also post your code with the lines that print the raw analog values.

Overnight I reset all of my equipment: Computer, disconnected all connections and reconnected again this morning. Now it is working and reading analog values that make sense (low 90s for 5V, mid 240s for the 12V) And the voltage is reading correctly on the Serial Monitor.

...Resolved, thank you for your help

No, not realy resolved, because we never found the cause of the problem. My best guess is there was a fault in your original circuit. When you re-connected everything, you unwittingly corrected the error. Its not an uncommon thing and has certainly happened to me a few times.