Arduino as Generator Auto Start System

hello, i made a simple generator auto start system for my gasoline generator and it worked fine for a while. Now from last two days as soon as the mains not available the generator starts and then shuts off. To me arduino is somehow reseting automatically and it turns off the Switch Relay of the generator shutting down the generator and then attempt to restart it and the process keeps on going.
Here is my code it is very simple and works fine on the table but starts to act funny when generator has started.

#define IGN 13 //Ignition Pin
#define SW 12 //Switch Pin
#define AC 11//mains sense pin
#define Gen_IP 10 // generator start sense pin
int IGN_Time=0;
unsigned long Report_Time=0;
unsigned long Stop_Time=0;
int IGN_Attempt=0;
void setup() {
pinMode(IGN,OUTPUT);
pinMode(SW,OUTPUT);
pinMode(AC,INPUT);
pinMode(Gen_IP,INPUT);
digitalWrite(SW,LOW);
digitalWrite(IGN,LOW);
}

void loop() {
if(digitalRead(AC)==HIGH)
  {
  
   if(IGN_Attempt<4&&digitalRead(Gen_IP)==HIGH)//Gen_IP will be high when generator has not started yet
     {
        
     for(IGN_Time=0;IGN_Time<=4000;IGN_Time++)//give ign for 4 sec
      {
        digitalWrite(SW,HIGH);
        digitalWrite(IGN,HIGH);
        if(digitalRead(Gen_IP)==LOW||digitalRead(AC)==LOW)//if gen has started or mains is available then break the ign loop
          break; 
        delay(1);  
      }
     if(IGN_Time>=4000&&digitalRead(Gen_IP)==HIGH&&digitalRead(AC)==HIGH) //if ign loop was complete and genrator has not started yet then wait for 5 sec before next attempt
     {
       for(int i=0;i<=5000;i++)
      {
        digitalWrite(IGN,LOW);
        if(digitalRead(Gen_IP)==LOW||digitalRead(AC)==LOW)
        break; 
        delay(1);  
      }
     IGN_Attempt++;
     }     
     }
   else
     {
       if(digitalRead(Gen_IP)==LOW)//if generator has started reset the ignition counter
        {
          IGN_Attempt=0;
        }
        digitalWrite(IGN,LOW);
     }
  }   
else //if mains is available
{
  digitalWrite(IGN,LOW);
if(digitalRead(Gen_IP)==LOW)//if generator is running 
  for(Stop_Time=0;Stop_Time<=120000;Stop_Time++)//wait for 2 mins before truning of the gen
    {
     if(digitalRead(Gen_IP)==HIGH||digitalRead(AC)==HIGH)
      { break; }
  if(Stop_Time>=120000)
  digitalWrite(SW,LOW);
  delay(1);
}

  IGN_Attempt=0;
 
}
}

You say it worked fine for a while - how long was that? Several weeks?

If the code you have posted is identical to the code that worked fine I doubt if the problem is there. More likely some component has been stressed or something has come loose.

Another possibility is electrical interference between the generator output or the high voltage ignition system and the Arduino. Though why that should be a problem now if it was not a problem previously? Maybe some wires have shifted their position due to vibration or heat.

You don't seem to have any diagnostic Serial.print() statements in your program so you can see what the Arduino thinks is happening

...R

Hi,
How are you powering the Arduino, what model?

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

If you are using the battery that starts the generator, make sure all the connections are clean.

The Arduino power supply should have its own supply wires to the battery, if that is what you are using.

Tom… :slight_smile:

The signal that tells the generator to turn off is the 'AC' input. Is that pickng up noise somewhere?

Allan

Here is the schematic. https://drive.google.com/open?id=0B9zn2-c1CPOHMjMxTWExUWprV2c

You say it worked fine for a while - how long was that? Several weeks?

Yes the code worked for a month or so.

You don't seem to have any diagnostic Serial.print() statements in your program so you can see what the Arduino thinks is happening

I put the diagnostic code for checking the functionality on table but not in the actual system. I will put back the serial.print() code to see what is happing.

How are you powering the Arduino, what model?

I am using the generator's battery to power the arduino through LM7805 as indicated in the schematic.

The signal that tells the generator to turn off is the 'AC' input. Is that pickng up noise somewhere?

Yes it is the AC but i am sampling this signal for 2 minutes before the generator is shutoff and in those 2 mins if the AC signals fails, the counter is reset. But the generator shuts off as soon as it has started whereas i have not given any such command in the code.

oops. No diagram.

How is the arduino mounted? it may not be subjected to direct rain, it is subject to high humidity and he wires?

Vibrations can cause havoc on soldered connections, and while it isn't subjected to direct rain, it is subject to high humidity and massive temp swings. Corrosion on terminals could become an issue with those conditions. The market is also chock full of components that "work", but don't last long. Reliability and performance are often sacrificed to make the part more economical.

tinman13kup: How is the arduino mounted? it may not be subjected to direct rain, it is subject to high humidity and he wires?

Vibrations can cause havoc on soldered connections, and while it isn't subjected to direct rain, it is subject to high humidity and massive temp swings. Corrosion on terminals could become an issue with those conditions. The market is also chock full of components that "work", but don't last long. Reliability and performance are often sacrificed to make the part more economical.

Weather is clear and dry and the circuit has no corrosion, mounting does not seem to be the problem, what i feel is that the arduino is reseting somehow when the generator kicks in but i checked the output of LM7805 during Ignition and it stays stable. as for vibrations the circuit is not mounted on the generator but is sitting on the ground while wires are connected to the generator thus no vibrations, i further used my mobile's magnetic sensor to measure the change in electromagnetic interference but the signal remains unchanged where the circuit is place it however vanished when i put it directly under the dynamo.

As was stated earlier, if nothing else has changed, component failure or connections are the most likely culprits. Wires do not have to be flailing around to be subject to vibration, and with any internal combustion engine, there are vibrations.

As for reading the output of the 7805, if you are using a multimeter, it may not be fast enough to read a uS drop in power. What type capacitors are you using on the 7805?

Try posting the diagram again.

tinman13kup: As was stated earlier, if nothing else has changed, component failure or connections are the most likely culprits. Wires do not have to be flailing around to be subject to vibration, and with any internal combustion engine, there are vibrations.

As for reading the output of the 7805, if you are using a multimeter, it may not be fast enough to read a uS drop in power. What type capacitors are you using on the 7805?

Try posting the diagram again.

I have a 100uF electrolytic capacitor, 2ndly arduino uno has on board electrolytic capacitor as well to cater for such power drops, i hope purpose of these capacitors is to reduce the ripples. I will further add higher value capacitor on the I/P of arduino to see if that changes any thing

Hi,

You also need 0.1uF capacitors around the LM7805, these caps have to be mounted as close to the LM7805 as possible.
One from input to gnd.
One from output to gnd.

Ops circuit.
GENAUTO_Arduino_schematic.png

The Arduino draws its power directly from the battery, does it do this with its own wires or are you tapping into wires already connected to the battery?
Have you cleaned the battery terminals?

How are you detecting AC and Generator, please put these on your circuit.

Can you post a picture of your project so we can see your component layout please?

Have you checked the gap on the spark plug and the ignition lead?

Tom… :slight_smile:

You also need 0.1uF capacitors around the LM7805, these caps have to be mounted as close to the LM7805 as possible. One from input to gnd. One from output to gnd.

i have one from the output to ground i will put one on the input side

The Arduino draws its power directly from the battery, does it do this with its own wires or are you tapping into wires already connected to the battery?

i/p power jack of Arduino is connected to the output of LM7805.

How are you detecting AC and Generator, please put these on your circuit.

for AC i am using a 5V Mobile charger whose ouput turn on a transistor which in trun pull down the sense pin of arduino

For Generator i am using generator's 14-15V output to do the same with the Generator start pin

Can you post a picture of your project so we can see your component layout please?

please refer to my previous post i have posted the schematic there

Once the generator starts aren't you killing the ignition here and shutting it off here

else
    {
      if (digitalRead(Gen_IP) == LOW) //if generator has started reset the ignition counter
      {
        IGN_Attempt = 0;
      }
      digitalWrite(IGN, LOW);

    }

What it the function of the "Switch Relay"? is that the starter relay? And what de-energizes it when the gen starts?

tonybullard: Once the generator starts aren't you killing the ignition here and shutting it off here

else
    {
      if (digitalRead(Gen_IP) == LOW) //if generator has started reset the ignition counter
      {
        IGN_Attempt = 0;
      }
      digitalWrite(IGN, LOW);

    }




What it the function of the "Switch Relay"? is that the starter relay? And what de-energizes it when the gen starts?

yes it is just turning of the ignition not the Generator switch, ignition is not required when the generator has started, but arduino is supposed to keep the switch relay on which it turns off. Switch relay is there to shutdown the generator when the AC is available and the generator is on.

Hi,

i/p power jack of Arduino is connected to the output of LM7805.

The input jack is for higher than 7V supplies, it goes to an internal 5V regulator. You need to connect your 5V from your regulator to the 5V pin of the Arduino.

https://learn.adafruit.com/ladyadas-learn-arduino-lesson-number-0/power-jack-and-supply

With your present connection, measure the 5V pin on the Arduino.

Tom... :)

TomGeorge: Hi,The input jack is for higher than 7V supplies, it goes to an internal 5V regulator. You need to connect your 5V from your regulator to the 5V pin of the Arduino.

https://learn.adafruit.com/ladyadas-learn-arduino-lesson-number-0/power-jack-and-supply

With your present connection, measure the 5V pin on the Arduino.

Tom... :)

Very good point. I just tried it and I only get 3.8V on the 5V rail.

Remove the 10 ohm resistor in series with the 7805 output!

What is/was the purpose of that resistor?

You should have opto-couplers on the GEN and AC inputs. It’s bad practice to ground one side of the AC to the Arduino.

It should be isolated by the phone charger the OP is using as a 5v signal source.

Allan

first of sorry for getting back late.

Hi,The input jack is for higher than 7V supplies, it goes to an internal 5V regulator. You need to connect your 5V from your regulator to the 5V pin of the Arduino.

https://learn.adafruit.com/ladyadas-learn-arduino-lesson-number-0/power-jack-and-supply

With your present connection, measure the 5V pin on the Arduino.

i identified this i was getting 4.4V so i connected the I/P jack to battery i.e.13V or so. problem with connecting LM7805 directly to 5V is that they tend to get short circuited when they go bad which will fry my Arduino. this is the reason for using a 10ohm resistor as to minimize the damage in such case.

You should have opto-couplers on the GEN and AC inputs. It's bad practice to ground one side of the AC to the Arduino

it is connected to the base of a transistor and not directly connected to Arduino pin further more these chargers are internally isolated from 220V via transformer so i don't see and issue there.

and finally i had found the issue i was using only 40-50ohms resistor on the bases of output transistor which seemed to be the issue as current flowing from Atmega328 was exceeding or approaching 200mA thus causing a reset i place 1k resistors and now the system is working fine without any issues thanks all for your assistance regards.