Automatic engine/generator control

I am a newbee
I live "off grid" in western Montana and would like to use the Arduino to start a diesel engine/generator and charge a battery bank.

I would like to detect when the battery bank is low and automatically start the charging cycle. I feel sure there is someone out there that has created the code to do this job but don't know where to look. Any help would be greatly appreciated.

You need to provide specifics of the electrical and mechanical controls for your equipment and how they operate before code can be suggested.

Thanks for responding to my call for help.

The goal is to have the Yanmar diesel engine start automatically when the battery voltage reaches the low voltage set point (22 VDC). The battery bank is made up of 2 strings of 20 cells each of NiFe batteries with each string wired in series to provide 600 Amp Hours @ 24 volts DC. Fully charged when 33 volts is reached. These batteries need to charge at a C5 rate or 120 amps @ 33 volts.

The starting sequence:
when the battery voltage drops <= set point
glow plugs on for 90 seconds
starter spins engine for 30 seconds
if engine does not start
try again in 60 seconds
try this routine 3 times then sound alarm if engine does not start

if engine starts
when engine oil pressure > 5 psi ... shut off starter
set engine warm up to 750 RPM for 3 minutes
monitor engine oil pressure and water temp
shut down engine if oil pressure drops or water temp goes too high
read generator amp output via signal from shunt
read generator volts
when battery volts reach 33 VDC
reduce engine RPM for 3 minutes
shut down engine
Ideally the program will report to the computer screen
engine rpm
amps and volts output
engine oil pressure and temp
engine run time for this session
total amp hours generated

This might be more information than you need but will give a better idea of what I am trying to achieve.

Thanks in advance for any and all help

Mac

33 volts is high for a 24 volt alternator to put out.

Arduino voltmeter
http://www.google.com/search?q=arduino%20voltmeter&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a&source=hp&channel=np

tachometer
http://www.google.com/search?q=arduino%20voltmeter&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a&source=hp&channel=np#hl=en&client=firefox-a&hs=URL&rls=org.mozilla:en-US%3Aofficial&channel=np&sclient=psy-ab&q=arduino+tachometer&oq=arduino+tacho&aq=0&aqi=g4&aql=1&gs_l=serp.1.0.0l4.53134.56178.0.57990.14.14.0.0.0.7.1128.4938.0j7j1j2j0j3j0j1.14.0.eish.1.0.0.JFd-r3sMr1U&pbx=1&bav=on.2,or.r_gc.r_pw.r_qf.,cf.osb&fp=5878b6447359618&biw=1024&bih=638&safe=images

Oil pressure
http://www.google.com/search?q=arduino%20voltmeter&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a&source=hp&channel=np#hl=en&client=firefox-a&hs=H7f&rls=org.mozilla:en-US%3Aofficial&channel=np&sclient=psy-ab&q=arduino+oil+pressure&oq=arduino+oil+pressure&aq=f&aqi=g2&aql=1&gs_l=serp.12..0l2.0.0.2.15032.0.0.0.0.0.0.0.0..0.0.eish.1.0.0.viNBCgLIt-I&pbx=1&bav=on.2,or.r_gc.r_pw.r_qf.,cf.osb&fp=5878b6447359618&biw=1024&bih=638&safe=images

This would be a good candidate for a state machine - search the forums for examples.

Edit: Such as this one: http://arduino.cc/forum/index.php/topic,106335.0.html

Interesting project idea!

How are you controlling engine speed of the generator unit?

Also, you'll probably find you'll get oil pressure > 5psi just on the starter, especially when the oil is cold. Might need a higher set point, or use an engine RPM signal or the output of the alternator/generator to signal 'engine started' or 'engine running' to the controller.

Have fun and I look forward to seeing this project progress!
Ryan.

Thanks for all the response to my request for help.

Regarding the signal from the oil pressure to cut power to the starter ... there are other options that could be used such as RPM of the engine, voltage output from the AC generator, voltage output from the engine alternator, etc. At this point .. don't know which one would be best ... but there are options.

Being a "newbee" I am not familiar with the term "state machine". some education would appreciated

33 volts is what is the ideal for charging my bank of nickle/iron batteries. I plan to obtain this voltage via an AC transformer prior to the rectifier changing to DC

I am currently working on learning some basic code to program the Arduino. Getting the picture on most of it but have hit a glitch on getting the "if" statement to work in my program. Here is my code so far ... any help would be appreciated

/* The goal is to have the Yanmar engine start automatically when the battery voltage reaches the low voltage set point.
The battery bank is made up of 2 strings of 20 cells each of NiFe batteries with each string wired in series
to provide 600 Amp Hours @ 24 volts DC. Fully charged when 33 volts is reached */

void setup()
{
//for (int count = 1; count <= 10; count ++);
}

void loop()
{
// for (int count = 1; count <= 3; count ++);
{
int glowPlug=8;
int starter = 7;
int oilPres = 2;
int count =0;

pinMode(glowPlug, OUTPUT); // initialize the glowPlug pin as an output (RED).
pinMode(starter,OUTPUT); // initialize the starter pin as an output (YELLOW)
pinMode(oilPres,OUTPUT); // initialize the engine oil pressure as an output (GREEN)

for ( count = 1; count <= 3; count ++);
{
digitalWrite(oilPres, HIGH); //yellow LED turn on
delay(800);
digitalWrite(oilPres, LOW); //yellow LED turn off

digitalWrite(glowPlug, HIGH); //red LED turn on
delay(400);
digitalWrite(glowPlug, LOW); // red LED turn off

digitalWrite(starter, HIGH); //green LED turn on
delay(300);
digitalWrite(starter, LOW); //yellow LED turn off
delay (2000);
}

}
}

Thanks in advance for all your help and encouragement

Mac

First, you need to use code tags. Look for the # button above the smiley faces.

code goes here

Here is a general rule for a beginner when writing your code. Keep in mind this rule is just to help you get started. Once you get a better understanding you will find reasons to do things differently. You need to write your code in this format:

put your definitions here such as:
int  glowPlug=8;

void setup()
{
put anything that says pinMode here:
  pinMode(glowPlug, OUTPUT);   // initialize the glowPlug pin as an output (RED). 
}


void loop()
{
  put the code here that you want to run over and over
    digitalWrite(oilPres, HIGH);    //yellow LED turn on
  delay(800);
  digitalWrite(oilPres, LOW);    //yellow LED turn off
}

I recommend that you start by trying the example called "blink without delay". Really, you should try as many examples that you have the hardware for. They will help you get a quick understanding of how the code works.

I have watched a bunch of videos and read a considerable amount regarding Adruino programing. Successfully written code for simple sketches that have worked just fine.

However, have been working on this code for over a week and the only way I could get it to work was with the above code. I understand that this is not the correct procedure but ....

Here is the message I get when I try to compile the following code

I feel sure there is some simple thing I am overlooking but would appreciate any help

Yanmar_start_3:24: error: 'oilPres' was not declared in this scope
Yanmar_start_3:28: error: 'glowPlug' was not declared in this scope
Yanmar_start_3:32: error: 'starter' was not declared in this scope

void setup()
{

int glowPlug=8; //sets glowPlug to pin 8
int starter = 7; //sets starter to pin 7
int oilPres = 2; //sets oilPress to pin 2

pinMode(glowPlug, OUTPUT); // initialize the glowPlug pin as an output (RED).
pinMode(starter,OUTPUT); // initialize the starter pin as an output (YELLOW)
pinMode(oilPres,OUTPUT); // initialize the engine oil pressure as an output (GREEN)
}

void loop()
{
// for ( count = 1; count <= 3; count ++);

digitalWrite(oilPres, HIGH); //green LED turn on
delay(800);
digitalWrite(oilPres, LOW); //green LED turn off

digitalWrite(glowPlug, HIGH); //red LED turn on
delay(400);
digitalWrite(glowPlug, LOW); //red LED turn off

digitalWrite(starter, HIGH); //yellow LED turn on
delay(300);
digitalWrite(starter, LOW); //yellow LED turn off
delay (2000);
}

The compiler is complaining that those variables aren't declared because you have made them local to setup. This should be better:

     int  glowPlug=8;    //sets glowPlug to pin 8
     int starter = 7;    //sets starter to pin 7
     int oilPres = 2;    //sets oilPress to pin 2

void setup() 
  {
     pinMode(glowPlug, OUTPUT);   // initialize the glowPlug pin as an output (RED). 
     pinMode(starter,OUTPUT);     // initialize the starter pin as an output (YELLOW) 
     pinMode(oilPres,OUTPUT);     // initialize the engine oil pressure as an output (GREEN)
  }
 
 
 void loop()
 {          
    // for ( count = 1; count <= 3; count ++);
         
           digitalWrite(oilPres, HIGH);    //green LED turn on
           delay(800);
           digitalWrite(oilPres, LOW);    //green LED turn off
              
           digitalWrite(glowPlug, HIGH);  //red LED turn on
           delay(400);
           digitalWrite(glowPlug, LOW);   //red LED turn off
          
           digitalWrite(starter, HIGH);    //yellow LED turn on
           delay(300);
           digitalWrite(starter, LOW);    //yellow LED turn off
           delay (2000);
 }

Thanks for all your help .. Thanks to all of you I have my code working well so far

The next step is to come up with a way to read the RPM of my diesel engine driving the generator. A while back I purchased a hand held RPM meter that seems to work pretty well. A piece of reflective tape is stuck to something that spins (in my case it is attached to the generator drive pulley). There is an opaque red light that comes from the hand held and when aimed at the reflective tape the RPM reading is recorded.

From what I have read there are various ways to receive a signal from a spinning object. However, being a novice at all this and being without any electronic background I need help selecting the best and most economical method to read the RPM that I can feed into the Arduino.

I feel sure there is a logical answer to this challenge and someone in this group has the answer

Thanks in advance for your help

montanamac:
From what I have read there are various ways to receive a signal from a spinning object. However, being a novice at all this and being without any electronic background I need help selecting the best and most economical method to read the RPM that I can feed into the Arduino.

IMO the most accurate and inexpensive way to measure RPM is to use a Hall Effect sensor. These can be purchase for less than 1 USD. The output is normally open collector and in the presence of a magnetic field will pull the output low. I use a pullup resistor to get a 0-5v TTL level signal to feed the Arduino.

Keep in mind there are several types of Hall-Effect sensors, so you will need to do some research to get one that is appropriate to your application.

What model Yanmar are you using? I would be surprised if it did not already have a sensor for rpm or a hole to put one in. Check other manuals for more highly integrated units of the same displacement/configuration as even if you have a pretty bare block they probably used the same block casting for more integrated gen sets marine motors etc. Assuming they did that's probably your best choice to get RPM data.

My Yanmar is a 3 cyl with a cast iron block & head that I purchased used. It does not have a governor and I suspect the original use might have been intended for a tractor or some other implement. there is a number T767
Don't know if this is any help.
The engine came complete with generator, starter, radiator, etc.
Any idea where would I look for a tachometer signal sending unit or a place for the same?

montanamac:
My Yanmar is a 3 cyl with a cast iron block & head that I purchased used. It does not have a governor and I suspect the original use might have been intended for a tractor or some other implement. there is a number T767
Don't know if this is any help.
The engine came complete with generator, starter, radiator, etc.
Any idea where would I look for a tachometer signal sending unit or a place for the same?

Unfortunately that number does not seem to pop anything up for a yanmar engine. The tach sensors is generally on the top of block behind the head near where the gen bolts up to the engine. It should look like most engine sensors a bit like a spark plug with 2 leads coming off of it. Pretty much anything that's not a glow pug or a fuel injector grab the number off and google it. Have you called a yanmar dealer and tried to buy a replacement tach sending unit? They should be able to walk you through finding the model where a tach would be and if it's not there what part ya need.

For RPM you could also use an inductive signal from the ignition wire(magneto) (coil of wire wound around ignition wire clamped with a zener), coil wire primary circuit, alternator frequency.

using RPM would be a better way to tell when the engine has started ( rpm will come up plateau and then increase), or by watching for the starter current to drop off ( might plateau at 150 amps then drop rapidly as start the engine runs under its own power)...

Also just a side note all of those delays might cause you grief as your program gets more involved, look at the example "blink without delay"

Montanamac!

So interesting: I also live off the grid, also have a diesel generator, and am also working on using an arduino to control it! My main source of power is the PV array, though. So I will be following this thread closely.

First of all, I am measuring the current consumed by the starter to know when the engine has started. When cranking, it absorbs over 100A. When started, consumption drops down to <50A. So a pretty visible change.

In my situation, I also had to install a solenoid to open the fuel valve, which was manual. I found a great universal car door lock 40N on eBay which came with brackets and rods. I could have used it also to shut off the valve, but the generator happens to already have a solenoid to shut it off.

I have no need to measure rpm, as the engine's governor takes care of that. I plan to control warm up and cool down by simply delaying and anticipating load connection. In other words I will have the arduino connect the battery charger only after 3 mins of running time. And when it receive shutoff signal, it will first disconnect the load via hi power relays, then let the engine run load free for 3mins, then kill the fuel line with the solenoid.

I do plan, though, to completely replace the dashboard with 8 LED displays, to monitor in real time volts and amps of each of the 3 phases and 12V. All over i2C and with a remote dashboard for the house.

And for power, I plan to power the arduino independently via a battery backpack: I cannot rely on the 12V starter battery as its voltage can oscillate a lot and drop very low when cranking the engine especially in the winter (when I need it the most). So it would make no sense for the arduino to reboot during cranking. I thinking of using the battery to charge the arduino. When the generator is off, it means I have enough power, so I can use the power from the house to keep the starter battery fully charged with a trickle charger.

I also don't need to develop a battery charger: i'm using a fantastic Swiss micro controlled sine wave inverter (studer-innotec C2600) which takes care of tripping a multipurpose relay when the battery bank is, say, at 10% and reverse it when at 90%. Which is perfect in my case, because it makes little sense for me to fully charge the bank today, if maybe tomorrow it's clear again, and the sun hits te PV array.

Exciting we are working on this together!

Keep in touch.

I too have just started with arduino for the very same reason!
my set is a five horse propane electric start and manual choke.
I was able to set up a electric car door lock actuator (11 bucks)
And counter spring to work the choke from the start solenoid.
So, the idea is to watch 24v bank on say pin A0 through a voltage
Devider(0-5v) if below set point close relay to fuel solenoid allowing
Fuel to regulator. Then close starter relay for an adjustable time on
2nd relay. I forgot to mention that I did get a four relay board to go
With the arduino.
The feed back bit has not been thought about much till now and I guess
I will have to cross that bridge before going any further...
I did do the sketch for reading a pot on A0 and turning pin13 on and viewing
Serial port. I hooked the relay trigger to pin3 changed the sketch accordingly
and ran it. Once I reached preset(400) the relay would chatter like crazy. By
Reducing the sample rate, that problem was fixed. Any way I have 30 years
Electeromechanical back ground and 0 years programming. I have been reading
And doing, but, it is slow. So if I can contribute in any way to get some code
Even if it is just enough to experiment with so I can gain understanding along the way.

And mine makes 4!

Designed a dedicated PCB (based on Arduino, but I wanted to eliminate shield connectors for reliability reasons) for both engine control as well as better alternator regulation. It manages both the voltage and amps in order to meet the battery charging needs and also present a consistent load to the Kubota diesel engine and also manages the starting, stopping, and throttle speed of the engine. This generator (and watermaker) are currently installed in our boat and we have been using it for three years now. I am looking for this project to reduce the total amount of generator time needed, and also provide remote control of the system.

More can be seen here: http://smartdcgenerator.blogspot.com/

I am just about ready to order the PCBs, then will be looking to start on the firmware. Perhaps we can all share some in our experiences?

-al-