Greetings all!
I'm pretty new at this and I hope I'm in the right category, apologies if I'm not. Anyhoo I'm building an automatic transfer switch to switch house power to a generator. I have a generator panel which is separate from the main breaker panel, and in the generator panel my MAX draw would be 50 amps. I have 200 amp service in the house but the circuits in the generator panel only draws 50 amps.
Equipment / Parts:
-
Arduino NANO
-
20x4 LCD Display
-
100 amp solid state relay / 3 phase https://www.amazon.com/gp/product/B01JI40VUM/ref=ppx_yo_dt_b_search_asin_title?ie=UTF8&psc=1
-
Automatic transfer switch https://www.amazon.com/gp/product/B093S6QR7L/ref=ppx_yo_dt_b_search_asin_image?ie=UTF8&psc=1
-
100A, 480V AC, 60V DC, 2 Pole, DIN Rail Mount Miniature Circuit Breaker
[https://www.amazon.com/gp/product/B089TNQL1F/ref=ppx_yo_dt_b_search_asin_image?ie=UTF8&psc=1] -
LCLCTC DC 5V Din Rail Slim Switching Power Supply 15W 2.4A(Input:100-240VAC,Output:5VDC,50/60HZ) Power Supply Adapter Switch Switching [https://www.amazon.com/dp/B0BY476TB8?psc=1&ref=ppx_yo2ov_dt_b_product_details]
General Description:
I'm using the Nano for a few things, first and foremost to detect Mains power loss, add a delay of a specified amount to give the generator a few minutes to start before switching to generator power. Of course the generator has to be running before the power gets switched at all. So I have the power supply AC to DC converters sensing on a specified pin.
I also have a temperature sensor which will be located inside the box which will switch on intake and exhaust fans (PC Case Fans) when the inside of the box reaches 80 degrees or above. Currently I'm only turning on and off 2 LED's based on temperature.
Lastly, I have a separate red LED that illuminates when mains and generator power are running. Simulating the mains power coming back on while the generator is running.
Problems:
Most of the code seems to work well with some issues that seem small but would be catastrophic in the event of a power outage.
First, I'm not sure how to use the "if" statements because when I simulate a power outage, and switch to generator power everything seems to work just fine. But when I add Mains power back into the mix along with the generator power, I want the SSR to remain on for a specified about of time then shut off. What ACTUALLY happens is the SSR stays on for the specific amount of time but then it turns off then back on again in that loop. It seems to have something to do with my use of the "delay" lines but I'm not sure where to put them. After all sometimes the mains power will return then go back out again so I want the system to stay on generator power for a specified amount of time.
I'm going to add my complete code so if anyone can help I would sure appreciate it. Thanks to you all in advance.
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <DHT.h>
#define Type DHT11
//Define LCD pinout
const int en = 2, rw = 1, rs = 0, d4 = 4, d5 = 5, d6 = 6, d7 = 7, bl = 3;
//Define I2C Address
const int i2c_addr = 0x27;
LiquidCrystal_I2C lcd(i2c_addr, en, rw, rs, d4, d5, d6, d7, bl, POSITIVE);
int mainsLED = 2;
int genLED = 3;
int mainsDetect = 4;
int mainsPin = 5;
int genDetect = 6;
int genPin = 7;
int sensePin = 8;
int naLED = 9;
int intakeFan = 10;
int genMnLEDred = 11;
int exhaustFan = 12;
int dt = 1000;
int genDelay = 30000;
int mainsDelay = 1000;
int mainsStatus;
int genStatus;
float humidity;
float tempC;
float tempF;
DHT HT(sensePin, Type);
void setup() {
Serial.begin(115200);
lcd.begin(20, 4);
HT.begin();
pinMode(mainsLED, OUTPUT);
pinMode(genLED, OUTPUT);
pinMode(mainsDetect, INPUT);
pinMode(mainsPin, OUTPUT);
pinMode(genDetect, INPUT);
pinMode(genPin, OUTPUT);
pinMode(naLED, OUTPUT);
pinMode(genMnLEDred, OUTPUT);
pinMode(intakeFan, OUTPUT);
pinMode(exhaustFan, OUTPUT);
}
void loop() {
delay(2000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Temperature: ");
lcd.print(tempF);
lcd.print(" F");
lcd.setCursor(0, 1);
lcd.print("Humidity: ");
lcd.print(humidity);
lcd.print(" % ");
lcd.setCursor(0, 2);
lcd.print("Mains Status: ");
if (digitalRead(mainsDetect) == HIGH) {
lcd.print("On");
digitalWrite(mainsLED, HIGH);
digitalWrite(mainsPin, HIGH);
} else {
lcd.print("Off");
digitalWrite(mainsLED, LOW);
digitalWrite(mainsPin, LOW);
}
lcd.setCursor(0, 3);
lcd.print("Gentr Status: ");
if (digitalRead(genDetect) == HIGH) {
lcd.print("On");
digitalWrite(genLED, HIGH);
digitalWrite(genPin, HIGH);
} else {
lcd.print("Off");
digitalWrite(genLED, LOW);
digitalWrite(genPin, LOW);
}
if ((digitalRead(mainsDetect) == HIGH) && (digitalRead(genDetect) == HIGH)) {
delay(10000);
digitalWrite(genPin, LOW);
}
if ((digitalRead(mainsDetect) == LOW) && (digitalRead(genDetect) == LOW)) {
digitalWrite(naLED, HIGH);
delay(dt);
digitalWrite(naLED, LOW);
}
if ((tempF) >= 69.00) {
digitalWrite(genMnLEDred, HIGH);
digitalWrite(intakeFan, HIGH);
digitalWrite(exhaustFan, HIGH);
} else {
digitalWrite(genMnLEDred, LOW);
digitalWrite(intakeFan, LOW);
digitalWrite(exhaustFan, LOW);
}
humidity = HT.readHumidity();
tempC = HT.readTemperature();
tempF = HT.readTemperature(true);
Serial.print(genStatus);
Serial.println(" Gen Status ");
Serial.print(mainsStatus);
Serial.println(" Mains Status ");
mainsStatus = digitalRead(mainsDetect);
genStatus = digitalRead(genDetect);
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.println(" % ");
Serial.print(" Temperature ");
Serial.print(tempF);
Serial.println(" F ");
}