Read Vin internally

Hi,

I've had a look around & not found anything on the subject.

Is there any way of internally reading Vin? or must it be read via external means.

I would like to be able to read Vin & view it on my LCD.

Thanks.

Steve...

No, you must reduce it to < 5v externally and read with an analog input.


Rob

Graynomad:
No, you must reduce it to < 5v externally and read with an analog input.


Rob

Ok, thanks Rob.

Steve...

One other think to consider is that unless you have another voltage reference (AREF) then your voltage in is your reference. So, if you tie your VIN to A0, you will always read 1023 from Analog Input 0.

One other think to consider is that unless you have another voltage reference (AREF) then your voltage in is your reference.

Nope.
Vin is the supply to the on-board regulator, which could be 6 to 20 volts.
The default analogue reference is the processor supply voltage, usually 5 volts.

Could a couple of resistors be used to divide Vin, by 4 for example, and read the divided value at an A/D pin?

Yes.

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...