solar and wind backup charging system...on those cloudy windless days

hi there, my name is Joe

i am fairly new at arduino and this forum. i do have good knowledge on electronics though.

what i am working on is a backup charger for my battery bank, it runs 5 cabins for a remote fishing/hunting resort. what i need is to have something monitor the voltage in the batteries, and when they fall below a certain point ( 10.5 volts ) it will power down the inverter, then power up the generator, and then switch the cabins from the inverter to the generator.

then when the batteries have been charged up to 14.5 volts, it will kill the gen, switch from gen to inverter, and then power up the inverter.

this is what i have for code ( i copied some parts to here and some i wrote myself )

const int referenceVolts = 5; // the default reference on a 5-volt board
const int R1 = 3000; // value for a maximum voltage of 20 volts
const int R2 = 1000; // determine by voltage divider resistors, see text
const int resistorFactor = 255 / (R2/(R1 + R2));
const int batteryPin = 0; // +V from battery is connected to analog pin 0
int outPin0 = 13; // power to generator starter
int outPin1 = 11; // power to switch inverter off
int outPin2 = 9; // power to switch from inverter to A/C generator

void setup()
{
Serial.begin(9600);
pinMode(outPin0, OUTPUT);
pinMode(outPin1, OUTPUT);
pinMode(outPin2, OUTPUT);
}

void loop()
{
int val = analogRead(batteryPin); // read the value from the sensor
float volts = (val / resistorFactor) * referenceVolts ; // calculate the ratio
Serial.println(volts); // print the value in volts

if (volts <= 10.5)

{
digitalWrite(outPin1, HIGH); // turns inverter off
delay(2000);
digitalWrite(outPin0, HIGH); // starts generator
delay(2000);
digitalWrite(outPin2, HIGH); // switches from inverter to A/C
}

else (volts = 14.5);
{
digitalWrite(outPin0, LOW); // kills generator
delay(2000);
digitalWrite(outPin2, LOW); // switches from A/C to inverter
delay(2000);
digitalWrite(outPin1, LOW); // powers on inverter
}

}

I think it should work...like i said i dont have much experience with arduino but i think its pretty cool

thanks for looking

I would sample the generator output to be sure it actually started. Is 2 seconds enough time for it to come up to speed and stabilize? Does it matter if the sun come out while the generator is running (probably not). What happens if the generator doesn't start? Are you going to retry it or is there auto start circuitry in the generator? What happens if the generator dies? Is it ok for the generator to start at night while the patrons are sound asleep? How about if the site doesn't have any guests, do you want to use the fuel or just shut off the inverter and wait for the sun? 10.5 volts sounds a little low, but you know your batteries better than I do. The same with the 14.5 volts, I put my batteries on float at 13.4, but you're trying to get a full charge, so that may be ok. Like I said, you know your batteries better than I do. I would also sample the fuel for the generator, it would be nice to alarm somehow if it is getting low. If you choose to sample the generator output, that would be a good check to make before turning the inverter back on; you don't want them both on at the same time (bad for most inverters).

I'm assuming you already have the various start up currents necessary taken care of with big enough relays and such.

I'll shut up now.

This looks odd:

else (volts = 14.5);

I'm not sure what it's supposed to do, but what it does is set volts to 14.5 if volts is > 10.5. To make matters worse The block of code after it is run unconditionally - i.e. it runs on every iteration of loop.

the generator is electric start, and is very dependable, it has 3000 watts a/c and it is wired into the cabins to power them when the batteries are drained. the 2 seconds is a delay between between relays just for safety reasons.(did i do that wrong?) if the sun comes out while the gen is charging the batts, it wont matter because my solar system will be switched off. it never even dawned on me that i should have failsafe!! thank you so much
i guess ill need a way to check if the gen powered up, and one for fuel level. im using 2 12 volt batteries...i cant remember the brand but it looks like an oil radiator sorta, its got 6 huge cells cant remember the amp hours either. and i ordered 6 6 volt golf cart batteries. what should i be charging these to? and when do you think the gen should kick on?

for now though, i just want to figure out how to get the very basics working.

wildbill- that is suppose to turn off the relay that powers the gen and power back on the inverter when the battery level has reached 14.5 volts. i think i just figured out what i did wrong there. its been ages since i did any kind of programming :frowning:

thanks a bunch for the help, when i finish the whole thing im gonna make an instructable

What wildbill was hinting at with the expression

else (volts = 14.5);

is that the = sign is an assignment operator and will set the variable volts to 14.5 what you wanted there was

else if (volts == 14.5)

or more likely

else if (volts >= 14.5)

Lead acid batteries are a mystery. I've read literally hundreds of articles on them and still come away confused. My recommendation is to charge them up to 14.5 and shut the charging off. Then keep an eye on the electrolyte level. If it goes down, lower the charge voltage and see what happens. I float my batteries at 13.4 to keep them charged and avoid rapid water loss. I still have to add water once in a while, but usually not for a couple of months. I learned that trick right here on this board. If your generator has a fuel gauge, you can leverage it to tell you the fuel level; if it doesn't, think about a float or something to tell you how much you have or maybe trip something when it reaches a certain point.

As for kicking in the generator, call one of the manufacturers and talk to them. They'll know the best point for you to stop discharging and kick in the generator. The deep discharge batteries will work pretty well down to 10.5 and recover nicely, but they take a while to charge so remember that. I love calling the manufacturers; they like to talk about their product and can usually save you a bunch of testing to figure it out yourself.

You can monitor the voltage output from the generator to make sure it is running and the alternator is doing it's job, but remember to do it safely. I recommend getting a cheap bell transformer, putting it across the line and using the stepped down and isolated voltage it will give you. Stick a bridge rectifier and voltage divider on the low voltage side to get a value the arduino can read and you have your monitor. The big reason for using the transformer is to make it safer if you have to check something in a rain storm !! Try to keep the line voltage way far away from the arduino. If you make a mistake there you'll get to order a new board or two.

The delay looks to me like it will work, but I recommend that you take a look at the timeAlarm library. I use this a LOT to time things because I don't have to hang the processor in a loop just waiting around. You can set a pin, set an timer for two seconds later and go do something else; the timer will expire and then you can do the next thing. I use this trick all over my house for various timed operations. You can also set an alarm to start the generator on Saturday at 10:00 AM and run for 15 minutes to make sure everything is ok. This way you can set up monitors for the test start and sound alarms if something doesn't work.

Lastly, think about a watchdog timer. As you get more sophisticated with the device, you may make a mistake in the code and have it hang up. Or, there may be a bug in some library you're using that will do the same thing. A watchdog will automatically reset the board and clean up various problems for you. It's in the wdt code and you can find information about it on the wiki or playground. I use the watchdog timer on every board I have running. I hate having them hang up. When you do real control applications, it's nice to have something watching out for you.

Have fun.

Forgive me if it is already in the above, but....

With any such system: Build in some hysterisis

By which I mean:

Fix it so that IF the generator comes on at all, then it will run for at least, say, 10 minutes.

Such things (internal combustion engine powered devices generally, especially those started by an electric motor served by a lead acid battery) do not take kindly to "short cycling", e.g. being started once every ten minutes, but only being allowed to run for 20 seconds each time.

While obviously, you wouldn't PLAN on your system invoking short cycling, do all that you can to design it so that even when something isn't working as expected, short cycling scenarios are not likely.

Discrete modules which say "if I come on at all, I will stay on for at least..." are available... talk to your local HVAC contractor.