Matthew asks:

My friends and I are working on a VAWT, and we will need a battery bank to go along with it. We would like to be able to use a micro controller to keep track of voltage and amperage over the entire bank (or preferably each individual battery). My question is how can I use a micro controller to do this?

Fantastic! My students just finished installing our 400W vertical axis wind turbine (VAWT) and monitor similarly to how you would like. For this post I am going to assume that you are going to be using 12V car-style lead acid batteries as your bank for the following explanations and math.

In order to monitor the voltage off of your batteries, presumably somewhere between ~11.7V & 14.4V for the car battery depending on its state of charge, you will need to convert the high voltage to a voltage that your microcontroller can handle, typically 5V. One method to accomplish this is through the use of a voltage-divider, which uses a pair of resistors to “scale” the voltage down.

Using the following formula: Vout = (R2/(R1+R2)) * Vin and say a standard resistance for R1 of 10,000Ohms.

So 5V = 14.4V * 10000Ohms / (10000Ohms + R2)

Solve for R2 = R1 / ((Vin / Vout) – 1) or R2 = 10000Ohms / ((14.4V / 5V) – 1)

R2 = 5319.15Ohms

Alternatively you can use a calculator like this one to do the math for you (note: there are more sophisticated calculators that take the effect of current load into account)

I use this reference for finding the closest standard resistor value. In this case the closes resistance equivalent to 5319.14Ohms is 5100Ohms giving you a ~0V to 4.864V (You want to pick the value that is slightly lower then your calculated so as to not go over your 5V ADC limit. i.e. 5600Ohms would result in a max voltage of 5.169V and would potentially damage your microcontroller)

You can also use two resistors in series for R2 in order to more closely match your calculation. i.e. R2 = 5100Ohm + 220Ohm = 5320Ohm which would result in a range of ~0V to 5.001V rather then ~0V to 4.864V.

Your ADC conversion is as follows:

Volts/Bit = 5V / 1024 (10bit) = 0.00489V / Bit

So 14.4V from your ADC would look like 4.864V / 0.00489V/Bit = 995

If your bank consists of more then one battery….say 4 in series, all you have to do is add more dividers. There are two methods of doing this. The first would be to use just one divider on all 4 batteries. This method gives you the most resolution on your max voltage.

The second method is to attach a voltage divider to each battery and use a common ground. This method allows for the monitoring of each battery, although the V/Bit resolution decreases for each successive battery, as shown below.

Now, on to measuring current. A common way for a microcontroller to measure current is with a shunt (a really low resistance high-precision resistor) and a differential microcontroller. If you apply Ohm’s law to the circuit and measure the voltage drop over the resistor you can deduce the current flowing through the bank. Adafruit has a nice little breakout for the INA219 I2C current sensor that can measure up to 26V @ +-3.2A. This might be a bit low power for your application but could act as a good test board. Alternatively, Trossen Robotics has a 30A version that might be a bit more in your range.

I have also had luck with Microchip’s MCP3424’s in the past for such an application, as you can measure the voltage of 3 batteries and the current over the entire bank with one device. You just need to calculate the needed shunt and cooresponding dividers and you are good to go…as shown below:

I hope this has helped to answer your question and good luck with your turbine!

**Don’t forget, everyone is invited to ask a question!**

**Click here!**

“Ask an Educator” questions are answered by Adam Kemp, a high school teacher who has been teaching courses in Energy Systems, Systems Engineering, Robotics and Prototyping since 2005.

Check out all the Circuit Playground Episodes! Our new kid’s show and subscribe!

Have an amazing project to share? Join the SHOW-AND-TELL every Wednesday night at 7:30pm ET on Google+ Hangouts.

Join us every Wednesday night at 8pm ET for Ask an Engineer!

Learn resistor values with Mho’s Resistance or get the best electronics calculator for engineers “Circuit Playground” – Adafruit’s Apps!

## 3 Comments

Sorry, the comment form is closed at this time.

Dude! A voltage divider? Seriously? You’re putting a resistor straight between each battery and the ground. Guess what goes through it? Current!

You know that the impedence of an ADC port is infinite, right? So if you really want to use a voltage divider, you could use way higher resistors, say 150k and 300k.

But the smart answer to this solution is not a voltage divider at all. You know that the voltage of the batteries is 12V, but you also know that it won’t vary from 0 to 12V. So you can also use a voltage substractor to substract a reference voltage, say 8V. So you end up with a nice voltage range that you can measure with your microcontroller, AND you are always in infinite impedence.

What about that?

“You know that the impedence of an ADC port is infinite, right?”

No it’s not. The impedance of _any_ input is never infinite, it’s simply relatively large. For some types of ADCs (SARs, for example), the effective input Z can be a lot lower than you think it is.

Let’s assume Z_input = 1Meg. For your suggested ‘tail’ resistance of 150k, the combined parallel resistance of 150k || 1Meg = ~130k, which throws off expected values by 15%.

An SAR type ADC (as found on the Arduino) uses a sample-and-hold capacitor which needs to be adequately charged in order to yield a good reading. It’s optimized for feed values of around 10k – 50k, so the resistances Adam suggested would draw more current (though still ~1mA), but also yield more accurate data.

It was helpful, I’m going to start playing with this tonight. Thanks 😀