Automatic Solar Grid Tie Switch v1.1
Posted on 20/07/2015 by Adam
My solar shed now generates more power than I can regularly use. I wanted a way to use that excess energy, but ensure my battery was kept fully charged.
I’ve recently bought a couple of Arduinos to have a play with. They fit this purpose perfectly. They can run from the battery, but use very little power. Using a voltage sensor (which is a simple, pre-built voltage divider) and a relay board, I can easily change the relay based on the voltage input.
This is my first project, so please be kind on the code. I’m still learning!
[code]/* Automatic Grid Tie Switch v1.1
*
* Using a voltage sensor and a relay board this sketch allows solar panels to feed a charge controller or grid tie converter based on a batteries voltage.
*
* Three status LEDs and a manual override switch add extra functionality.
*
* You can change the voltage where the switch activates by adjusting the maxBattery float variable below.
*
* More info: http://admw.uk/hQ
*/
//Constant vars
const int gtButtPin = 5;
const int battButtPin = 6;
const int autoLEDPin = 7;
const int battLEDPin = 8;
const int gtLEDPin = 9;
const int posRelayPin = 2;
const int negRelayPin = 3;
const int battAnalogPin = A1;
const int numVoltReadings = 10;
// vars that will change
float battVoltage = 0.0;
float maxBattery = 13.4; //Set the voltage at which automatic mode should switch between charge controller and grid tie.
void setup()
{
pinMode(autoLEDPin,OUTPUT); //initialize the led pin as output
pinMode(gtLEDPin,OUTPUT); //initialize the led pin as output
pinMode(battLEDPin,OUTPUT); //initialize the led pin as output
pinMode(posRelayPin,OUTPUT); //initialize the relay pin as output
pinMode(negRelayPin,OUTPUT); //initialize the relay pin as output
pinMode(gtButtPin,INPUT); //initialize the GridTieButton as input
pinMode(battButtPin,INPUT); //initialize the BatteryButton as input
Serial.begin(9600);
}
/**********************************/
void loop()
{
while (digitalRead(gtButtPin) == HIGH) { //while the grid tie manual switch is active, feed the grid tie inveter
digitalWrite(gtLEDPin,HIGH);//turn on GridTie indicator LED
digitalWrite(battLEDPin,LOW);//turn off Charge indicator LED
digitalWrite(autoLEDPin,LOW);//turn off Auto indicator LED
digitalWrite(posRelayPin,LOW);//turn relay to low.
digitalWrite(negRelayPin,LOW);//turn relay to low.
Serial.println("Manual Grid Tie Mode!");//Serial print Grid Tie Mode
}
while (digitalRead(battButtPin) == HIGH) { //while the charge controller manual switch is active, feed the charge controller
digitalWrite(gtLEDPin,LOW);//turn off GridTie indicator LED
digitalWrite(battLEDPin,HIGH);//turn on Charge indicator LED
digitalWrite(autoLEDPin,LOW);//turn off Auto indicator LED
digitalWrite(posRelayPin,HIGH);//turn relay to high.
digitalWrite(negRelayPin,HIGH);//turn relay to high.
Serial.println("Manual Battery Charge Mode!");//Serial print Battery Charge Mode
}
analogRead(battAnalogPin);
delay(20);
battVoltage = (analogRead(battAnalogPin)* 25.0 / 1024);
if (battVoltage <= maxBattery ) //if battery voltage is less than value,
{
digitalWrite(gtLEDPin,LOW);//turn off GridTie indicator LED
digitalWrite(battLEDPin,HIGH);//turn on Charge indicator LED
digitalWrite(autoLEDPin,HIGH);//turn on Auto indicator LED
digitalWrite(posRelayPin,HIGH);//turn relay to high.
digitalWrite(negRelayPin,HIGH);//turn relay to high.
Serial.print("Automatic Battery Charge Mode!");//Serial print Auto Battery Charge Mode
Serial.print(" Battery Voltage: ");
Serial.print(battVoltage);
Serial.println("v");
}
else
{
digitalWrite(gtLEDPin,HIGH);//turn on GridTie indicator LED
digitalWrite(battLEDPin,LOW);//turn off Charge indicator LED
digitalWrite(autoLEDPin,HIGH);//turn on Auto indicator LED
digitalWrite(posRelayPin,LOW);//turn relay to low.
digitalWrite(negRelayPin,LOW);//turn relay to low.
Serial.print("Automatic Grid Tie Mode!");//Serial print Auto Battery Charge Mode
Serial.print(" Battery Voltage: ");
Serial.print(battVoltage);
Serial.println("v");
}
}
/************************************/
[/code]
There are some improvements I know I need to make. I need to adjust my code so that there is a spectrum of voltages where the system can be in either mode. For example, I’d like the switch to feed the grid once the battery has reached float voltage (~13.8 volts), but remain in that mode until the battery hits a lower level (eg. 12.2 volts).
A screen of some sort would also be beneficial – it could display the mode and the current battery voltage.
Please do comment and share and let me know if you use my idea!