Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 3

/* ===============================================================

Project: Generator Auto Start.


Original code found online, no author listed, and sketch wasn't completely
functional.
Modified by Robert Cummings, with help from Rolando Valdez.
================================================================== */

/*
Connect 5V on Arduino to VCC on Relay Module
Connect GND on Arduino to GND on Relay Module
Delay time is in milliseconds. 1000 delay = 1 second, 2000 delay = 2 seconds,
60000 = 1 minute, etc.
- The Grid Up Relay creates a low input on Pin 11 when the grid is up, closing
the relay. Pullup keeps pin high normally.
- The Generator Running relay creates a low input on Pin 12 when the generator is
running, closing the relay. Pullup keeps pin high normally.
- When the grid goes down, this circuit will turn on an LP gas solenoid, then the
generator run switch, and automatically start the generator.
- If the generator doesn't start, it will try a total of 3 times before quitting,
and illuminating an LED indicating a fault.
- If the generator does start, it will operate the loads until the grid is
restored, then automatically power down.
*/

// Connect LCD Backpack VCC To Arduino 5V


// Connect LCD Backpack GND To Arduino Ground
// Connect LCD Backpack SDA To Arduino A4
// Connect LCD Backpack SCL To Arduino A5

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x27 for a 20 chars


and 4 line display

int tempsensor = 6; // Engine Temperature Sensor


int choke = 7; // Choke Solenoid
int gas = 8; // LP Gas Solenoid
int on = 9; // Generator Run Switch
int start_switch = 10; // Generator Start Switch
int grid = 11; // Grid Up Relay
int gen = 12; // Generator Running Relay
int alarm = 13; // Alarm LED

int a = 0; // error code


int i = 1; // Start attempt #s

void setup()
{
lcd.init(); // initialize the lcd
lcd.backlight();
lcd.clear();
pinMode(tempsensor, INPUT);
pinMode(choke, OUTPUT);
pinMode(alarm, OUTPUT);
pinMode(start_switch, OUTPUT);
pinMode(gas, OUTPUT);
pinMode(on, OUTPUT);
pinMode(grid, INPUT);
digitalWrite(grid, HIGH);
pinMode(gen, INPUT);
digitalWrite(gen, HIGH);
}

void loop()
{

int start_switch_delay = 3000;


if (digitalRead(grid) == LOW) // Grid Is Up
{ // switch is pressed - pullup keeps pin
high normally
digitalWrite(alarm, LOW) ; // Alarm Off
digitalWrite(choke, LOW);
digitalWrite(start_switch, LOW) ; // Generator Start Switch Off
digitalWrite(gas, LOW) ; // LP Gas Solenoid Off
digitalWrite(on, LOW) ; // Generator Run Switch Off
lcd.setCursor(0,0);
lcd.print("GRID IS UP");
i = 1;
a = 0;
}
else
{
if (digitalRead(gen) == HIGH) // Generator Not Running
{
for (i; i <= 3; i++) // Attempt to start, 3 times max
{
if (a == 0) //Attempt to start engine
{
digitalWrite(gas, HIGH); // LP Gas Solenoid On
lcd.clear();
lcd.setCursor(0,0);
lcd.print("LP GAS ON");
delay(1000);
digitalWrite(choke, HIGH); // Choke Solenoid On
lcd.setCursor(0,1);
lcd.print("CHOKE ON ");
delay(1000);
digitalWrite(on, HIGH) ; // Generator Run Switch On
lcd.setCursor(0,2);
lcd.print("GENERATOR ON");
delay(start_switch_delay);
digitalWrite(start_switch, HIGH); // Generator Start Switch On
lcd.setCursor(0,3);
lcd.print("GENERATOR STARTING ");
delay(start_switch_delay);
digitalWrite(start_switch, LOW); // Generator Start Switch Off
lcd.setCursor(0,3);
lcd.print("GENERATOR START OFF");
digitalWrite(choke, LOW); // Choke Solenoid Off
lcd.setCursor(0,1);
lcd.print("CHOKE OFF");
}

if (digitalRead(gen) == LOW) // Generator Running


{
start_switch_delay = 0;
i = 3;
a = 0; // no error
}

if (digitalRead(grid) == LOW) // Grid Is Up


{
start_switch_delay = 0;
i = 3;
}

if (i == 3) //I have tried three times check generator running or not


{
if (digitalRead(gen) == HIGH) { // Generator Not Running

digitalWrite(start_switch, LOW) ; // Generator Start Switch Off


lcd.setCursor(0,2);
lcd.print("GENERATOR OFF");
delay(start_switch_delay);
digitalWrite(gas, LOW) ; // LP Gas Solenoid Off
lcd.setCursor(0,0);
lcd.print("LP GAS OFF");
digitalWrite(on, LOW) ; // Generator Run Switch Off
lcd.setCursor(0,2);
lcd.print("GENERATOR OFF");
digitalWrite(choke, LOW); // Choke Solenoid Off.
lcd.setCursor(0,1);
lcd.print("CHOKE ON ");
digitalWrite(alarm, HIGH) ; // Alarm On
lcd.clear();
lcd.setCursor(0,0);
lcd.print("GENERATOR FAULT ");
a == 1;
}//Alarm State
else{
digitalWrite(on, HIGH) ; // Generator Run Switch On
lcd.setCursor(0,2);
lcd.print("GENERATOR ON");
digitalWrite(gas, HIGH) ; // LP Gas Solenoid On
lcd.setCursor(0,0);
lcd.print("LP GAS ON");
digitalWrite(choke, LOW); // Choke Solenoid Off
lcd.setCursor(0,1);
lcd.print("CHOKE OFF");
}//False Alarm
}
}
}
else
{
digitalWrite(start_switch, LOW); // Generator Start Switch Off
lcd.setCursor(0,3);
lcd.print("GENERATOR START OFF");

}
}

You might also like