Measuring voltage is required for the open charge controller project, as we use the voltage to measure the charging of the battery.

Hence we need to be able to reliably and accurately measure voltage. I have written quite a bit before on voltage measurement.

Here are the details on measuring voltage specifically for the open charge regulator project.

Voltage specifications

The charge regulator is designed to work with 12V and 24V systems, hence we must be able to measure the voltage of a fully charged 24V battery bank. This is in the region of 28V DC. Hence we need to be able to measure at least 28V DC. Lets have a range of 0-35V DC, so there is some headroom.

Reference voltage

The regulator needs to have accurate voltage monitoring, even with a varying input power supply.

The microcontroller used (an ATtiny85) can perform analogue to digital conversion using either an external reference voltage, the power supply voltage, an internal 1.1V reference or an external 2.56V reference.

Using an internal reference makes the most sense as it will be buffered from a variable supply voltage but requires no additional components.

The main issue with the internal reference is the variation in the reference voltage. This value will be relatively stable, but there is variation between each IC due to manufacturing techniques. The datasheet for the ATTiny25/45/85 states that the 1.1V reference can vary between 1.0 and 1.2V and the 2.56V reference can vary between 2.3 and 2.8V. This will cause issues unless this variation can be cancelled.

Due to the variation in the reference voltage (each microcontroller will be different) we must perform some form of calibration on each unit. This is explained in more detail in my “accurate voltage measurment” post here.

Basically we apply a know accurate voltage to the microcontroller. We then upload the calibration code. This stores the calibration value within EEPROM on the microcontroller. Once this is done then other code can be run which will use that calibration factor to make accurate voltage measurements which have been adjusted for the variation in the internal reference voltage.

Another benifit of using a claibration factor is that inaccuracies in the actual resistor values used are cancelled out (as long as they stay constant).


We are using a non-isolated voltage divider to reduce the voltage, as shown below. This is simple and low cost. A 5V1 zener diode protects the input to the microcontroller from any spikes or over voltage. A 0.1uF/100nF capacitor smooths the signal to stop any fast variation.

Voltage divider

Voltage divider (ignore the values given for R1 and R2)

The maximum input voltage is 32V DC. This should correspond to the maximum voltage to the ADC on the microcontroller, which is 2.56V DC (as we are using the internal 2.56V reference).

So we know the input and output voltages are related by the equation:

Vout = Vin (R2/(R1+R2)

For our specifications, and using a lower resitor (R2) of 10k ohms, we get:

Vout = 32V x (10k/(R1+10k) =2.56V
So R1 = 115k ohm


(Check here for the theory on voltage dividers.)

If we use 10kΩ as the lower resistor (R1), then R2 is 115kΩ. The standard resistor value near to 115k is 120k Ω, so lets use that value. Total resistance is 130kΩ, so at 32V the current is 0.2mA, consuming 0.0079W (7.9mW). This is very low power consumption.


We need to think about the resolution of this. The microcontroller has an 10-bit ADC, hence the 5V input is converted into 210 levels (1024 levels). Each input level is equivalent to 5/1024 = 0.00488V (4.88mV). This goes through th potential divider to give the voltage level steps of 0.00488 x ((120+10)/10) = 0.063V (63mV).This resolution is perfectly adequate for this application (an accuracy of approximately 0.2% of the full scale).

2 responses to “Charge Controller Project – Voltage Measurement

  1. HI,
    I best begin by outlining that I am in no way a technical professional. I have a small run off river hydro system where I have managed to maintain a constant flow thus maintaining synchronous speed of the generator regardless of the river flow fluctuations. In lieu of direct use of the power I am exploring my options with regard to battery storage. I have in my travels been advised that conventional MPPT Charge controllers are not well suited to a constant voltage input. I have recently played around with a Victron 100vdc-20amp unit. despite the constant voltage input the charge controller was trying to track the voltage similar to that of Solar (i am assuming). Is there an alternative system available or is possible to tweak an existing unit to accept a constant voltage input. Your assistance will be greatly appreciated.

    1. Hi John,
      I think your assumption that the Victron MPPT charger is designed for solar MPPT tracking hence would not be suitable for a micro hydro sources.
      I’d suggest that micro-hydro is very similar to wind turbine systems.
      Solar controller use series control, which means they disconnect the solar PV when the battery is full.
      Wind/Hydro controllers use shunt control, which put the output into a ‘dump’ load when the battery is full.
      I’ve used the Xantrex C60 PWM charge controllers for wind turbines and pedal power items:
      This is good quality, but quite high price. It also needs a dump load made from resistors to dissipate the excess power.

      Lots of (slightly technical) information here:
      Water Teachers Manual
      And also here:

      I dont think its possible to tweak the Victron controller (they are very good, though – you might try dropping them an email about this).
      Bit more detail on wind tubrine controllers (which I think would be suitable for hydro as well, but please check) is here:

      I hope thats some help,
      Regards, Matt

Leave a Reply

Your email address will not be published. Required fields are marked *