# Solar controller with BJT transistor and PIC24 microcontroller to charge 3.6V NiMH batteries

I'm designing a solar controller circuit and am having some confusion about how to switch the BJT on and off. I have a single solar panel charging a battery. The BJT is there to prevent over-charging the battery. I have a microcontroller to monitor the battery voltage and current, and use this feedback to switch the transistor off and on. The microcontroller is powered by those same batteries.

Here's a simplified circuit schematic:

simulate this circuit – Schematic created using CircuitLab

Do I need to figure out the collector current (I_C drawn from the solar panel) based on the current coming out of the microcontroller (I_B)? Or vice versa?

I'm not sure which comes first. I know that I_B is what turns the transistor on and off to allow I_C through.. but I'm confused how to get values for each.

Here's the data on the components: The solar panel typically outputs 5.5V and 170 mA. It has an open-circuit voltage of 8.2 V and a maximum load voltage of 6.4V. (linked here)

The batteries are rechargeable NiMH with 2450 mAh and 3.6 V. (datasheet here)

The microcontroller is the PIC24, which can source up to 25 mA through its I/O port. (datasheet here)

Here's what I'm stuck on:

Typical solar values: V_solar = 5.5 V I_solar = 170 mA

Values for beta, base current, and base-emitter voltage: B=100 I_B = 1 mA (from microcontroller datasheet?) V_BE = .7 V

B*I_B = I_C 100 * 1 mA = 100 mA

I_B = (1.6 - .7) / R = 1 mA R = .9 V / 1 mA = 900 ohms Since I_B > 1 mA, R > 900 ohms = 1k ohm

I obtained I_B from the PIC24 datasheet, where it says output high from an I/O pin is at least 1.6 V when the PIC24 is powered by 2 V, and the current associated with these numbers is 1mA. Is this the correct way to obtain these values from the datasheet?

Revised Circuit (2/10/15):

simulate this circuit

tl,dr: In your case, you don't seem to need charge control at all, and it is more complicated than you seem to sink because of various reasons. Just put a 1N4001 between the solar cell and the battery.

The NiMH battery is a quite low impedance, pulling as much current from the solar cell as available at the cell voltage. During charging, it is likely around 1.4V/cell. This is an output voltage of 4.2 Volts, so in bright sunlight, you likely exceed the 170mA quoted for the maximum power point, expect something like 200-220mA, which is below C/10 of the cells. I have no idea how you want to do NiMH charging control at widely varying charging currents that never exceed C/10 (no -deltaU, no dT/T seems applicable, but let's ignore that).

First thing to notice: Your circuit will not work as drawn. You drew a NPN transistor. It needs a voltage at the base that exceeds the emitter voltage (by around 0.6V) to make it conductive, but the uC has no access to provided the needed 4.8V (battery voltage + 0.6V). You need an PNP transistor instead. In that case, you need to to provide current from the base terminal to a more negative sink. Also, you would connect the emitter to the solar cell in that case. Note that to turn off the transistor, you need the base voltage to go up to 0.5V below the unloaded solar cell voltage, this is around 8V.

Start with the desired collector current (220mA maximum cell output) and take a look into the transistor data sheet. Let's choose a BC327 for it's higher current rating compared to the typical 100mA transistors. Take a look at figure 4 (Saturation region) if you want to have low losses on the transistor, which seems like a good idea now (but see later). They have curves for 100mA and 300mA collector current. As we don't have a lot of energy to waste, choosing a base current at the low end of the neary flat end of the saturation voltage curve is a good idea, which yields something around 4mA if you interpolate between the 100mA and the 300mA curve. To turn in the transistor, at 4.4V solar cell voltage, 200mV transistor drop, and 4.2V battery voltage, you need to sink 4mA at 4.4V-0.6V (emitter-base voltage). To turn it off, base must rise to 8V (see above). This means, you need a pull-up resistor between base and emitter, providing the turn-off voltage from the cell instead of the uC and a diode (1N4148 will do) to protect the uC from that high voltage.

So the circuit looks like this: PNP with emitter to solar cell, and collector to the battery. A resistor connecting emitter with base (the value does not matter much, and something around 100k will provide enough pull-off effect without disturbing the circuit while the transistor is on), a diode and a resistor in series to the uC. The uC needs to sink 4mA to turn the transistor on. This results in an output voltage of 0.4V. So the resistor has to sink 4mA while having 0.4V above ground on the uC end and 3.8V above ground on the diode end. 4mA at 3.4V is 850 ohms. So 900 Ohms in your circuit does not seem off that much.

You will not be happy at all with that circuit for different reasons, though: Constantly sinking 4mA takes too much of the charging current (getting 220mA outdoor on a bright sunny summer day is one thing, on cloudy days, being inside, expect something like 10mA maximum), and you are wasting 4mA of that just to turn that transistor on. Furthermore, when it gets dark, the solar cells draw power due to their leakage current and discharge the battery by operating the transistor in reverse mode (collector acts as emitter, base current is provided by the solar cells and the 100k resistor meant as pull-up, and the emitter acts as collector). Common wisdow is you need to protect against that, for example by putting a diode between the collector and the battery. You will lose voltage there, though. Another possiblity would be a "secondary pull-up" that will pull the base up, even if the emitter supply (the solar cell) fails to provide power, by connecting a resistor from collector to the base terminal. This resistor has to be low enough to pull the base up against the 100k that pulls it down, so go for something like 20k there. Of course adding all these resistors doesn't make the thing more efficient.

Actually, your charging current is very low compared to cell capacity. As estimated above, you only get to C/12 on extraordinary good conditions, you the charging current can safely be considered as "trickle charging" unless you put the device into the beam of a bright headlight 24/7. You don't need any charge control. You just need to prevent discharge through cell leakage, and this can be povided by a single diode between solar cell and battery.

• Extremely helpful, thank you for taking the time to write out this answer! It cleared up a lot of confusion for me; I was definitely over-complicating the whole thing. Commented Feb 9, 2015 at 23:51
• I still have a few questions though, which I hope that you can clear up. You mentioned that it would be safe to charge the battery with just a diode between it and the solar panel, because the current is so low that it would just be trickle charging the whole time.. But I'm still a little concerned about having zero control between the battery and solar panel. I've read that NiMH need to trickle charge at 1/20? In either case, how do I know what the exact self-discharge rate of the battery is? Doesn't that change over time? Commented Feb 9, 2015 at 23:56
• Common knowledge is: you should not trickle-charge NiMH at all. But because in your case, you stay way below C/20 most of the time, the battery will survive it well enough. It's right: You don't know the rate of self-discharge, which is depends on state-of-charge, temperature and cell age, but as long as you provide more energy from your solar cell than the device uses, the remaining energy from the cell just warms up the battery a little. Still, if you are really concerned, turn the charging off a different way: Use a low-threshold FET to short the solar cell to prevent charging. Commented Feb 10, 2015 at 0:15
• Ok, in general the solar panel should provide enough but in worst cast scenarios (cloud coverage over many days), the battery will have to power the system as backup. I think that the FDN304P with a threshold voltage of 1.5 V should be a good choice so that it can be driven by logic level output from the PIC24. Would you agree? Thank you again for all the tips. Commented Feb 10, 2015 at 5:37
• The FDN304P is a P-channl MOSFET, so gate voltage would be refenced to the "+" terminal of the solar cell. You ned an N-channel MOSFET if the "-" terminal of the solar cell and GND of the PIC are connected, but the "+" can be anywhere. Use the FET in parallel to the cell, so it can take over the short circit current, and prevent energy to go into the battery. Commented Feb 10, 2015 at 7:09

The battery is 2450mAh but the solar panel can only put out 170mA, so you don't need a complex charging circuit. Just hook the panel directly to the battery, and you're done!

But how is this possible?

It will take at least 2450/170 = 14.4 hours to fully charge the battery from empty. That is already slower than the standard 10 hour trickle charge rate, but the sun doesn't shine at full brightness for 14 hours so the average current will be even lower. A NiMH battery will not be damaged by charging continuously at this low current.

The purpose of a diode in series is to stop reverse leakage current in the panel from discharging the battery. However the leakage current of such a low power panel is probably insignificant. So put a diode in if you want, but it's probably not necessary.

There is little point switching the charge off if you don't know the state of the battery. If the charging current was known then you could estimate the state of charge by measuring the battery voltage. But you aren't measuring the current so you don't know how much of the voltage is due to charge state and how much is due to charging current.

Therefore you might as well just leave the battery on trickle charge continuously and let it dissipate the small amount of excess charge as heat once it reaches full charge. If kept topped up like this it will stay in balance because eventually all the cells will receive a full charge, even if some get there sooner than others.

My point is: there missing some sensors LDR (light dependent resistor) to detect darkness and day. Its always better to charge a battery during a day.

As it was said before, charging batteries in series is hazardous. They should be carefully balanced and thermo-controlled. Otherwise, they can get unbalanced and discharge under 0V (that can cause permanent damage to batteries).

You can change you batteries for LiPo with Protection Circuit Module PCM for 2S 7.4V 7.2V.

Using a voltage divider V1*(R2)/(R1+R2)=V2 (0-5V) for sensing analog voltage from battery. You will be able to monitor battery status.