If you have a solar installation and you use batteries connected to a load, it doesn't take long to learn you have a real problem on your hands because there just isn't enough solar energy to keep the batteries charged during those long dark cloudy periods.

Preserve the Batteries in your Storage Bank

Tom Woods

Preserve the Batteries in your S
If you have a solar installation and you use batteries connected to a load, it doesn't take long to learn you have a real problem on your hands because there just isn't enough solar energy to keep the batteries charged during those long dark cloudy periods.

Preserve the Batteries in your Storage Bank
with this Voltage Controlled Switch

by Tom Woods www.altenergyweb.com


Where I live in Northern New England, there can be long periods, especially at the turn of the seasons, of dark cloudy weather lasting for weeks or even months. If you have a solar installation and you use batteries connected to a load, it doesn't take long to learn you have a real problem on your hands because there just isn't enough solar energy to keep the batteries charged during these long dark cloudy periods. It's a big problem because batteries can be damaged by subjecting them to a chronically undercharged conditions.

The Solution

This solution uses the grid in a sort of reverse grid tie arrangement. PVs charge the batteries, but the batteries are also connected to the grid by way of a supplementary charger that keeps the batteries topped off even if the load is more than the PV array is capable of delivering during cloudy spells. I've been using this system for the past two years. I have never had to worry about low batteries, and I have always been able to power the load on my inverter, even during the times from October to January when the number of sunny days here can be counted on one hand.

I call the circuit that does this a grid-charger voltage switch. It uses a PIC microcontroller to protect the batteries from chronic low charge by connecting them through a solid state relay to a grid powered battery charger when it is needed. The circuit monitors battery voltage and when it drops below a certain preset voltage it turns on a solid state relay for a selectable period of time from one to four hours. The relay connects the grid powered battery charger. Two jumpers, or DIP switches let you select the amount of time the relay stays switched ON. Refer to the schematic diagram in Figure 1. The ON time select switches 1 and 2 are set as follows:


            1          2          ON Time Duration

            on       on       1 hour

            off       on       2 hours

            on       off       3 hours

            off       off       4 hours

To protect the batteries from overcharge, the PIC will switch the relay OFF if the battery voltage exceeds an adjustable setpoint. In the OFF state, the switch waits for the next low voltage event to occur, and then it recycles.

There is a reset button in the circuit that will manually toggle the relay on or off. Also, whenever you press the reset button to turn the relay OFF, the LED will blink a number of times to indicate how many ON/OFF cycles occurred since the last reset.

Circuit and Board Features

Potentiometers, R3 and R4, are the adjustments to the upper and lower voltage setpoints. R3 trims the battery input voltage which is monitored by the PIC. R4 is a reference voltage adjustment for the turn-on voltage. These two controls allow you to set the voltages at which the relay will turn ON and OFF.

The LED tells you if the circuit is working. It turns ON when the relay is ON. Additionally, the LED blinks when you press the reset button. It blinks the number of times the switch turned on since the last reset.

How to Build the Circuit

The schematic diagram shows the circuit. You can build it up on a printed circuit board, a breadboard, a PIC prototype board, or by other means that you prefer. Please note the 12 volt battery shown in the schematic is actually your alternative energy bank of storage batteries. There is nothing critical in deciding parts placement. Component values are critical, however, particularly the crystal and resistors R3 and R7. R7 must be twice the value of R3.

Refer to the parts list in Figure 2. The battery charger and solid state relay you choose to operate with this circuit will depend on the size of your storage battery bank and the current at which you wish to charge your batteries. The solid state relay must be able to handle the current draw of the charger you choose, plus a safety factor of roughly 25%. The relay must be able to switch 120vac and the control voltage must be at least 3 vdc.

My bank consists of 10 batteries of 125 amp-hour capacity each. I use the DLS-55 charger made by Iota Engineering, capable of delivering 55 amps. The Iota charger is not the cheapest charger you will find on the market, but it is a very well engineered product. It offers precise current control and cool trouble free operation. I chose a 40 amp solid state relay, which is more than adequate to power the charger.

Use care in soldering the components. Avoid blobs of solder that may cause a short between adjacent pins on the board. A 25 watt grounded soldering iron is recommended. Be mindful of static electricity when handling the PIC and other components. Use rosin core solder made for electrical circuits. Do not solder the PIC chip to the board. Instead solder a 14 pin DIP socket to the board and plug the PIC into it after all the components have been soldered first.

Soldering can sometimes be tricky for a beginner. If you lack experience try to get someone to show you how it's done.

Build or Buy

If you lack the skill, knowledge, time, or desire to build the circuit board, or the completed circuit yourself, a variety of kits, preprogrammed PIC chips, and completed units are available for sale at http://www.altenergyweb.com/gridcharger.htm

Iota Engineering info is at http://www.iotaengineering.com/dls.htm

Programming the PIC 16F676

Listings 1 and 2 give the sequence of programming instructions that go into the PIC microcontroller. To program the PIC you need special equipment and knowledge which may be beyond the means of many readers except those who are programming junkies. Everyone else may obtain preprogrammed chips from the altenergy web site shown above.

Testing the Circuit

To test the circuit you will need a voltmeter and an adjustable dc power supply capable of delivering from 5 to 15 volts.

1. To begin, turn the low voltage adjust pot, R3, fully counter clockwise.

2. Turn the overvoltage adjust pot, R4, fully clockwise.

3. Adjust the power supply to a voltage close to that of your storage batteries and connect the power to the circuit board. The LED should turn ON or blink ON, then OFF.

/ Troubleshooting: If the LED does not light or blink when power is supplied, press the reset button to see if that turns it on. If it still does not blink there is something wrong with your assembly and you will need to troubleshoot the cause. Inspect it closely with a magnifying glass for bad solder joints. Check if the PIC or LED is placed backwards or if pins are not properly seated. Test the supply voltage between pins 1 and 14 on the PIC to insure it is 5v. If you did not use the supplied printed circuit board, double-check all your connections against the schematic./

4. Now adjust the power supply to the maximum acceptable voltage for your battery bank. This can be measured conveniently between the points marked A and B at the upper right hand corner of the board. The maximum voltage you choose might be just under 15 volts, which is the over voltage cut-off on many inverters.

5. At this stage the LED should be OFF. If it is ON, press the reset button to turn it OFF. Then turn R3 clockwise until voltage between pin 8 of the 16F676 and ground (point 'B' on the circuit board) measures 2.5 volts.

6. Adjust the power supply to the minimum acceptable voltage for your battery bank. There are several considerations to make when deciding upon the optimum low-end voltage. A higher adjustment will mean the grid charger will turn on more frequently, and you will consume more electricity from the power company, but you will afford greater longevity to your batteries. A lower voltage will mean you get more power from your batteries, but the deeper discharge cycles may shorten battery life. Consult your favorite experts. I chose 11.95 volts for my minimum battery voltage.

7. Turn R4 counter clockwise until the LED turns ON. If you overshoot this adjustment, turn R4 back 1/2 turn, press the reset button to turn off the LED, then slowly turn R4 counter clockwise until the LED lights

Mains and Circuit Board Connections

Run small gauge wires between the control terminals on the relay and the pads on the circuit board labeled Relay + and - in the schematic. The same size wire may be used to bring power to the board from your 12-volt battery array.  Use care not to accidentally reverse the positive and negative leads to the board. Doing so will destroy the voltage regulator chip. You may wish to install a SPST switch in line with the positive wire so that you can turn the unit on and off.

Now it's time to make the 120vac connections. Refer to Figure 3 that shows how one leg of a suitable power cable rated for the current capacity of your charger is series connected to the relay. Put an AC plug on one end and a receptacle to receive the charger plug on the other. Observe safety precautions and electrical codes when working with 120vac. 

After the battery is connected, plug the ac power cable into a wall outlet and plug your battery charger into the receptacle. The charger will now keep your batteries charged once it is hooked up according to the manufacturer's instructions.

You can verify that the unit is operating by manually turning the LED on and off with the reset button. When the LED lights, you can measure a change in voltage (from approximately 0 volts to approximately 5 volts) between the relay control terminals. When this happens your charger will come to life (unless the battery voltage exceeds your high voltage adjustment).

I have been very pleased with the operation of the grid charger voltage switch. It allows me to gain what energy I can from my solar panels while it fills the gaps caused by periods of cloudy weather and protects the expensive batteries from damage due to chronic under charging.

Figure 1. Grid Charger Voltage Switch Schematic Diagram

Listing 1. PIC Software: The Annotated Assembly Listing

;PIC Lead/Acid Grid Charger Control

;Tom Woods 3/1/2006

;This program monitors battery voltage. When it drops below an adjustable

;preset voltage, it turns on a solid state relay that can control a battery

;charger that is connected to the public utility power grid. The relay will

;remain on for a period of time set by jumpers SW1 and SW2, or

;until battery reaches an adjustable preset high voltage cut-off.

;When the relay turns off, charging reverts to the solar or other alternative energy

;source. Grid power will not be switched on until battery voltage again drops

;below the setpoint. A reset switch will toggle the relay OFF and ON. The unit will

;turn itself ON when battery voltage is below the setpoint.

;When the reset button is pressed, the LED will blink the number of times the

;charger has turned on since the last reset.


; Relay ON duration is approximately as follows

; (n=no jumper, y=jumper connected to ground):

;         SW1 SW2  Duration

;          y     y   1 hour

;          n     y   2 hours

;          y     n   3 hours

;          n     n   4 hours


       include "c:\program files\mplab ide\mchip_tools\p16f676.inc"

RELAY  EQU    0      ;Bit 0 (Pin 10) is the relay control line

LED    EQU 1         ;Bit 1 (Pin 9) is the LED line

SW1    EQU 5         ;Jumpers on these bits of PORTC determine Relay ON duration

SW2    EQU 4

SECONDS       EQU h'20'     ;Address of location that stores count of seconds

MINUTES       EQU h'21'     ;Address of location that stores count of minutes

HOURS  EQU h'22'     ;Address of location that stores count of hours

CYCLES EQU h'23'     ;Address of location that stores number of times the charger

                     ;  was turned on since the last reset.

DELAY1 EQU h'24'     ;Address of locations that process a delay during the LED blink.

DELAY2 EQU h'25'

SCRATCH       EQU h'26'

PAUSETIME     EQU h'3'      ;Number of iterations for the wait loop

MAXVOLTS EQU d'128'     ;This value is good when the battery high cut-off voltage

                     ;is trimmed to 2.5 volts as measured at pin 8 and pin 12.


;Summary of 16F676 Pin Assignments

       ;Pin 4  MCLR         Reset Button Input

       ;Pin 5  SW1          Relay ON duration jumpers, SW1, SW2

       ;Pin 6  SW2

       ;Pin 8  A/D          + Battery Voltage Input

       ;Pin 9  LED          Output to LED

       ;Pin 10       Relay         Control Output to relay

       ;Pin 12       Comparator    Battery + Voltage Input

       ;Pin 13 Comparator   Reference Voltage Input


              ORG           0

RESETVECTOR   BSF    STATUS,RP0    ;Select bank 1

              BTFSS PCON,1

              GOTO POWERUP

INITIALIZE    CLRF ANSEL           ;Power ON and button resets initialize

                                  ;the peripherals... 

              MOVLW b'00110100'    ;Make RC2 (pin 8) an input for the A-D (AN6)

                                  ;RC5 (pin 5) and RC4 (pin 6) digital inputs,

              MOVWF TRISC          ;and other lines of PORTC outputs

              BCF STATUS,RP0             ;Select bank 0

              CLRF INTCON          ;disable peripheral interrupts.

                                  ;Initialize A-D converter on AN6 (Pin 8)

              MOVLW b'00011000'    ;Left justified, AN6, VDD=Vref

              MOVWF ADCON0

              CLRF ADRESH          ;Zero out the AD converter

              BSF STATUS,RP0             ;Bank 1

              MOVLW b'01000011'    ;Enable AN6, AN0, AND AN1 (Pins 8,13,12)as analog

              MOVWF ANSEL

              MOVLW b'01010000'    ;Set AD clock to Fosc/16

              MOVWF ADCON1

                                  ;Initialize comparator and timer.

              BSF    TRISA,1              ;Pin 12 is comparator input.

              BSF    TRISA,0              ;Pin 13 is comparator input.

              BCF    STATUS,RP0    ;Bank 0

              MOVLW  b'00000010'   ;Comparator goes high when

              MOVWF  CMCON         ;battery voltage (pin 12) is less than

                                  ; reference voltage (pin 13)

              CLRF   TMR0          ; Clear the clock value

              BSF    STATUS,RP0    ;Bank 1

              MOVLW  b'10000110'



              MOVWF  OPTION_REG

              BCF    STATUS,RP0    ;Bank 0

              BTFSS  PORTC,RELAY   ;What is the status of the relay?

              GOTO   RELAYISOFF


              CALL   LEDBLINK

              GOTO   RELAYOFF



              GOTO   RELAYSET



RELAYOFF      BCF    STATUS,RP0    ;Bank 0

              BCF    PORTC,RELAY   ;Turn OFF the relay and LED

              BCF    PORTC,LED



;At this point everything is initialized and the relay is OFF.

;All we do is watch the voltages and the clock.

COMPARATOR    BTFSS  CMCON,6       ;Is the battery < Vref? (was BTFSS)

              GOTO   RELAYOFF      ;No. Go back and wait.

              CALL   WAIT          ;Yes. Then resample to make sure

              BTFSS  CMCON,6              ;we're not looking at a load spike                            GOTO       RELAYOFF      ;Is battery<Vref? No. Go back and wait.

                                  ;Otherwise we have a true reading and need

                                  ;to turn on the relay.

              CLRF   HOURS         ;Zero out the counters

              CLRF   MINUTES

              CLRF   SECONDS

              CLRF   TMR0

CHECKAD              BSF    ADCON0,0      ;Turn ON the A/D

              BSF    ADCON0,1      ;Read the A/D. Set the GO bit

ADHOLD        BTFSC  ADCON0,1      ;and wait for it to go low (DONE)

              GOTO   ADHOLD

              BCF    ADCON0,0      ;Turn OFF the A/D

              MOVLW MAXVOLTS     

              SUBWF  ADRESH,0      ;Subtract maxvolts from battery volts

              BTFSC  STATUS,C     

              GOTO   RELAYOFF      ;If battery>MAXVOLTS, go back and turn off the relay




                                  ;If Battery < MAXVOLTS...

RELAYSET      BSF    PORTC,RELAY   ;Turn ON the relay

              BSF    PORTC,LED     ; and LED.

TLOOP         MOVLW  d'63'         ;Approximate 'ticks' per second.

              SUBWF  TMR0,0

              BTFSS  STATUS,Z

              GOTO   TLOOP



              INCF   SECONDS,1     ;Once per second

              CLRF   TMR0

              MOVLW  D'60'

              SUBWF  SECONDS,0

              BTFSS  STATUS,Z

              GOTO   CHECKAD


ADVANCE              INCF   MINUTES,1     ;Once per minute

              CLRF   SECONDS

              MOVLW  d'60'

              SUBWF  MINUTES,0

              BTFSS  STATUS,Z

              GOTO   CHECKAD


              INCF   HOURS,1              ;Once per hour

              CLRF   MINUTES

              CALL   ONTIME        ;Find out how long the relay should be ON.

              SUBWF  HOURS,0

              BTFSS  STATUS,Z

              GOTO   CHECKAD              ;Keep counting if time is not up.

              GOTO   RELAYOFFA     ;Shut off and wait when time is up.


LEDBLINK      BCF    PORTC,LED     ;Subroutine that handles the blinking of

              CALL   WAIT          ;the LED equal to the number of times the

              MOVF   CYCLES,W      ;charger was turned on since the last reset.

              MOVWF  SCRATCH                    ;The count is set to zero

              INCF   SCRATCH,1


              BTFSC  STATUS,Z

              GOTO   OUT

BLINK3        BSF           PORTC,LED

              CALL   WAIT

              BCF           PORTC,LED

              CALL   WAIT

              GOTO   BLINK2

OUT           CALL   WAIT

              CLRF   CYCLES



WAIT          MOVLW  PAUSETIME     ;A subroutine to delay

              MOVWF  DELAY1

WAIT1         MOVLW  h'ff'

              MOVWF  DELAY2


              GOTO   WAIT2

              DECFSZ DELAY1,1

              GOTO   WAIT1


ONTIME        CLRF   SCRATCH              ;Subroutine returns with W=# hrs the relay

              BTFSC PORTC,SW1            ;should be ON. Transfer SW2 and SW1 to W bits

              BSF    SCRATCH,0     ;1 and 0. Then increment W so the subroutine will

              BTFSC PORTC,SW2            ;return with W=1,2,3,4

              BSF SCRATCH,1

              INCF SCRATCH

              MOVF SCRATCH,W



POWERUP              BSF PCON,1           ;The initial powerup.

              BCF STATUS,RP0             ;Select Bank 0

              CLRF PORTC

              CLRF CYCLES  

              CLRF MINUTES

              CLRF HOURS

              CLRF SECONDS

              BSF STATUS,RP0             ;Bank 1

              GOTO INITIALIZE


Listing 2. PIC 16F676 Hexadecimal Program Data

PIC 16F676 Program Hexadecimal Code


Addr Values                                          

0000 16 83 1C 8E 28 71 01 91 30 34 00 87 12 83 01 8B

0008 30 18 00 9F 01 9E 16 83 30 43 00 91 30 50 00 9F

0010 14 85 14 05 12 83 30 02 00 99 01 81 16 83 30 86

0018 00 81 12 83 1C 07 28 1F 0A A3 20 50 28 22 20 50

0020 28 37 0A A3 12 83 10 07 10 87 1F 19 28 22 20 60

0028 1F 19 28 22 01 A2 01 A1 01 A0 01 81 14 1F 14 9F

0030 18 9F 28 30 10 1F 30 80 02 1E 18 03 28 22 14 07

0038 14 87 30 3F 02 01 1D 03 28 39 0A A0 01 81 30 3C

0040 02 20 1D 03 28 2E 0A A1 01 A0 30 3C 02 21 1D 03

0048 28 2E 0A A2 01 A1 20 69 02 22 1D 03 28 2E 28 21

0050 10 87 20 60 08 23 00 A6 0A A6 03 A6 19 03 28 5D

0058 14 87 20 60 10 87 20 60 28 55 20 60 01 A3 00 08

0060 30 03 00 A4 30 FF 00 A5 0B A5 28 64 0B A4 28 62

0068 00 08 01 A6 1A 87 14 26 1A 07 14 A6 0A A6 08 26

0070 00 08 14 8E 12 83 01 87 01 A3 01 A1 01 A2 01 A0

0078 16 83 28 03 




PIC 16F676 Configuration Bits

Oscillator:             LP

Watchdog Timer:         Disabled

Power-up Timer:         Disabled

Brown-out Reset:        Disabled

MCLR Pin Function:      Reset

Code:                   Not protected

Data EEPROM:                                   Not Protected



Figure 2. Grid-Charger Voltage Switch Materials



PB1                1                      reset switch (momentary, normally open)

SW1,SW2      1                      ON time select DIP switches or jumpers



C1                   1                      .1uf     electrolytic    

C2                   1                      10uf    electrolytic capacitors         

C3, C4            2                      18pf    ceramic capacitors



R1                   1                      2k        1/4 watt resistor       

R2, R5, R6    3                      10k      1/2 watt resistor       

R3, R4            2                      50k      multi-turn potentiometer    

R7                   1                      100k   1/4 watt resistor



LED1              1                      LED    5mm T1

U1                   1                      78L05 5v 3 terminal voltage regulator

U2                   1                      PIC 16F676



XT1                 1                      32.768khz crystal    

DIP14             1                      14 pin DIP socket

                        1                      Printed Circuit Board or breadboard

                        1                      120vac Solid State Relay

                        1                      120vac Battery Charger

Figure 3. Relay Connections Diagram

The content & opinions in this article are the author’s and do not necessarily represent the views of AltEnergyMag

Comments (0)

This post does not have any comments. Be the first to leave a comment below.

Post A Comment

You must be logged in before you can post a comment. Login now.

Featured Product

OMNISTAR GAS ANALYZER - Fast accurate analysis from % to sub-ppm in a compact, turnkey benchtop system.

OMNISTAR GAS ANALYZER - Fast accurate analysis from % to sub-ppm in a compact, turnkey benchtop system.

The Pfeiffer Vacuum OmniStar benchtop analysis system offers you a compact footprint, powerful software and Ethernet connectivity. It's the optimum solution for many real-time gas analysis applications. With the OmniStar, Pfeiffer Vacuum offers you a complete solution for gas analysis, in chemical processes, semiconductor industry, metallurgy, fermentation, catalysis, laser technology and environmental analysis. The turnkey OmniStar gas analysis system consists of heated, temperature-regulated gas inlet system, Quadrupole mass spectrometer, a dry diaphragm vacuum pump and HiPace turbopump. Unlike competing methods such as FTIR, OmniStar is suitable for qualitative and quantitative analysis of most gases.