V18 by TXMEDIC

This sketch is missing a short description
//********************************************************************** //***************************** libraries ****************************** //********************************************************************** #include <DHT.h> #include <LiquidCrystal_I2C.h> #include <Wire.h> #include <OneWire.h> //********************************************************************** //************************** pin assignments *************************** //********************************************************************** // coop photocell sensors const int photocell_front = A0; const int photocell_side = A1; const int photocell_back = A2; // coop climate #define DHTPIN 22 #define DHTTYPE DHT11 DHT climate(DHTPIN, DHTTYPE); // coop fans const int coop_fan_1 = 22; const int coop_fan_2 = 22; // coop water const int coop_heater = 22; const int coop_heater_pump = 22; const int coop_water_heater = 22; const int coop_water_pump = 22; // chicken door const int chicken_door_motor_enable = 2; const int chicken_door_motor_close = 22; const int chicken_door_motor_open = 22; const int chicken_door_open_sensor = 22; const int chicken_door_closed_sensor = 22; // left coop windows const int left_window_motor_enable = 3; const int left_window_motor_close = 22; const int left_window_motor_open = 22; const int left_window_open_sensor = 22; const int left_window_closed_sensor = 22; // right coop window const int right_window_motor_enable = 4; const int right_window_motor_close = 22; const int right_window_motor_open = 22; const int right_window_open_sensor = 22; const int right_window_closed_sensor = 22; // coop doors const int main_door_sensor = 22; const int left_nesting_box_sensor = 22; const int right_nesting_box_sensor = 22; const int run_door_sensor = 22; // coop lights const int coop_interior_light = 22; // coop led const int green_led = 22; const int red_led = 22; // coop security const int electric_fence_relay = 22; //const int motion_sensor = 22; //const int security_strobe = 22; //********************************************************************** //***************************** variables ****************************** //********************************************************************** // coop photocell sensor int photocell_reading_front; int photocell_reading_side; int photocell_reading_back; int photocell_reading_avg; int photocell_reading_level; // coop climate sensor int coop_humidity; int coop_temperature = 75; int coop_heat_index; // coop fan int fan_running_val = true; // coop pumps int coop_pump_val = true; // coop door sensors int chicken_door_open_sensor_val; int chicken_door_closed_sensor_val; int chicken_door_sensor_val; int main_door_sensor_val; int left_nesting_box_sensor_val; int right_nesting_box_sensor_val; int run_door_sensor_val; // coop window sensors int left_window_open_sensor_val; int left_window_closed_sensor_val; int left_window_sensor_val; int right_window_open_sensor_val; int right_window_closed_sensor_val; int right_window_sensor_val; // coop light int chicken_door_open_time; int coop_light_control_val = 0; // led int led_state = LOW; // lcd int coop_fault_val; int fault_status_val; int lcd_val; LiquidCrystal_I2C lcd(0x27, 20, 4); //********************************************************************** //******************************* delays ******************************* //********************************************************************** // coop control unsigned long last_control_time = 0; unsigned long control_time_delay = 600000; // coop fan switch unsigned long last_fan_time = 0; unsigned long fan_time_delay = 3600000; // coop and heater pumps unsigned long last_coop_pump_time = 0; unsigned long coop_pump_time_delay = 60000; // chicken door unsigned long last_chicken_door_time = 0; unsigned long chicken_door_delay = 2000; // sensor fault unsigned long last_sensor_fault_time = 0; unsigned long sensor_fault_delay = 60000; // led flasher unsigned long last_led_flash_time = 0; unsigned long led_flash_delay = 250; // lcd display unsigned long last_lcd_display_time = 0; unsigned long lcd_display_delay = 5000; // lcd fault display unsigned long last_lcd_fault_time = 0; unsigned long lcd_fault_delay = 2500; // coop light unsigned long coop_light_delay = (60000 * 840); //********************************************************************** //***************************** coop setup ***************************** //********************************************************************** void setup(void) { Serial.begin(9600); lcd.init(); lcd.display(); lcd.backlight(); // coop photocell pinMode(photocell_front, INPUT); pinMode(photocell_side, INPUT); pinMode(photocell_back, INPUT); // coop climate climate.begin(); // coop fans pinMode(coop_fan_1, OUTPUT); digitalWrite(coop_fan_1, HIGH); pinMode(coop_fan_2, OUTPUT); digitalWrite(coop_fan_2, HIGH); // coop heaters pinMode(coop_heater, OUTPUT); digitalWrite(coop_heater, HIGH); pinMode(coop_heater_pump, OUTPUT); digitalWrite(coop_heater_pump, HIGH); pinMode(coop_water_heater, OUTPUT); digitalWrite(coop_water_heater, HIGH); pinMode(coop_water_pump, OUTPUT); digitalWrite(coop_water_pump, HIGH); // coop door pinMode(chicken_door_open_sensor, INPUT); digitalWrite(chicken_door_open_sensor, HIGH); pinMode(chicken_door_closed_sensor, INPUT); digitalWrite(chicken_door_closed_sensor, HIGH); pinMode(chicken_door_motor_enable, OUTPUT); pinMode(chicken_door_motor_close, OUTPUT); pinMode(chicken_door_motor_open, OUTPUT); // coop windows pinMode(left_window_open_sensor, INPUT); digitalWrite(left_window_open_sensor, HIGH); pinMode(left_window_closed_sensor, INPUT); digitalWrite(left_window_closed_sensor, HIGH); pinMode(right_window_open_sensor, INPUT); digitalWrite(right_window_open_sensor, HIGH); pinMode(right_window_closed_sensor, INPUT); digitalWrite(right_window_closed_sensor, HIGH); pinMode(left_window_motor_enable, OUTPUT); pinMode(left_window_motor_close, OUTPUT); pinMode(left_window_motor_open, OUTPUT); pinMode(right_window_motor_enable, OUTPUT); pinMode(right_window_motor_close, OUTPUT); pinMode(right_window_motor_open, OUTPUT); // coop doors pinMode(main_door_sensor, INPUT); digitalWrite(main_door_sensor, HIGH); pinMode(left_nesting_box_sensor, INPUT); digitalWrite(left_nesting_box_sensor, HIGH); pinMode(right_nesting_box_sensor, INPUT); digitalWrite(right_nesting_box_sensor, HIGH); pinMode(run_door_sensor, INPUT); digitalWrite(run_door_sensor, HIGH); // coop light pinMode(coop_interior_light, OUTPUT); digitalWrite(coop_interior_light, HIGH); // coop led pinMode(green_led, OUTPUT); digitalWrite(green_led, LOW); pinMode(red_led, OUTPUT); digitalWrite(red_led, LOW); // coop security pinMode(electric_fence_relay, OUTPUT); digitalWrite(electric_fence_relay, HIGH); } //********************************************************************** //**************************** coop control **************************** //********************************************************************** void coop_control() { if ((unsigned long)(millis() - last_control_time) >= control_time_delay) { last_control_time = millis(); photocell_reading_front = analogRead(photocell_front); photocell_reading_side = analogRead(photocell_side); photocell_reading_back = analogRead(photocell_back); photocell_reading_avg = ((photocell_reading_front) + (photocell_reading_side) + (photocell_reading_back) / 3); if ((photocell_reading_avg >= 0 && photocell_reading_avg <= 3)) { photocell_reading_level = '1'; } else if (photocell_reading_avg >= 4 && photocell_reading_avg <= 120) { photocell_reading_level = '2'; } else if (photocell_reading_avg >= 125) { photocell_reading_level = '3'; } float humidity = climate.readHumidity(); coop_humidity = humidity; float temperature = climate.readTemperature(true); coop_temperature = temperature; float heat_index = climate.computeHeatIndex(humidity , temperature); coop_heat_index = heat_index; } } //********************************************************************** //************************ coop climate control ************************ //********************************************************************** void coop_climate_control() { if (coop_temperature < 40) { digitalWrite(coop_heater, LOW); digitalWrite(coop_heater_pump, LOW); digitalWrite(coop_water_heater, LOW); digitalWrite(coop_water_pump, LOW); digitalWrite(coop_fan_1, HIGH); digitalWrite(coop_fan_2, HIGH); fan_running_val = false; coop_window_close_control(); } if ((coop_temperature < 50) && (coop_temperature < 70)) { digitalWrite(coop_fan_1, HIGH); digitalWrite(coop_fan_2, HIGH); digitalWrite(coop_heater, HIGH); digitalWrite(coop_heater_pump, HIGH); digitalWrite(coop_water_heater, HIGH); fan_running_val = false; coop_water_pump_control(); coop_window_open_control(); } if (coop_temperature > 80) { digitalWrite(coop_heater, HIGH); digitalWrite(coop_heater_pump, HIGH); digitalWrite(coop_water_heater, HIGH); fan_running_val = false; coop_fan_control(); coop_water_pump_control(); coop_window_open_control(); } } void coop_window_close_control() { left_window_closed_sensor_val = digitalRead(left_window_closed_sensor); left_window_open_sensor_val = digitalRead(left_window_open_sensor); right_window_closed_sensor_val = digitalRead(right_window_closed_sensor); right_window_open_sensor_val = digitalRead(right_window_open_sensor); digitalWrite(left_window_motor_close, LOW); digitalWrite(left_window_motor_open, HIGH); analogWrite(left_window_motor_enable, 255); if (left_window_closed_sensor_val == 0) { digitalWrite(left_window_motor_close, HIGH); digitalWrite(left_window_motor_open, HIGH); analogWrite(left_window_motor_enable, 0); } digitalWrite(right_window_motor_close, LOW); digitalWrite(right_window_motor_open, HIGH); analogWrite(right_window_motor_enable, 255); if (right_window_closed_sensor_val == 0) { digitalWrite(right_window_motor_close, HIGH); digitalWrite(right_window_motor_open, HIGH); analogWrite(right_window_motor_enable, 0); } } void coop_window_open_control() { left_window_closed_sensor_val = digitalRead(left_window_closed_sensor); left_window_open_sensor_val = digitalRead(left_window_open_sensor); right_window_closed_sensor_val = digitalRead(right_window_closed_sensor); right_window_open_sensor_val = digitalRead(right_window_open_sensor); digitalWrite(left_window_motor_close, HIGH); digitalWrite(left_window_motor_open, LOW); analogWrite(left_window_motor_enable, 255); if (left_window_closed_sensor_val == 0) { digitalWrite(left_window_motor_close, HIGH); digitalWrite(left_window_motor_open, HIGH); analogWrite(left_window_motor_enable, 0); } digitalWrite(right_window_motor_close, HIGH); digitalWrite(right_window_motor_open, LOW); analogWrite(right_window_motor_enable, 255); if (right_window_closed_sensor_val == 0) { digitalWrite(right_window_motor_close, HIGH); digitalWrite(right_window_motor_open, HIGH); analogWrite(right_window_motor_enable, 0); } } void coop_fan_control() { if ((unsigned long)(millis() - last_fan_time) >= fan_time_delay) { last_fan_time = millis(); if (fan_running_val == true) { fan_running_val = false; digitalWrite(coop_fan_1, LOW); digitalWrite(coop_fan_2, HIGH); } else if (fan_running_val == false) { fan_running_val = true; digitalWrite(coop_fan_1, HIGH); digitalWrite(coop_fan_2, LOW); } } } void coop_water_pump_control() { if ((unsigned long)(millis() - last_coop_pump_time) >= coop_pump_time_delay) { last_coop_pump_time = millis(); if (coop_pump_val == true) { coop_pump_val = false; digitalWrite(coop_water_pump, LOW); digitalWrite(coop_heater_pump, LOW); } else if (coop_pump_val == false) { coop_pump_val = true; digitalWrite(coop_water_pump, LOW); digitalWrite(coop_heater_pump, LOW); } } } //********************************************************************** //**************************** chicken door **************************** //********************************************************************** void coop_chicken_door_control() { if (photocell_reading_level == '1') { chicken_door_open_time = millis(); chicken_door_open_control(); } if (photocell_reading_level == '3') { chicken_door_close_control(); } } void chicken_door_close_control() { chicken_door_closed_sensor_val = digitalRead(chicken_door_closed_sensor); chicken_door_open_sensor_val = digitalRead(chicken_door_open_sensor); digitalWrite(chicken_door_motor_close, LOW); digitalWrite(chicken_door_motor_open, HIGH); analogWrite(chicken_door_motor_enable, 255); if (chicken_door_closed_sensor_val == 0) { digitalWrite(chicken_door_motor_close, HIGH); digitalWrite(chicken_door_motor_open, HIGH); analogWrite(chicken_door_motor_enable, 0); } } void chicken_door_open_control() { chicken_door_closed_sensor_val = digitalRead(chicken_door_closed_sensor); chicken_door_open_sensor_val = digitalRead(chicken_door_open_sensor); digitalWrite(chicken_door_motor_close, HIGH); digitalWrite(chicken_door_motor_open, LOW); analogWrite(chicken_door_motor_enable, 255); if (chicken_door_closed_sensor_val == 0) { if ((unsigned long)(millis() - last_chicken_door_time) > chicken_door_delay) { last_chicken_door_time = millis(); digitalWrite(chicken_door_motor_close, HIGH); digitalWrite(chicken_door_motor_open, HIGH); analogWrite(chicken_door_motor_enable, 0); } } } //********************************************************************** //***************************** coop light ***************************** //********************************************************************** void coop_light_control() { if((photocell_reading_level == '2') && (chicken_door_open_sensor == 0)) { coop_light_control_val = 1: } if (coop_light_control_val == 1) { digitalWrite(coop_interior_light, LOW); } if((coop_light_control_val == 1) && (chicken_door_closed_sensor == 0) { if((unsigned long)(millis() - chicken_door_open_time) >= coop_light_delay) { chicken_door_open_time = 0; coop_light_control_val = 0; digitalWrite(coop_interior_light, HIGH); } } } //********************************************************************** //*************************** coop security **************************** //********************************************************************** void coop_electric_fence() { if (chicken_door_closed_sensor == 0) { digitalWrite(electric_fence_relay, LOW); } else if (chicken_door_closed_sensor != 0) { digitalWrite(electric_fence_relay, HIGH); } } //********************************************************************** //************************** coop door faults ************************** //********************************************************************** void coop_door_fault() { chicken_door_closed_sensor_val = digitalRead(chicken_door_closed_sensor); chicken_door_open_sensor_val = digitalRead(chicken_door_open_sensor); left_nesting_box_sensor_val = digitalRead(left_nesting_box_sensor); right_nesting_box_sensor_val = digitalRead(right_nesting_box_sensor); main_door_sensor_val = digitalRead(main_door_sensor); run_door_sensor_val = digitalRead(run_door_sensor); left_window_closed_sensor_val = digitalRead(left_window_closed_sensor); left_window_open_sensor_val = digitalRead(left_window_open_sensor); right_window_closed_sensor_val = digitalRead(right_window_closed_sensor); right_window_open_sensor_val = digitalRead(right_window_open_sensor); if ((chicken_door_closed_sensor_val == 0) || (chicken_door_open_sensor_val == 0)) { chicken_door_sensor_val = 0; } else if ((chicken_door_closed_sensor_val != 0) && (chicken_door_open_sensor_val != 0)) { chicken_door_sensor_val = 1; } if ((left_window_closed_sensor_val == 0) || (left_window_open_sensor_val == 0)) { left_window_sensor_val = 0; } else if ((left_window_closed_sensor_val != 0) && (left_window_open_sensor_val != 0)) { left_window_sensor_val = 1; } if ((right_window_closed_sensor_val == 0) || (right_window_open_sensor_val == 0)) { right_window_sensor_val = 0; } else if ((right_window_closed_sensor_val != 0) && (right_window_open_sensor_val != 0)) { right_window_sensor_val = 1; } if ((chicken_door_sensor_val == 0) && (left_nesting_box_sensor_val == 0) && (right_nesting_box_sensor_val == 0) && (main_door_sensor_val == 0) && (run_door_sensor_val == 0) && (left_window_sensor_val == 0) && (right_window_sensor_val == 0)) { last_sensor_fault_time = millis(); coop_fault_val = 0; coop_sensor_led(); coop_sensor_lcd(); } else if ((chicken_door_sensor_val != 0) || (left_nesting_box_sensor_val != 0) || (right_nesting_box_sensor_val != 0) || (main_door_sensor_val != 0) || (run_door_sensor_val != 0) || (left_window_sensor_val != 0) || (right_window_sensor_val != 0)) { if ((unsigned long)(millis() - last_sensor_fault_time) >= sensor_fault_delay) { coop_fault_val = 1; coop_sensor_fault_led(); coop_sensor_fault_lcd(); } } } void coop_sensor_led() { if ((chicken_door_closed_sensor_val == 0) && (main_door_sensor_val == 0) && (left_nesting_box_sensor_val == 0) && (right_nesting_box_sensor_val == 0) && (run_door_sensor_val == 0)) { digitalWrite(green_led, HIGH); digitalWrite(red_led, LOW); } else if ((chicken_door_closed_sensor_val != 0) && (main_door_sensor_val != 0) && (left_nesting_box_sensor_val != 0) && (right_nesting_box_sensor_val != 0) && (run_door_sensor_val != 0)) { digitalWrite(green_led, LOW); digitalWrite(red_led, HIGH); } } void coop_sensor_fault_led() { last_led_flash_time = millis(); if (led_state == LOW) led_state = HIGH; else led_state = LOW; digitalWrite(red_led, led_state); } void coop_sensor_lcd() { if (lcd_val == 0) { if ((unsigned long)(millis() - last_lcd_display_time) >= lcd_display_delay) { last_lcd_display_time = millis(); lcd.clear(); lcd.setCursor(6, 0); lcd.print("COOP BRAIN"); lcd.setCursor(0, 1); lcd.print("Version 2.1a"); lcd.setCursor(0, 2); lcd.print("Chicken Corp."); lcd.setCursor(0, 3); lcd.print("Copyright 2000-2020"); lcd_val = 1; } } else if (lcd_val == 1) { if ((unsigned long)(millis() - last_lcd_display_time) >= lcd_display_delay) { last_lcd_display_time = millis(); lcd.clear(); lcd.setCursor(0, 0); lcd.print("Light Sensor"); lcd.setCursor(0, 1); lcd.print("level: "); if (photocell_reading_level == '1') { lcd.print("Night"); } else if ((photocell_reading_level == '2') && (chicken_door_closed_sensor == 1)) { lcd.print("Dawn"); } else if ((photocell_reading_level == '2') && (chicken_door_open_sensor == 1)) { lcd.print("Dusk"); } else if (photocell_reading_level == '3') { lcd.print("Day"); } lcd_val = 2; } } else if (lcd_val == 2) { if ((unsigned long)(millis() - last_lcd_display_time) >= lcd_display_delay) { last_lcd_display_time = millis(); lcd.clear(); lcd.setCursor(0, 0); lcd.print("Coop temperature"); lcd.setCursor(0, 1); lcd.print("temperature: "); lcd.print(coop_temperature); lcd.print((char)223); lcd.print("F"); lcd.setCursor(0, 2); lcd.print("humidity: "); lcd.print(coop_humidity); lcd.print(" %"); lcd.setCursor(0, 3); lcd.print("Heat Index: "); lcd.print(coop_heat_index); lcd.print((char)223); lcd.print("F"); lcd_val = 3; } } else if (lcd_val == 3) { if ((unsigned long)(millis() - last_lcd_display_time) >= lcd_display_delay) { last_lcd_display_time = millis(); lcd.clear(); lcd.setCursor(0, 0); lcd.print("Coop Fans"); lcd.setCursor(0, 2); lcd.print("Fan group 1: "); if (coop_fan_1 == LOW) { lcd.print("ON"); } else if (coop_fan_1 == HIGH) { lcd.print("OFF"); } lcd.setCursor(0, 3); lcd.print("Fan group 2: "); if (coop_fan_2 == LOW) { lcd.print("ON"); } else if (coop_fan_2 == HIGH) { lcd.print("OFF"); } lcd_val = 4; } } else if (lcd_val == 4) { if ((unsigned long)(millis() - last_lcd_display_time) >= lcd_display_delay) { last_lcd_display_time = millis(); lcd.clear(); lcd.setCursor(0, 0); lcd.print("Coop Heaters"); lcd.setCursor(0, 2); lcd.print("Coop Heater: "); if (coop_heater == LOW) { lcd.print("ON"); } else if (coop_heater == HIGH) { lcd.print("OFF"); } lcd.setCursor(0, 3); lcd.print("Water Heater: "); if (coop_water_heater == HIGH) { lcd.print("ON"); } else if (coop_water_heater == LOW) { lcd.print("OFF"); } lcd_val = 5; } } else if (lcd_val == 5) { if ((unsigned long)(millis() - last_lcd_display_time) >= lcd_display_delay) { last_lcd_display_time = millis(); lcd.clear(); lcd.setCursor(0, 0); lcd.print("Coop Chicken Door"); lcd.setCursor(0, 2); if ((chicken_door_closed_sensor_val == 0) && (chicken_door_open_sensor_val != 0)) { lcd.print("SECURED"); } else if ((chicken_door_closed_sensor_val != 0) && (chicken_door_open_sensor_val == 0)) { lcd.print("UNSECURED"); } lcd_val = 6; } } else if (lcd_val == 6) { if ((unsigned long)(millis() - last_lcd_display_time) >= lcd_display_delay) { last_lcd_display_time = millis(); lcd.clear(); lcd.setCursor(0, 0); lcd.print("Coop Window Status"); lcd.setCursor(0, 2); lcd.print("Left Window: "); if ((left_window_closed_sensor_val == 0) && (left_window_open_sensor_val != 0)) { lcd.print("SECURED"); } else if ((left_window_closed_sensor_val != 0) && (left_window_open_sensor_val == 0)) { lcd.print("UNSECURED"); } lcd.setCursor(0, 3); lcd.print("Right Window: "); if ((right_window_closed_sensor_val == 0) && (right_window_open_sensor_val != 0)) { lcd.print("SECURED"); } else if ((right_window_closed_sensor_val != 0) && (right_window_open_sensor_val == 0)) { lcd.print("UNSECURED"); } lcd_val = 7; } } else if (lcd_val == 7) { if ((unsigned long)(millis() - last_lcd_display_time) >= lcd_display_delay) { last_lcd_display_time = millis(); lcd.clear(); lcd.setCursor(0, 0); lcd.print("Coop Door Status"); lcd.setCursor(0, 2); lcd.print("Main Door: "); if (main_door_sensor_val == 0) { lcd.print("SECURED"); } else if (main_door_sensor_val != 0) { lcd.print("UNSECURED"); } lcd.setCursor(0, 3); lcd.print("Run Door: "); if (run_door_sensor_val == 0) { lcd.print("SECURED"); } else if (run_door_sensor_val != 0) { lcd.print("UNSECURED"); } lcd_val = 8; } } else if (lcd_val == 8) { if ((unsigned long)(millis() - last_lcd_display_time) >= lcd_display_delay) { last_lcd_display_time = millis(); lcd.clear(); lcd.setCursor(0, 0); lcd.print("Nesting Box Status"); lcd.setCursor(0, 2); lcd.print("Left: "); if (left_nesting_box_sensor_val == 0) { lcd.print("SECURED"); } else if (left_nesting_box_sensor_val != 0) { lcd.print("UNSECURED"); } lcd.setCursor(0, 3); lcd.print("Right: "); if (right_nesting_box_sensor_val == 0) { lcd.print("SECURED"); } else if (right_nesting_box_sensor_val != 0) { lcd.print("UNSECURED"); } lcd_val = 9; } } else if (lcd_val == 9) { if ((unsigned long)(millis() - last_lcd_display_time) >= lcd_display_delay) { last_lcd_display_time = millis(); lcd.clear(); lcd.setCursor(0, 0); lcd.print("Coop Pumps"); lcd.setCursor(0, 2); lcd.print("Water Pump: "); if (coop_water_pump == LOW) { lcd.print("ON"); } else if (coop_water_pump == HIGH) { lcd.print("OFF"); } lcd.setCursor(0, 3); lcd.print("Heat pump: "); if (coop_heater_pump == LOW) { lcd.print("ON"); } else if (coop_heater_pump == HIGH) { lcd.print("OFF"); } lcd_val = 10; } } else if (lcd_val == 10) { if ((unsigned long)(millis() - last_lcd_display_time) >= lcd_display_delay) { last_lcd_display_time = millis(); lcd.clear(); lcd.setCursor(0, 0); lcd.print("Coop Security"); lcd.setCursor(0, 1); lcd.print("Fence: "); if (electric_fence_relay == LOW) { lcd.print("ARMED"); } else if (electric_fence_relay == HIGH) { lcd.print("OFF"); } lcd.setCursor(0, 2); lcd.print("Sensors: "); lcd.print("N/A"); lcd.setCursor(0, 2); lcd.print("Strobes: "); lcd.print("N/A"); lcd_val = 1; } } } void coop_sensor_fault_lcd() { if (fault_status_val == 0) { if ((coop_fault_val == 1) && (chicken_door_sensor_val == 1)) { if ((unsigned long)(millis() - last_lcd_fault_time) >= lcd_fault_delay) { last_lcd_fault_time = millis(); lcd.display(); lcd.backlight(); lcd.clear(); lcd.setCursor(5, 0); lcd.print("COOP FAULT"); lcd.setCursor(0, 1); lcd.print("********************"); lcd.setCursor(4, 2); lcd.print("CHICKEN DOOR"); lcd.setCursor(0, 3); lcd.print("********************"); fault_status_val = 1; } } else if ((coop_fault_val == 1) && (chicken_door_sensor_val == 0)) { fault_status_val = 1; } } if (fault_status_val == 1) { if ((coop_fault_val == 1) && (main_door_sensor_val == 1)) { if ((unsigned long)(millis() - last_lcd_fault_time) >= lcd_fault_delay) { last_lcd_fault_time = millis(); lcd.display(); lcd.backlight(); lcd.clear(); lcd.setCursor(5, 0); lcd.print("COOP FAULT"); lcd.setCursor(0, 1); lcd.print("********************"); lcd.setCursor(5, 2); lcd.print("MAIN DOOR"); lcd.setCursor(0, 3); lcd.print("********************"); fault_status_val = 2; } } else if ((coop_fault_val == 1) && (main_door_sensor_val == 0)) { fault_status_val = 2; } } if (fault_status_val == 2) { if ((coop_fault_val == 1) && (left_nesting_box_sensor_val == 1)) { if ((unsigned long)(millis() - last_lcd_fault_time) >= lcd_fault_delay) { last_lcd_fault_time = millis(); lcd.display(); lcd.backlight(); lcd.clear(); lcd.setCursor(5, 0); lcd.print("COOP FAULT"); lcd.setCursor(0, 1); lcd.print("********************"); lcd.setCursor(2, 2); lcd.print("LEFT NESTING BOX"); lcd.setCursor(0, 3); lcd.print("********************"); fault_status_val = 3; } } else if ((coop_fault_val == 1) && (left_nesting_box_sensor_val == 0)) { fault_status_val = 3; } } if (fault_status_val == 3) { if ((coop_fault_val == 1) && (right_nesting_box_sensor_val == 1)) { if ((unsigned long)(millis() - last_lcd_fault_time) >= lcd_fault_delay) { last_lcd_fault_time = millis(); lcd.display(); lcd.backlight(); lcd.clear(); lcd.setCursor(5, 0); lcd.print("COOP FAULT"); lcd.setCursor(0, 1); lcd.print("********************"); lcd.setCursor(1, 2); lcd.print("RIGHT NESTING BOX"); lcd.setCursor(0, 3); lcd.print("********************"); fault_status_val = 4; } } else if ((coop_fault_val == 1) && (right_nesting_box_sensor_val == 0)) { fault_status_val = 4; } } if (fault_status_val == 4) { if ((coop_fault_val == 1) && (run_door_sensor_val == 1)) { if ((unsigned long)(millis() - last_lcd_fault_time) >= lcd_fault_delay) { last_lcd_fault_time = millis(); lcd.display(); lcd.backlight(); lcd.clear(); lcd.setCursor(5, 0); lcd.print("COOP FAULT"); lcd.setCursor(0, 1); lcd.print("********************"); lcd.setCursor(6, 2); lcd.print("RUN DOOR"); lcd.setCursor(0, 3); lcd.print("********************"); fault_status_val = 5; } } else if ((coop_fault_val == 1) && (run_door_sensor_val == 0)) { fault_status_val = 5; } } if (fault_status_val == 5) { if ((coop_fault_val == 1) && (left_window_sensor_val == 1)) { if ((unsigned long)(millis() - last_lcd_fault_time) >= lcd_fault_delay) { last_lcd_fault_time = millis(); lcd.display(); lcd.backlight(); lcd.clear(); lcd.setCursor(5, 0); lcd.print("COOP FAULT"); lcd.setCursor(0, 1); lcd.print("********************"); lcd.setCursor(4, 2); lcd.print("LEFT WINDOW"); lcd.setCursor(0, 3); lcd.print("********************"); fault_status_val = 6; } } else if ((coop_fault_val == 1) && (left_window_sensor_val == 0)) { fault_status_val = 6; } } if (fault_status_val == 6) { if ((coop_fault_val == 1) && (right_window_sensor_val == 1)) { if ((unsigned long)(millis() - last_lcd_fault_time) >= lcd_fault_delay) { last_lcd_fault_time = millis(); lcd.display(); lcd.backlight(); lcd.clear(); lcd.setCursor(5, 0); lcd.print("COOP FAULT"); lcd.setCursor(0, 1); lcd.print("********************"); lcd.setCursor(4, 2); lcd.print("RIGHT WINDOW"); lcd.setCursor(0, 3); lcd.print("********************"); fault_status_val = 0; } } else if ((coop_fault_val == 1) && (right_window_sensor_val == 0)) { fault_status_val = 0; } } } void serial() { Serial.print("chicken door open \t"); Serial.print(chicken_door_open_sensor_val); Serial.print( "\n"); Serial.print("chicken door closed \t"); Serial.print(chicken_door_closed_sensor_val); Serial.print( "\n"); Serial.print("chicken door val \t"); Serial.print(chicken_door_sensor_val); Serial.print( "\n"); Serial.print("left nesting box \t"); Serial.print(left_nesting_box_sensor_val); Serial.print( "\n"); Serial.print("right nesting box \t"); Serial.print(right_nesting_box_sensor_val); Serial.print( "\n"); Serial.print("main door \t"); Serial.print(main_door_sensor_val); Serial.print( "\n"); Serial.print("run door \t"); Serial.print(run_door_sensor_val); Serial.print( "\n"); //delay(1000); } void loop() { coop_control(); coop_climate_control(); coop_chicken_door_control(); coop_light_control(); coop_electric_fence(); coop_door_fault(); serial(); }

Embed This Sketch

Use the following HTML code to embed the sketch code above in your blog or website.

<iframe style="height: 510px; width: 100%; margin: 10px 0 10px;" allowTransparency="true" src="https://codebender.cc/embed/sketch:157765" frameborder="0"></iframe>

Embed The Serial Monitor

You can also embed the Serial Monitor section! Just use this HTML code.

<iframe style="height: 510px; width: 100%; margin: 10px 0 10px;" allowTransparency="true" src="https://codebender.cc/embed/serialmonitor" frameborder="0"></iframe>