Smart Irrigation Aquacontroller
2138 3
Soumyabrata Debnath

Smart Irrigation Aquacontroller

I, being an Urban Planning professional and electronics hobbyist always found challenges whenever I...

Description:-

I, being an Urban Planning professional and electronics hobbyist always found challenges whenever I had to design a Water Management Plan for cities or town. A huge volume of water is used for outdoor-use demand which is used for watering the garden and lawn for Residential areas and also for parks and grounds of hospital, railway yard, Airport. As much as 50% of this water is wasted due to overwatering caused by inefficiencies in traditional irrigation methods and systems. Smart irrigation technology is the answer So, I started to design a device to automate Drip Irrigation and sprinkler system and thus this Aquacontroller came into being. And also tried to integrate and automate the lighting system of such places. Thus, saving water, electricity and manpower at the same time. Soil moisture sensor-based smart irrigation controllers use one of several well-established technologies to measure soil moisture content. When buried in the root zone of turf, trees or shrubs, the sensors accurately determine the moisture level in the soil and transmit this reading to the controller. There are two different soil moisture sensor-based systems available: Suspended cycle irrigation systems, which are set like traditional timer controllers, with watering schedules, start times and duration. The difference is that the system will stop the next scheduled irrigation when there is enough moisture in the soil. Water on demand irrigation requires no programming of irrigation duration (only start times and days of the week to water). It has a user-set lower and upper threshold, which initiates irrigation when the soil moisture level fails to meet those levels. Both this method is integrated in this device to cover most type of requirement by the beneficiaries.

Irrigation System

 

Project Used Hardware

 

Atmega 328 IC, DS3231 IC, 1602 Character LCD with I2C Breakout Board, AC-DC Converter Module, 10Amp Relay, 6Amp Socket, Soil Moisture Sensor, Rainfall Sensor, LDR Sensor, Flow Sensor, Buzzer, 4”X7” inch Enclosure, Main Cord.

Irrigation System

Project Used Software

Arduino IDE, EasyEDA, Adobe Photoshop, Autodesk Autocad.

Project Hardware Software Selection

#The Atmega 328 IC from Atmel was used for its simplicity and user-friendly developing environment like the Arduino IDE. #The DS3231 acts as Real Time Clock and provides timer function. It also has temperature compensated crystal built-in. #EasyEDA was used to develop the circuit diagram and for designing the PCB (Printed Circuit Board). #Autocad was used for measured drawing of the device which further helped in making the top label cover of the device, enhanced in Adobe Photoshop. #Soil moisture sensor is used to detect the presence of water in the soil. #Rain sensor is used to provide rain delay function to prevent overwatering after rain. #Flow sensor keep a check on the amount of water flowing out, this data is used to optimize the watering schedule and frequency.

Circuit Diagram

Circuit
 

PCB Board

The circuit has been made with Atmega328 at its centre. The Real Time Clock RTC DS3231 provide timer and schedule function to the circuit so that any pump for reservoir or lights can be automated. The soil moisture sensor can be connected to the USB ports to sense moisture presence in the soil and thus automatically switch on solenoid valve or water pump to irrigate. A temperature sensor is presence for monitoring the air temperature which along with the Rain sensor provides Rain Delay function. A flow sensor can be connected to the last USB port to measure amount of water flowing out. And a LDR (Light Dependent Resistor) sensor is present to automate garden or field lights.

Code

/*
Smart Irrigation Aqua Controllers V.2
**This code is part of a much bigger project of mine, that's why few bits of code may remain which plays no part in the current project.
Author - Soumyabrata Debnath 

*/
//Libraries Initialization
#include <Wire.h> 
#include <EEPROM.h>
#include <Arduino.h>
#include <OneWire.h>
#include <IRremote.h>
#include <LiquidCrystal_I2C.h>
#include <DallasTemperature.h>
#include <RealTimeClockDS1307.h>  

//Pin Assignment
#define Socket_A       0
#define Socket_B       1
#define Soil_1_sense 2
#define Buzzer           3 
#define Soil_2_sense 4 
#define DC1_Out       5  
#define DC2_Out       6
#define Rain              7 
#define Flow              8
#define LCD_BKL       9
#define Button_Sel   10
#define Button_Dn    11
#define Button_Up    12
#define Button_Prog 13
#define Temp_board 14
#define Temp_sense 15
#define ir_sense        16
#define LDR              17
//  SDA                       18
//  SCL                       19

// Variables Initialization
// General.................

byte count;
byte prog =  0;
byte str  =  1;
byte btReady  = 0;
byte prog_sel = 0; 
byte prog_sel_timer1 = 0;
unsigned long current_t;
unsigned long prog_btPushedMillis;
unsigned long RTC_previousMillis = 0;
byte Soil_1_sensorState   = 0;
byte Leak_sensorState  = 0;
// Push_Button...............
byte Button_Prog_State = 0;  
byte Button_Up_State   = 0; 
byte Button_Dn_State   = 0; 
byte Button_Sel_State  = 0;
byte prog_day = 0;
byte hr_val = 0;
byte min_val = 0;
// Socket_A..................
unsigned long s1_t1on ;
unsigned long s1_t1off;
unsigned long s1_t2on ;
unsigned long s1_t2off;
byte Socket_A_State    = HIGH;
// Socket_B..................
unsigned long s2_t1on ;
unsigned long s2_t1off;
unsigned long s2_t2on ;
unsigned long s2_t2off;
byte Socket_B_State    = HIGH;
// DC1....................
byte F_val    = 0;
byte DC1_Temp = 0;
// Light..................
byte L_Auto   = 1;
byte Light_P  = 0;
byte L_percent   ;
byte L_val    = 0;
byte R_val    = 0;
byte Ramp_Min = 0;
byte Ramp_flag = 0;
int  Ramp_counter = 0;
float Light_PWM ;
float Inc_Light_PWM = 0;
unsigned long Light_previousMillis;
unsigned long Light_currentMillis;
unsigned long L_t1on ;
unsigned long L_t1off;
unsigned long L_t2on ;
unsigned long L_t2off;
// Temp...................
float temp_C = 0;
// RTC.....................
byte  hours     = 0;
byte  minutes   = 0;
byte  seconds   = 0;
byte  days      = 0;
byte  dates     = 0;
byte  months    = 0;
 int  years     = 0; 
char* day_name[]={"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"};

// Timer1
byte day1A    = 0;
byte day2A    = 0;
byte day3A    = 0;
byte day4A    = 0;
byte day5A    = 0;
byte day6A    = 0;
byte day7A    = 0;

byte h_on_1A  = 0;
byte m_on_1A  = 0;
byte h_off_1A = 0;
byte m_off_1A = 0;

byte h_on_2A  = 0;
byte m_on_2A  = 0;
byte h_off_2A = 0;
byte m_off_2A = 0;

// Timer2
byte day1B    = 0;
byte day2B    = 0;
byte day3B    = 0;
byte day4B    = 0;
byte day5B    = 0;
byte day6B    = 0;
byte day7B    = 0;

byte h_on_1B  = 0;
byte m_on_1B  = 0;
byte h_off_1B = 0;
byte m_off_1B = 0;

byte h_on_2B  = 0;
byte m_on_2B  = 0;
byte h_off_2B = 0;
byte m_off_2B = 0;

// Light Timer
byte h_on_1L  = 0;
byte m_on_1L  = 0;
byte h_off_1L = 0;
byte m_off_1L = 0;

byte h_on_2L  = 0;
byte m_on_2L  = 0;
byte h_off_2L = 0;
byte m_off_2L = 0;

// Rain Timer
byte h_on_1F  = 0;
byte m_on_1F  = 0;  
byte h_on_2F  = 0; 
byte m_on_2F  = 0;

//Peripherals Initialization 
OneWire oneWire(Temp_sense);
DallasTemperature sensors(&oneWire);
LiquidCrystal_I2C lcd(0x27,16,2);

byte degree[8] = {B11100,
                           B10100,
                           B11100,
                           B00000,
                           B00000,
                           B00000,
                           B00000,
                           B00000}; 
byte thermo[8] = {B01100,
                           B01100,
                           B01100,
                           B01100,
                           B01100,
                           B11110,
                           B11110,
                           B01100};
byte arrow[8]  =  {B10000,
                           B11000,
                           B11100,
                           B11110,
                           B11100,
                           B11000,
                           B10000,
                           B00000};           
//-------------------------------------------------------------------
void Soil_1()  //
{ 
    Soil_1_sensorState = digitalRead(Soil_1_sense);   
    if (Soil_1_sensorState == LOW)
    {    
        digitalWrite(DC1_Out , HIGH);    
    }
    else
    {   
        lcd.setCursor(13, 1);
        lcd.print("Soil_1");       
        //delay(500);
        digitalWrite(DC1_Out , LOW);            
        //tone(Buzzer, 1000, 500); 
    }
} 

// Time and Date Function for LCD
void calender()
{
  RTC.readClock();
    hours     = RTC.getHours    ();
    minutes  = RTC.getMinutes  ();
    seconds = RTC.getSeconds  ();
    dates     = RTC.getDate     ();
    months  = RTC.getMonth    ();
    years     = RTC.getYear     (); 
    days      = RTC.getDayOfWeek();  
  lcd.clear();  
  printDigits(hours);
  lcd.print(":");
  printDigits(minutes);
  lcd.print(":");
  printDigits(seconds);
  lcd.print(" ");
  lcd.setCursor(0, 1);  
  printDigits(dates);
  lcd.print(":");  
  printDigits(months); 
  lcd.print(":"); 
  printDigits(years);
  lcd.print(" ");   
  lcd.setCursor(9, 1); 
  lcd.print(day_name[days-1]);  
  if (temp_C > 9 && temp_C < 100)
  {   
      lcd.setCursor(9, 0); 
      lcd.write(byte(1)); 
      lcd.print(temp_C,1);
      lcd.write(byte(0));
      lcd.print("C");      
  }  
}
void printDigits(int digits) // Sub function for calender
{
  if(digits < 10)
  lcd.print('0');
  lcd.print(digits);
}
void temp() // function for temperature monitor
{   
  sensors.requestTemperatures();  
  temp_C = sensors.getTempCByIndex(0); 
  /*float AverageTemperature = 0;
  int MeasurementsToAverage = 10;
  for(int i = 0; i < MeasurementsToAverage; ++i)
  {
      sensors.requestTemperatures();
      AverageTemperature += sensors.getTempCByIndex(0);
      delay(50);       
  }
  temp_C = AverageTemperature / MeasurementsToAverage;*/  
}
void day_select_A()
{
  lcd.clear();
  EEPROM.write(11, day1A);
  EEPROM.write(12, day2A);
  EEPROM.write(13, day3A);
  EEPROM.write(14, day4A);
  EEPROM.write(15, day5A);
  EEPROM.write(16, day6A);
  EEPROM.write(17, day7A);
}
void day_select_B()
{
  lcd.clear();
  EEPROM.write(41, day1B);
  EEPROM.write(42, day2B);
  EEPROM.write(43, day3B);
  EEPROM.write(44, day4B);
  EEPROM.write(45, day5B);
  EEPROM.write(46, day6B);
  EEPROM.write(47, day7B);
}  
void Press_Up_Dn()
{
  lcd.clear();  
  lcd.print(F("Press Up/Dn ->"));
  lcd.setCursor(0, 1);  
} 
void Press_Up_Sel()
{
  lcd.setCursor(0, 1);
  lcd.print(F("Press Up / Sel"));
  delay(1000);      
} 
void Selected_0()
{
 lcd.clear();  
 lcd.setCursor(3, 0);
 lcd.print(F("Selected"));
 delay(1000);           
 Press_Up_Dn(); 
}
void Selected_1()
{    
 lcd.setCursor(1, 1);
 lcd.print(F("Selected"));
 delay(1000);  
}
void days_save()
{    
 lcd.setCursor(0, 1);
 lcd.print(F("Press Dn to Save"));
 delay(1000); 
}

//-------------------------------------------------------------------------
//Setup Initialization
void setup()
{  
  lcd.init();             // initialize the lcd   
  lcd.home();
  lcd.backlight();
  lcd.createChar(0,  degree);
  lcd.createChar(1,  thermo);                                                         
  lcd.createChar(2,   arrow); 
  
  pinMode(DC1_Out,    OUTPUT);   
  pinMode(DC2_Out,    OUTPUT);
  pinMode(Rain,       OUTPUT);
  pinMode(Buzzer,     OUTPUT);
  pinMode(LDR,         INPUT);
  pinMode(Button_Prog, INPUT);
  pinMode(Button_Up,   INPUT);
  pinMode(Button_Dn,   INPUT);
  pinMode(Button_Sel,  INPUT);
  pinMode(Soil_1_sense,INPUT); 
  pinMode(Soil_2_sense,INPUT); 
  pinMode(Flow,  INPUT);   
  sensors.begin();
  sensors.setResolution(12); // (9)0.5C:94ms, (10)0.25C:188ms, (11)0.125C:375ms, (12)0.0625C:750ms 
  
  day1A    = EEPROM.read(11);
  day2A    = EEPROM.read(12);
  day3A    = EEPROM.read(13);
  day4A    = EEPROM.read(14);
  day5A    = EEPROM.read(15);
  day6A    = EEPROM.read(16);
  day7A    = EEPROM.read(17);  
 
  h_on_1A  = EEPROM.read(21);
  m_on_1A  = EEPROM.read(22);
  h_off_1A = EEPROM.read(23);
  m_off_1A = EEPROM.read(24);
  h_on_2A  = EEPROM.read(25);
  m_on_2A  = EEPROM.read(26);
  h_off_2A = EEPROM.read(27);
  m_off_2A = EEPROM.read(28);
  
  day1B    = EEPROM.read(41);
  day2B    = EEPROM.read(42);
  day3B    = EEPROM.read(43);
  day4B    = EEPROM.read(44);
  day5B    = EEPROM.read(45);
  day6B    = EEPROM.read(46);
  day7B    = EEPROM.read(47);  
 
  h_on_1B  = EEPROM.read(51);
  m_on_1B  = EEPROM.read(52);
  h_off_1B = EEPROM.read(53);
  m_off_1B = EEPROM.read(54);
  h_on_2B  = EEPROM.read(55);
  m_on_2B  = EEPROM.read(56);
  h_off_2B = EEPROM.read(57);
  m_off_2B = EEPROM.read(58);
  
  h_on_1L  = EEPROM.read(201);
  m_on_1L  = EEPROM.read(202);
  h_off_1L = EEPROM.read(203);
  m_off_1L = EEPROM.read(204);
  h_on_2L  = EEPROM.read(205);
  m_on_2L  = EEPROM.read(206);
  h_off_2L = EEPROM.read(207);
  m_off_2L = EEPROM.read(208);
  
  h_on_1F  = EEPROM.read(221);
  m_on_1L  = EEPROM.read(222);  
  h_on_2F  = EEPROM.read(223);
  m_on_2L  = EEPROM.read(224);
  
  Light_P  = EEPROM.read(250); //Light Intensity Percentage
  Ramp_Min = EEPROM.read(251); //Light ramping in minutes
  DC1_Temp = EEPROM.read(252); //DC1 Temperature                                                                
  
  tone(Buzzer, 1000, 300);
  
  lcd.print(F("Initializing"));
  delay(300); 
  lcd.clear(); 
  lcd.print(F("Initializing."));
  delay(300); 
  lcd.clear(); 
  lcd.print(F("Initializing.."));
  delay(300); 
  lcd.clear(); 
  lcd.print(F("Initializing..."));
  delay(300); 
  lcd.clear(); 
  lcd.print(F("Initializing...."));
  delay(300);
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print(F("Smart Irrigation"));
  lcd.setCursor(0, 1);
  lcd.print(F("Aqua Controller"));
  delay(1000); 
  lcd.clear();   
  temp();    
}
//---------------------------------------------------------------------
// Looping Sequence
void loop()
{ 
   unsigned long currentMillis = millis();
   if (btReady == 1)
   {
       if ((unsigned long)(currentMillis - prog_btPushedMillis) >= 4000)
       {
            str = 1;            
       }
   }
   unsigned long RTC_currentMillis = millis();
   if(RTC_currentMillis - RTC_previousMillis >= 1000)
   {
      RTC_previousMillis = RTC_currentMillis; 
      if (str == 1) 
      {          
          calender();  // Time and Date on LCD
          temp();     // Temparature          
          Soil_1();              
          prog = 0;
          prog_sel = 0;                         
      }   
   }   
   //--------------------------------------------------------
   current_t = (hours*10000) + (minutes*100) + seconds;   // Summation of current hour and minute 
   //--------------------------------------------------------
   // Summation of User stored Hour and Minute
   s1_t1on  = (h_on_1A  *10000) + (m_on_1A  *100);
   s1_t1off = (h_off_1A *10000) + (m_off_1A *100);
   s1_t2on  = (h_on_2A  *10000) + (m_on_2A  *100);
   s1_t2off = (h_off_2A *10000) + (m_off_2A *100);   
      
   s2_t1on  = (h_on_1B  *10000) + (m_on_1B  *100);
   s2_t1off = (h_off_1B *10000) + (m_off_1B *100);
   s2_t2on  = (h_on_2B  *10000) + (m_on_2B  *100);
   s2_t2off = (h_off_2B *10000) + (m_off_2B *100);
              
   if (days == day1A || days == day2A || days == day3A || days == day4A || days == day5A || days == day6A || days == day7A)
   {   // Socket_A on/off with respect to current time
       if (current_t == s1_t1on || current_t == s1_t2on)
       { 
           digitalWrite(Socket_A, HIGH);
           Socket_A_State = HIGH;       
       }
       if (current_t > s1_t1on && current_t < s1_t1off)
       { 
           digitalWrite(Socket_A, Socket_A_State);  
       }
     if (current_t > s1_t2on && current_t < s1_t2off)
       { 
           digitalWrite(Socket_A, Socket_A_State);  
       }
       if (current_t == s1_t1off || current_t == s1_t2off)
       { 
           digitalWrite(Socket_A, LOW); 
       }
   }
   if (days == day1B || days == day2B || days == day3B || days == day4B || days == day5B || days == day6B || days == day7B)
   {   // Socket_B on/off with respect to current time
       if (current_t == s2_t1on || current_t == s2_t2on)
       { 
           digitalWrite(Socket_B, HIGH);
           Socket_A_State = HIGH;       
       }
       if (current_t > s2_t1on && current_t < s2_t1off)
       { 
           digitalWrite(Socket_B, Socket_B_State);  
       }
     if (current_t > s2_t2on && current_t < s2_t2off)
       { 
           digitalWrite(Socket_B, Socket_B_State);  
       }
       if (current_t == s2_t1off || current_t == s2_t2off)
       { 
           digitalWrite(Socket_B, LOW); 
       }
   }  
  
// Main Loop ends   
//-----------------------------------------------------------------------   
   Button_Prog_State = digitalRead(Button_Prog);      
   if (Button_Prog_State == HIGH)      
   {
       prog_btPushedMillis = currentMillis;  
       btReady = 1;     
       if (prog_sel_timer1 == 0)
       {
           str = 0;
           prog = prog + 1;
           lcd.home();
           switch (prog)
           {
           case 1:
                lcd.clear();        
                lcd.write(byte(2));     
                lcd.print(F("Clock Settings"));
        lcd.setCursor(1, 1);  
                lcd.print(F("Timer 1"));
                delay(500);         
                break;
           case 2:
                lcd.clear();        
                lcd.write(byte(2));       
                lcd.print(F("Timer 1"));
        lcd.setCursor(1, 1); 
                lcd.print(F("Timer 2"));
                delay(500);         
                break;
           case 3:
                lcd.clear();        
                lcd.write(byte(2));         
                lcd.print(F("Timer 2"));
        lcd.setCursor(1, 1);   
                lcd.print(F("DC1"));  
                delay(500);         
                break;
           case 4:
                lcd.clear();        
                lcd.write(byte(2)); 
                lcd.print(F("DC1")); 
        lcd.setCursor(1, 1); 
        lcd.print(F("Light Timer")); 
                delay(500);         
                break;
           default: 
                prog = 0;  
           } 
       } 
       if (prog_sel_timer1 == 1)  
       {
           str = 1;  
           prog = 0;  
           prog_sel = 0;   
           prog_sel_timer1 = 0;              
       }
   }
//----------------------------------------------------------------------- 
//----------------------------------------------------------------------- 
   Button_Up_State = digitalRead(Button_Up);   
   if (Button_Up_State == HIGH) 
   {
       btReady = 0;
       if (prog == 0)      // Socket_A Manual On/Off
       {
           if (Socket_A_State == LOW)
               Socket_A_State = HIGH;            
           else
               Socket_A_State = LOW;
               digitalWrite(Socket_A, Socket_A_State);
               delay(500); 
       }
       if (prog == 1)      // RTC
       {
       if (prog_sel == 1)   // Hour  (+) Set time
       {
               lcd.setCursor(10, 1);
               lcd.print(F("   "));  
               hours = hours + 1;                              
               if (hours >= 0 && hours <= 23)
               {
                   lcd.setCursor(10, 1);
                   lcd.print(hours);
                   delay(500);  
                   RTC.setHours(hours);
                   RTC.setClock();   
               }           
               if (hours > 23)
               {
                   hours = -1;
               }               
           }
           if (prog_sel == 2)   // Minute(+) Set time
           {
               lcd.setCursor(12, 1);
               lcd.print(F("   ")); 
               minutes = minutes + 1;                               
               if (minutes >= 0 && minutes <= 59)
               {
                   lcd.setCursor(12, 1);
                   lcd.print(minutes);
                   delay(500);  
                   RTC.setMinutes(minutes);
                   RTC.setClock();
               }           
               if (minutes > 59)
               {
                   minutes = -1;
               }               
           }
           if (prog_sel == 3)   // Date  (+) Set time
           {
               lcd.setCursor(10, 1);
               lcd.print(F("   ")); 
               dates = dates + 1;                               
               if (dates >= 1 && dates <= 31)
               {
                   lcd.setCursor(10, 1);
                   lcd.print(dates);
                   delay(500);  
                   RTC.setDate(dates);
                   RTC.setClock();   
               }           
               if (dates > 31)
               {
                   dates = -1;
               }               
           }
           if (prog_sel == 4)   // Month (+) Set time
           {
               lcd.setCursor(11, 1);
               lcd.print(F("   ")); 
               months = months + 1;                               
               if (months >= 1 && months <= 12)
               {
                   lcd.setCursor(11, 1);
                   lcd.print(months);
                   delay(500);  
                   RTC.setMonth(months);
                   RTC.setClock();   
               }           
               if (months > 12)
               {
                   months = -1;
               }               
           }
           if (prog_sel == 5)   // Year  (+) Set time
           {
               lcd.setCursor(10, 1);
               lcd.print(F("   ")); 
               years = years + 1;                               
               if (years >= 0 && years <= 99)
               {
                   lcd.setCursor(10, 1);
                   lcd.print(years);
                   delay(500);  
                   RTC.setYear(years);
                   RTC.setClock();   
               }           
               if (years > 99)
               {
                   years = -1;
               }               
           }
           if (prog_sel == 6)   // Day   (+) Set time
           {
               lcd.setCursor(8, 1);
               lcd.print(F("   ")); 
               days = days + 1;                               
               if (days >= 1 && days <= 7)
               {
                   lcd.setCursor(8, 1);
                   lcd.print(day_name[days-1]);
                   delay(500);  
                   RTC.setDayOfWeek(days);
                   RTC.setClock();   
               }           
               if (days > 7)
               {
                   days = -1;
               }               
           }
     }
       //---------------------------------------
       if (((prog == 2 || prog == 3) && prog_sel_timer1 == 1) || (prog == 5))    // Timer 1 & 2 & Light Timer
       {           
           if ((prog_sel % 2) != 0)   // Socket Set Hour(+) 
           {
               lcd.setCursor(14, 1);
               lcd.print(F("   "));           
               hr_val = hr_val + 1;                              
               if (hr_val >= 0 && hr_val <= 23)
               {
                   lcd.setCursor(14, 1);
                   lcd.print(hr_val);
                   delay(500);               
               }           
               if (hr_val > 23)
               {
                   hr_val = -1;
               }               
           }       
           if ((prog_sel % 2) == 0)   // Socket_A Set Minute(+)  
           {
               lcd.setCursor(14, 1); 
               lcd.print(F("   "));              
               min_val = min_val + 1;                               
               if (min_val >= 0 && min_val <= 59)
               {
                   lcd.setCursor(14, 1);
                   lcd.print(min_val);
                   delay(500);  
               }           
               if (min_val > 59)
               {
                   min_val = -1;
               }               
           } 
       }
       //---------------------------------------
     if (( prog == 2 || prog == 3) && prog_sel_timer1 == 0  &&  prog_sel == 1) // Timer 1 & 2 Days
       {
           prog_day = prog_day + 1;  
           switch (prog_day)          // Socket Set Day 
           {
           case 1:
                lcd.clear();                
                lcd.print(F("Press Up to: Set"));
                lcd.setCursor(0, 1);
                lcd.print(F("Press Dn to: Clr"));
                delay(1000);           
                break;
           case 2:
                lcd.clear();
                lcd.setCursor(4, 0);
                lcd.print(F("Everyday"));
                days_save();          
                break;
           case 3:
                lcd.setCursor(5, 0);
                lcd.print(F("Sunday"));
                days_save();       
                break;
           case 4:
                lcd.setCursor(5, 0);
                lcd.print(F("Monday"));
                days_save();         
                break;
           case 5:
                lcd.setCursor(4, 0);
                lcd.print(F("Tuesday"));
                days_save();          
                break;
           case 6:
                lcd.setCursor(3, 0);
                lcd.print(F("Wednesday"));
                days_save();        
                break;
           case 7:
                lcd.setCursor(4, 0);
                lcd.print(F("Thursday"));
                days_save();          
                break;
           case 8:
                lcd.setCursor(4, 0);
                lcd.print(F("Friday"));
                days_save();       
                break;
           case 9:
                lcd.setCursor(3, 0);
                lcd.print(F("Saturday"));
                days_save();          
                break;
           default: 
                prog_day = 0;
                //prog_sel = 0;   
           }
       }     
   }
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
   Button_Dn_State = digitalRead(Button_Dn);   
   if (Button_Dn_State == HIGH) 
   {
       btReady = 0;
       if (prog == 1)       // RTC
     {   
         if (prog_sel == 1)   // Hour  (-) Set time
           { 
               lcd.setCursor(10, 1);           
               hours = hours - 1;                              
               if (hours >= 0 && hours <= 23)
               {
               lcd.print(F("   "));  
               lcd.setCursor(10, 1);
               lcd.print(hours);
               delay(500);  
               RTC.setHours(hours);
               RTC.setClock();   
               }           
               if (hours < 0)
               {
                   hours = 24;
               }
       }      
           if (prog_sel == 2)   // Minute(-) Set time
           {
               lcd.setCursor(12, 1);           
               minutes = minutes - 1;                             
               if (minutes >= 0 && minutes <= 59)
               {
                   lcd.print(F("   "));   
                   lcd.setCursor(12, 1);
                   lcd.print(minutes);
                   delay(500);  
                   RTC.setMinutes(minutes);
                   RTC.setClock();   
               }           
               if (minutes < 0)
               {
                   minutes = 60;
               }               
           }
           if (prog_sel == 3)   // Date  (-) Set time
           {
               lcd.setCursor(10, 1);           
               dates = dates - 1;                               
               if (dates >= 1 && dates <= 31)
               { 
                   lcd.print(F("   ")); 
                   lcd.setCursor(10, 1);
                   lcd.print(dates);
                   delay(500);  
                   RTC.setDate(dates);
                   RTC.setClock();   
               }           
               if (dates < 0)
               {
                   dates = 32;
               }               
           }
           if (prog_sel == 4)   // Month (-) Set time
           {
               lcd.setCursor(11, 1);           
               months = months - 1;                               
               if (months >= 1 && months <= 12)
               {
                   lcd.print(F("   ")); 
                   lcd.setCursor(11, 1);
                   lcd.print(months);
                   delay(500);  
                   RTC.setMonth(months);
                   RTC.setClock();   
               }           
               if (months < 0)
               {
                   months = 13;
               }               
           }
           if (prog_sel == 5)   // Year  (-) Set time
           {
               lcd.setCursor(10, 1);            
               years = years - 1;                               
               if (years >= 0 && years <= 99)
               {
                   lcd.print(F("   "));
                   lcd.setCursor(10, 1);
                   lcd.print(years);
                   delay(500);  
                   RTC.setYear(years);
                   RTC.setClock();   
               }           
               if (years < 0)
               {
                   years = 100;
               }               
           }
           if (prog_sel == 6)   // Day   (-) Set time
           {
               lcd.setCursor(8, 1);           
               days = days - 1;                               
               if (days >= 1 && days <= 7)
               {
                   lcd.print(F("   ")); 
                   lcd.setCursor(8, 1);
                   lcd.print(day_name[days-1]);
                   delay(500);  
                   RTC.setDayOfWeek(days);
                   RTC.setClock();   
               }           
               if (days < 0)
               {
                   days = 8;
               }               
           }
     }
       //---------------------------------------------
       if ((prog == 2 && prog_sel_timer1 == 1) || (prog == 3 && prog_sel_timer1 == 1) || (prog == 5))  // Timer 1 & 2 & Light Timer
       {
           if ((prog_sel % 2) != 0)   // Socket_A Set Hour(-) 
           {
               lcd.setCursor(14, 1);                       
               hr_val = hr_val - 1;                              
               if (hr_val >= 0 && hr_val <= 23)
               { 
                   lcd.print(F("   "));   
                   lcd.setCursor(14, 1);
                   lcd.print(hr_val);
                   delay(500);               
               }           
               if (hr_val < 0)
               {
                   hr_val = 24;
               }               
           }
           if ((prog_sel % 2) == 0)   // Socket_A Set Minute(-)  
           {
               lcd.setCursor(14, 1);               
               min_val = min_val - 1;                               
               if (min_val >= 0 && min_val <= 59)
               {
                   lcd.print(F("   "));
                   lcd.setCursor(14, 1);
                   lcd.print(min_val);
                   delay(500);  
               }           
               if (min_val < 0)
               {
                   min_val = 60;
               }
           }               
       }
       //---------------------------------------------
     if (prog == 2 && prog_sel_timer1 == 0 && prog_sel == 1) // Timer 1 Days
       {
           switch (prog_day)     // Socket_A Save Day  
           {
           case 1:
                day1A = 0;
                day2A = 0;
                day3A = 0;
                day4A = 0;
                day5A = 0;
                day6A = 0;
                day7A = 0; 
                day_select_A();
                lcd.setCursor(1, 0);
                lcd.print(F("Days cleared"));
                lcd.setCursor(0, 1);
                lcd.print(F("Press Up:Restart"));
                delay(1000);           
                break;
           case 2:
                day1A = 1;
                day2A = 2;
                day3A = 3;
                day4A = 4;
                day5A = 5;
                day6A = 6;
                day7A = 7; 
                day_select_A();                                
                lcd.setCursor(0, 0);
                lcd.print(F("Everyday : Saved"));
                lcd.setCursor(2, 1);
                lcd.print(F("Press Select"));
                delay(1000); 
                prog_day = 0;
                prog_sel = 1;          
                break; 
           case 3:
                day1A = 1;
                EEPROM.write(11,  day1A);
                lcd.setCursor(0, 0);
                lcd.print(F("Sunday : Saved"));
                Press_Up_Sel();           
                break;
           case 4:
                day2A = 2;
                EEPROM.write(12,  day2A);
                lcd.setCursor(0, 0);
                lcd.print(F("Monday : Saved"));
                Press_Up_Sel();            
                break;
           case 5:
                day3A = 3;
                EEPROM.write(13,  day3A);
                lcd.setCursor(0, 0);
                lcd.print(F("Tuesday : Saved"));
                Press_Up_Sel();            
                break;
           case 6:
                day4A = 4;
                EEPROM.write(14,  day4A);
                lcd.setCursor(0, 0);
                lcd.print(F("Wednesday: Saved"));
                Press_Up_Sel();            
                break;
           case 7:
                day5A = 5;
                EEPROM.write(15,  day5A);
                lcd.setCursor(0, 0);
                lcd.print(F("Thursday : Saved"));
                Press_Up_Sel();            
                break;
           case 8:
                day6A = 6;
                EEPROM.write(16,  day6A);
                lcd.setCursor(0, 0);
                lcd.print(F("Friday : Saved"));
                Press_Up_Sel();            
                break;
           case 9:
                day7A = 7;
                EEPROM.write(17,  day7A);
                lcd.setCursor(0, 0);
                lcd.print(F("Saturday : Saved"));
                Press_Up_Sel();            
                break; 
           default:
                prog_day = 0;
                //prog_sel = 0;     
           }              
       }
     //---------------------------------------------
     if (prog == 3 && prog_sel_timer1 == 0 && prog_sel == 1) // Timer 2 Days
     {
           switch (prog_day)     // Socket_B Save Day  
           {
           case 1:
                day1B = 0;
                day2B = 0;
                day3B = 0;
                day4B = 0;
                day5B = 0;
                day6B = 0;
                day7B = 0; 
                day_select_B();
                lcd.setCursor(1, 0);
                lcd.print(F("Days cleared"));
                lcd.setCursor(0, 1);
                lcd.print(F("Press Up:Restart"));
                delay(1000);           
                break;
           case 2:
                day1B = 1;
                day2B = 2;
                day3B = 3;
                day4B = 4;
                day5B = 5;
                day6B = 6;
                day7B = 7; 
                day_select_B();                                
                lcd.setCursor(0, 0);
                lcd.print(F("Everyday : Saved"));
                lcd.setCursor(2, 1);
                lcd.print(F("Press Select"));
                delay(1000); 
                prog_day = 0;
                prog_sel = 1;          
                break; 
           case 3:
                day1B = 1;
                EEPROM.write(41,  day1B);
                lcd.setCursor(0, 0);
                lcd.print(F("Sunday : Saved"));
                Press_Up_Sel();         
                break;
           case 4:
                day2B = 2;
                EEPROM.write(42,  day2B);
                lcd.setCursor(0, 0);
                lcd.print(F("Monday : Saved"));
                Press_Up_Sel();            
                break;
           case 5:
                day3B = 3;
                EEPROM.write(43,  day3B);
                lcd.setCursor(0, 0);
                lcd.print(F("Tuesday : Saved"));
                Press_Up_Sel();           
                break;
           case 6:
                day4B = 4;
                EEPROM.write(44,  day4B);
                lcd.setCursor(0, 0);
                lcd.print(F("Wednesday: Saved"));
                Press_Up_Sel();            
                break;
           case 7:
                day5B = 5;
                EEPROM.write(45,  day5B);
                lcd.setCursor(0, 0);
                lcd.print(F("Thursday : Saved"));
                Press_Up_Sel();           
                break;
           case 8:
                day6B = 6;
                EEPROM.write(46,  day6B);
                lcd.setCursor(0, 0);
                lcd.print(F("Friday : Saved"));
                Press_Up_Sel();           
                break;
           case 9:
                day7B = 7;
                EEPROM.write(47,  day7B);
                lcd.setCursor(0, 0);
                lcd.print(F("Saturday : Saved"));
                Press_Up_Sel();           
                break; 
           default:
                prog_day = 0;
                //prog_sel = 0;     
           }              
       }                                        
   }
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
   Button_Sel_State = digitalRead(Button_Sel);   
   if (Button_Sel_State == HIGH) 
   {
       btReady = 0; 
       if (prog == 1)       // RTC Time Stored
       {
           prog_sel = prog_sel + 1;
           switch (prog_sel)
           {
           case 1:                 //RTC Hour Stored                
                Selected_1();                     
                Press_Up_Dn();
                lcd.print(F("Set Hour: "));
                lcd.setCursor(10, 1);
                lcd.print(hours); 
                delay(500);            
                break; 
           case 2:                 //RTC Minute Stored
                Press_Up_Dn();
                lcd.print(F("Set Minute: "));
                lcd.setCursor(12, 1);
                lcd.print(minutes); 
                delay(500);            
                break; 
           case 3:                 //RTC Date Stored
                Press_Up_Dn();
                lcd.print(F("Set Date: "));
                lcd.setCursor(10, 1);
                lcd.print(dates); 
                delay(500);            
                break; 
           case 4:                 //RTC Month Stored
                Press_Up_Dn();
                lcd.print(F("Set Month: "));
                lcd.setCursor(11, 1);
                lcd.print(months); 
                delay(500);            
                break;
           case 5:                 //RTC Year Stored
                Press_Up_Dn();
                lcd.print(F("Set Year: "));
                lcd.setCursor(10, 1);
                lcd.print(years); 
                delay(500);            
                break; 
           case 6:                 //RTC Day Stored
                Press_Up_Dn();
                lcd.print(F("Set Day: "));
                lcd.setCursor(8, 1);
                lcd.print(day_name[days-1]); 
                delay(500);
                break;
           case 7:      
                str = 1; 
                prog = 0;
                prog_sel = 0;  
                break;    
           }                            
       }
       //-----------------------------------------
       if (prog == 2 && prog_sel_timer1 == 0)  // Socket_A Day Stored
       {
           prog_sel = prog_sel + 1;
           switch (prog_sel)     
           {
           case 1:                
                Selected_1();                
                lcd.clear();                    
                lcd.print(F("Soc A: Day"));
                lcd.setCursor(0, 1);
                lcd.print(F("Press Up to: Set"));                                    
                delay(500);                           
                break; 
           case 2: 
                lcd.clear();               
                lcd.print(F("Soc A: Day Saved"));
                lcd.setCursor(0, 1);
                lcd.print(F("-> Sel: Set Time"));                
                delay(1000);
                prog_sel = 0;
                prog_sel_timer1 = 1;               
                break;           
           }             
       }
       if (prog == 2 && prog_sel_timer1 == 1)  // Socket_A On/OFF Stored
       {
           prog_sel = prog_sel + 1;
           switch (prog_sel)
           {
           case 1:              // Socket_A 
                Selected_0();                
                lcd.print(F("A-> 1 ON Hr:"));
                lcd.setCursor(14, 1);
                lcd.print(h_on_1A);
                hr_val = h_on_1A; 
                delay(500);            
                break; 
           case 2:              // Socket_A 1_On Hour Stored
                h_on_1A = hr_val;
                EEPROM.write(21, h_on_1A);
                hr_val = 0;
                Press_Up_Dn();
                lcd.print(F("A-> 1 ON Min:"));
                lcd.setCursor(14, 1);
                lcd.print(m_on_1A); 
                min_val = m_on_1A; 
                delay(500);            
                break;                
           case 3:              // Socket_A 1_On Minute Stored
                m_on_1A = min_val;
                EEPROM.write(22, m_on_1A);
                min_val = 0;
                Press_Up_Dn();
                lcd.print(F("A-> 1 OFF Hr:"));
                lcd.setCursor(14, 1);
                lcd.print(h_off_1A);
                hr_val = h_off_1A;  
                delay(500);            
                break; 
           case 4:              // Socket_A 1_Off Hour Stored
                h_off_1A = hr_val;
                EEPROM.write(23, h_off_1A);
                hr_val = 0;
                Press_Up_Dn();
                lcd.print(F("A-> 1 OFF Min:"));
                lcd.setCursor(14, 1);
                lcd.print(m_off_1A); 
                min_val = m_off_1A; 
                delay(500);            
                break; 
           case 5:              // Socket_A 1_Off Minute Stored
                m_off_1A = min_val;
                EEPROM.write(24, m_off_1A);
                min_val = 0;
                Press_Up_Dn();
                lcd.print(F("A-> 2 ON Hr:"));
                lcd.setCursor(14, 1);
                lcd.print(h_on_2A);
                hr_val = h_on_2A;   
                delay(500);            
                break;
           case 6:              // Socket_A 2_On Hour Stored
                h_on_2A = hr_val;
                EEPROM.write(25, h_on_2A);
                hr_val = 0;
                Press_Up_Dn();
                lcd.print(F("A-> 2 ON Min:"));
                lcd.setCursor(14, 1);
                lcd.print(m_on_2A); 
                min_val = m_on_2A; 
                delay(500);            
                break;
           case 7:              // Socket_A 2_On Minute Stored
                m_on_2A = min_val;
                EEPROM.write(26, m_on_2A);
                min_val = 0;
                Press_Up_Dn();
                lcd.print(F("A-> 2 OFF Hr:"));
                lcd.setCursor(14, 1);
                lcd.print(h_off_2A);
                hr_val = h_off_2A;  
                delay(500);            
                break;
           case 8:              // Socket_A 2_Off Hour Stored
                h_off_2A = hr_val;
                EEPROM.write(27, h_off_2A);
                hr_val = 0;
                Press_Up_Dn();
                lcd.print(F("A-> 2 OFF Min:"));
                lcd.setCursor(14, 1);
                lcd.print(m_off_2A); 
                min_val = m_off_2A; 
                delay(500);            
                break; 
           case 9:              // Socket_A 2_Off Minute Stored
                m_off_2A = min_val;
                EEPROM.write(28, m_off_2A);
                min_val = 0;                 
                delay(500);
                prog_sel = 0; 
                str = 1;              
                break;        
           }
       }  
     //------------------------------------------
     if (prog == 3 && prog_sel_timer1 == 0)  // Socket_B Day Stored
       {
           prog_sel = prog_sel + 1;
           switch (prog_sel)     
           {
           case 1:                
                Selected_1();                
                lcd.clear();                    
                lcd.print(F("Soc B: Day"));
                lcd.setCursor(0, 1);
                lcd.print(F("Press Up to: Set"));                                    
                delay(500);                           
                break; 
           case 2: 
                lcd.clear();               
                lcd.print(F("Soc B: Day Saved"));
                lcd.setCursor(0, 1);
                lcd.print(F("-> Sel: Set Time"));                
                delay(1000);
                prog_sel = 0;
                prog_sel_timer1 = 1;               
                break;               
           }             
       }
       if (prog == 3 && prog_sel_timer1 == 1)  // Socket_B On/OFF Stored
       {
           prog_sel = prog_sel + 1;
           switch (prog_sel)
           {
           case 1:              // Socket_B 
                Selected_0();                
                lcd.print(F("B-> 1 ON Hr:"));
                lcd.setCursor(14, 1);
                lcd.print(h_on_1B);
                hr_val = h_on_1B; 
                delay(500);            
                break; 
           case 2:              // Socket_B 1_On Hour Stored
                h_on_1B = hr_val;
                EEPROM.write(51, h_on_1B);
                hr_val = 0;
                Press_Up_Dn();
                lcd.print(F("B-> 1 ON Min:"));
                lcd.setCursor(14, 1);
                lcd.print(m_on_1B); 
                min_val = m_on_1B; 
                delay(500);            
                break;                
           case 3:              // Socket_B 1_On Minute Stored
                m_on_1B = min_val;
                EEPROM.write(52, m_on_1B);
                min_val = 0;
                Press_Up_Dn();
                lcd.print(F("B-> 1 OFF Hr:"));
                lcd.setCursor(14, 1);
                lcd.print(h_off_1B);
                hr_val = h_off_1B;  
                delay(500);            
                break; 
           case 4:              // Socket_B 1_Off Hour Stored
                h_off_1B = hr_val;
                EEPROM.write(53, h_off_1B);
                hr_val = 0;
                Press_Up_Dn();
                lcd.print(F("B-> 1 OFF Min:"));
                lcd.setCursor(14, 1);
                lcd.print(m_off_1B); 
                min_val = m_off_1B; 
                delay(500);            
                break; 
           case 5:              // Socket_B 1_Off Minute Stored
                m_off_1B = min_val;
                EEPROM.write(54, m_off_1B);
                min_val = 0;
                Press_Up_Dn();
                lcd.print(F("B-> 2 ON Hr:"));
                lcd.setCursor(14, 1);
                lcd.print(h_on_2B);
                hr_val = h_on_2B;   
                delay(500);            
                break;
           case 6:              // Socket_B 2_On Hour Stored
                h_on_2B = hr_val;
                EEPROM.write(55, h_on_2B);
                hr_val = 0;
                Press_Up_Dn();
                lcd.print(F("B-> 2 ON Min:"));
                lcd.setCursor(14, 1);
                lcd.print(m_on_2B); 
                min_val = m_on_2B; 
                delay(500);            
                break;
           case 7:              // Socket_B 2_On Minute Stored
                m_on_2B = min_val;
                EEPROM.write(56, m_on_2B);
                min_val = 0;
                Press_Up_Dn();
                lcd.print(F("B-> 2 OFF Hr:"));
                lcd.setCursor(14, 1);
                lcd.print(h_off_2B);
                hr_val = h_off_2B;  
                delay(500);            
                break;
           case 8:              // Socket_B 2_Off Hour Stored
                h_off_2B = hr_val;
                EEPROM.write(57, h_off_2B);
                hr_val = 0;
                Press_Up_Dn();
                lcd.print(F("B-> 2 OFF Min:"));
                lcd.setCursor(14, 1);
                lcd.print(m_off_2B); 
                min_val = m_off_2B; 
                delay(500);            
                break; 
           case 9:              // Socket_B 2_Off Minute Stored
                m_off_2B = min_val;
                EEPROM.write(58, m_off_2B);
                min_val = 0;                 
                delay(500);
                prog_sel = 0; 
                str = 1;              
                break;        
           }
       }
       //------------------------------------------    
     if (prog == 4)       // DC1 Temp Stored
       {
           prog_sel = prog_sel + 1;
           switch (prog_sel)
           {
           case 1:                      
                Selected_0();                
                lcd.print(F("DC1 Temp:"));
                lcd.setCursor(10, 1);
                lcd.print(DC1_Temp);
                lcd.write(byte(0));
                lcd.print(F("C "));  
                F_val = DC1_Temp; 
                delay(500);            
                break; 
           case 2:
                DC1_Temp = F_val;                
                EEPROM.write(252, DC1_Temp);
                F_val = 0;
                lcd.clear();   
                lcd.setCursor(0, 1);
                lcd.print(F("DC1 Temp:"));
                lcd.setCursor(10, 1);
                lcd.print(DC1_Temp);
                lcd.write(byte(0));
                lcd.print(F("C "));   
                lcd.setCursor(0, 0);
                lcd.print(F("    Saved       "));                     
                delay(1500);
        prog_sel = 0; 
                str = 1;                  
                break;        
           }
       }
       //---------------------------------------
       if (prog == 5)       // Light Timer Stored
       {
           prog_sel = prog_sel + 1;
           switch (prog_sel)
           {
           case 1:           // Light 1
                Selected_0();                
                lcd.print(F("L-> 1 ON Hr:"));
                lcd.setCursor(14, 1);
                lcd.print(h_on_1L);
                hr_val =  h_on_1L; 
                delay(500);            
                break; 
           case 2:           // Light 1_On Hour Stored
                h_on_1L = hr_val;
                EEPROM.write(201, h_on_1L);
                hr_val = 0;
                Press_Up_Dn();
                lcd.print(F("L-> 1 ON Min:"));
                lcd.setCursor(14, 1);
                lcd.print(m_on_1L); 
                min_val = m_on_1L; 
                delay(500);            
                break;                
           case 3:           // Light 1_On Minute Stored
                m_on_1L = min_val;
                EEPROM.write(202, m_on_1L);
                min_val = 0;
                Press_Up_Dn();
                lcd.print(F("L-> 1 OFF Hr:"));
                lcd.setCursor(14, 1);
                lcd.print(h_off_1L);
                hr_val =  h_off_1L;  
                delay(500);            
                break; 
           case 4:           // Light 1_Off Hour Stored
                h_off_1L = hr_val;
                EEPROM.write(203, h_off_1L);
                hr_val = 0;
                Press_Up_Dn();
                lcd.print(F("L-> 1 OFF Min:"));
                lcd.setCursor(14, 1);
                lcd.print(m_off_1L); 
                min_val = m_off_1L; 
                delay(500);            
                break; 
           case 5:           // Light 1_Off Minute Stored
                m_off_1L = min_val;
                EEPROM.write(204, m_off_1L);
                min_val = 0;
                Press_Up_Dn();
                lcd.print(F("L-> 2 ON Hr:"));
                lcd.setCursor(14, 1);
                lcd.print(h_on_2L);
                hr_val =  h_on_2L;   
                delay(500);            
                break;                
           case 6:              // Light 2_On Hour Stored
                h_on_2L = hr_val;
                EEPROM.write(205, h_on_2L);
                hr_val = 0;
                Press_Up_Dn();
                lcd.print(F("L-> 2 ON Min:"));
                lcd.setCursor(14, 1);
                lcd.print(m_on_2L); 
                min_val = m_on_2L; 
                delay(500);            
                break;
           case 7:              // Light 2_On Minute Stored
                m_on_2L = min_val;
                EEPROM.write(206, m_on_2L);
                min_val = 0;
                Press_Up_Dn();
                lcd.print(F("L-> 2 OFF Hr:"));
                lcd.setCursor(14, 1);
                lcd.print(h_off_2L);
                hr_val = h_off_2L;  
                delay(500);            
                break;
           case 8:              // Light 2_Off Hour Stored
                h_off_2L = hr_val;
                EEPROM.write(207, h_off_2L);
                hr_val = 0;
                Press_Up_Dn();
                lcd.print(F("L-> 2 OFF Min:"));
                lcd.setCursor(14, 1);
                lcd.print(m_off_2L); 
                min_val = m_off_2L; 
                delay(500);            
                break; 
           case 9:              // Light 2_Off Minute Stored
                m_off_2L = min_val;
                EEPROM.write(208, m_off_2L);
                min_val = 0;                 
                delay(500);
                prog_sel = 0; 
                str = 1;              
                break;      
           }
       }      
     //---------------------------------------
       if (prog == 8)       // Rain Timer Stored
       {
           prog_sel = prog_sel + 1;
           switch (prog_sel)
           {
           case 1:           // Rain 
                Selected_0();                
                lcd.print(F("F-> 1 ON Hr:"));
                lcd.setCursor(14, 1);
                lcd.print(h_on_1F);
                hr_val =  h_on_1F; 
                delay(500);            
                break;
           case 2:           // Rain 1_On Hour Stored
                h_on_1F = hr_val;
                EEPROM.write(221, h_on_1F);
                hr_val = 0;
                Press_Up_Dn();
                lcd.print(F("F-> 1 ON Min:"));
                lcd.setCursor(14, 1);
                lcd.print(m_on_1F); 
                min_val = m_on_1F; 
                delay(500);            
                break;            
           case 3:           // Rain 1_On Minute Stored
                m_on_1F = min_val;
                EEPROM.write(222, m_on_1F);
                min_val = 0;
                Press_Up_Dn();
                lcd.print(F("F-> 2 ON Hr:"));
                lcd.setCursor(14, 1);
                lcd.print(h_on_2F); 
                hr_val = h_on_2F; 
                delay(500);            
                break;
       case 4:           // Rain 2_On Hour Stored
                h_on_2F = hr_val;
                EEPROM.write(223, h_on_2F);
                hr_val = 0;
                Press_Up_Dn();
                lcd.print(F("F-> 2 ON Min:"));
                lcd.setCursor(14, 1);
                lcd.print(m_on_2F); 
                min_val = m_on_2F; 
                delay(500);            
                break;      
       case 5:           // Rain 2_On Minute Stored
                m_on_2F = min_val;
                EEPROM.write(224, m_on_2F);
                min_val = 0;              
                delay(500);
                prog_sel = 0; 
                str = 1;            
                break;      
           }
       }
       //---------------------------------------
       if (prog == 9)       // Reset
       {
           prog_sel = prog_sel + 1;
           switch (prog_sel)
           {
           case 1:
                lcd.clear();
        lcd.setCursor(1, 0);
                lcd.print(F("Press Sel to:"));
                lcd.setCursor(4, 1);
                lcd.print(F("Confirm"));
                delay(1000);        
                break; 
           case 2:
                lcd.clear(); 
                lcd.setCursor(2, 0);   
                lcd.print(F("Please Wait"));                
                for (byte i = 220; i > 0; i = i - 1) 
                {
                   //EEPROM.update(i, 0);
                     lcd.setCursor(7, 1);
                     lcd.print(i);
                     lcd.print(F("   "));           
                     delay(50);                     
                }
                lcd.clear(); 
                lcd.setCursor(5, 0);        
                lcd.print(F("Reset"));
                lcd.setCursor(3, 1);
                lcd.print(F("Successful"));
                delay(1000);        
                prog_sel = 0; 
                str = 1;                
                break;  
           }
       }                
   } 
}