Read Vin internally

Hi All,

This is what I ended up doing...

5K between Gnd & D1
20k between Vin & D1

/* Read voltage divider
 * Reads the voltage divider to calculate a battery voltage
 * This software has no warranty, real or implied and is free to distribute and modify 
 */

int batMonPin = A1;                                    // input pin for the divider
int val = 0;                                               // variable for the A/D value
float pinVoltage = 0;                                 // variable to hold the calculated voltage
float batteryVoltage = 0;
float ratio = 2.316;                               // Change this to match the MEASURED ration of the circuit

void setup() {
  
  Serial.begin(9600);                        // open the serial port at 9600 baud
}

void loop() {  
  val = analogRead(batMonPin);      // read the voltage on the divider  
  
  pinVoltage = val * 0.00473;       //  Calculate the voltage on the A/D pin
                                            //  A reading of 1 for the A/D = 0.0048mV
                                           //  if we multiply the A/D reading by 0.00488 then 
                                          //  we get the voltage on the pin.                                  
                                    
                                    
  
  batteryVoltage = pinVoltage * 5.075;    //  Use the ratio calculated for the voltage divider
                                                      //  to calculate the battery voltage
  Serial.print("Voltage: ");
  Serial.println(batteryVoltage);
  
  
  delay(1000);                  //  Slow it down
}

I just played with the ratio until I got the correct reading.

Steve...