Desmond's code for Room Automation Control

#include <Keypad.h>
#include <OneWire.h>
#include <LiquidCrystal_I2C.h>
#include <Wire.h> 
#include <dht11.h>
#include <math.h>

dht11 DHT11;
#define DHT11PIN 12 
 

long unsigned int lowIn;         

//the amount of milliseconds the sensor has to be low 
//before we assume all motion has stopped
long unsigned int pause = 15000;  
long unsigned int pause2 = 10000;

boolean lockLow = true;
boolean takeLowTime;  
OneWire  ds(13);  //on pin 48

int mSensor = 2;
float Thermvalue,fahrenheits,Total,Average,lightVal = 0.00,lighty;
float negFahren = 0.00, posFahren = 0.00;
float total,value;
char* ourCode = "#3";
int currentPosition = 0;
int nightLight = A2;

const byte rows = 4;
const byte cols = 4;

char keys[rows][cols] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
};

byte rowPins[rows] = {11,10,9,8};
byte colPins[cols] = {7,6,5,4};

Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, rows, cols);



int light = 3,lightSensor=A1;
int k =1,Y=1,T=1,passWord=1,J=0,x =1;
int h = A0;
int Music = A3;

LiquidCrystal_I2C lcd(0x27,20,4); 
void setup()
{
lcd.init();
lcd.backlight();
  pinMode(light,OUTPUT);
  pinMode(h,OUTPUT);
  pinMode(nightLight,OUTPUT);
  pinMode(Music,OUTPUT);
  pinMode(mSensor,INPUT);
  digitalWrite(h,HIGH);
  digitalWrite(Music,HIGH); 
  digitalWrite(light,LOW);
  digitalWrite(nightLight,LOW);
  digitalWrite(mSensor,LOW);
    Serial.begin(9600);
  
}

void loop(){
  


  char key = keypad.getKey();
  if (passWord==1){
    digitalWrite(nightLight,LOW);}

if (key == 'B' && Y == 1 && passWord == 1){
  digitalWrite(Music,LOW);


--Y;}
else if (key=='B' && Y ==0 && passWord==1){
digitalWrite(Music,HIGH);
  ++Y;}
  
 else if (key == 'A' && k== 1 && passWord ==1){

digitalWrite(light,HIGH);

--k;}
else if (key=='A' && k ==0  && passWord ==1){
  digitalWrite(light,LOW);
  ++k;}
else if (key == 'C' && T==1  && passWord ==1){
  lcd.noBacklight();

  --T;}
 else if (key== 'C' && T==0 && passWord ==1){
   lcd.backlight();
   ++T;}
   else if ( key == '1' && passWord == 1){
   if(digitalRead(light)==HIGH){
     digitalWrite(light,LOW);
     ++k;}
   if (digitalRead(Music)==LOW){
   digitalWrite(Music,HIGH);
   ++Y;}
   if (T==1){
    lcd.noBacklight();
  --T;}}
  
  else if ( key == '2' && passWord == 1){
   if(digitalRead(light)==LOW){
     digitalWrite(light,HIGH);
     --k;}
   if (digitalRead(Music)==HIGH){
   digitalWrite(Music,LOW);
   --Y;}
   if (T==0){
    lcd.backlight();
  ++T;}}
  
 else if (key =='*' && passWord==1){
--passWord;
   getOut();
   
   delay(30000);
 
  
    
  
   if (T==1){
    lcd.noBacklight();
  --T;}
   clearScreen();
   
   if (digitalRead(light)==HIGH){
   digitalWrite(light,LOW);
 ++k;}
   if (digitalRead(Music)==LOW){
   digitalWrite(Music,HIGH);
 ++Y;}
   for(int i = 0; i < 15; i++){
      
      delay(1000);
      }
  
 }
  
    
   getLight();
    
  getFahren();
 
  delay(10);

Part 2

while (passWord==0){   
      
    
 MotionLocked();     
       
  getLight();
  getFahren2();      
  int l;
  
  char keY = keypad.getKey();
  
 
  if (int(keY) !=0) {
  
    
    lcd.setCursor(14,3);
    lcd.print("    ");
    lcd.setCursor(14,3);
    
    for (l=0; l<=currentPosition; ++l)
    {
      lcd.backlight();
      lcd.print("*");
    }
    
    if (keY == ourCode[currentPosition])
      {
        ++currentPosition;
        if (currentPosition == 2)
        {
         
          ++passWord;
         
          currentPosition = 0;
          clearScreen();
          delay(150);
          digitalWrite(Music,LOW);
          --Y;
          digitalWrite(light,HIGH);
          --k;
          ++T;                    
          
        }
      } else {
        invalidCode();
        currentPosition = 0;
        getPAss();
      }
      
 
  
    
  }}




  

}





void getFahren() {
  
 

  
  
  byte i;
  byte present = 0;
  byte type_s;
  byte data[12];
  byte addr[8];
  float celsius, fahrenheits;
  
  if ( !ds.search(addr)) {
   
    ds.reset_search();
    
    return;
  }

  ds.reset();
  ds.select(addr);
  ds.write(0x44,1);         // start conversion, with parasite power on at the end
  
     // maybe 750ms is enough, maybe not
  // we might do a ds.depower() here, but the reset will take care of it.
  
  present = ds.reset();
  ds.select(addr);    
  ds.write(0xBE);         // Read Scratchpad

 
  for ( i = 0; i < 9; i++) {           // we need 9 bytes
    data[i] = ds.read();
   
  }
 
  unsigned int raw = (data[1] << 8) | data[0];
  if (type_s) {
    raw = raw << 3; // 9 bit resolution default
    if (data[7] == 0x10) {
      // count remain gives full 12 bit resolution
      raw = (raw & 0xFFF0) + 12 - data[6];
    }
  } else {
    byte cfg = (data[4] & 0x60);
    if (cfg == 0x00) raw = raw << 3;  // 9 bit resolution, 93.75 ms
    else if (cfg == 0x20) raw = raw << 2; // 10 bit res, 187.5 ms
    else if (cfg == 0x40) raw = raw << 1; // 11 bit res, 375 ms
    // default is 12 bit resolution, 750 ms conversion time
  }
  celsius = (float)raw / 16.0;
  
 
   
  
 fahrenheits = celsius * 1.8 + 32.0;

  

  
  lcd.setCursor(6,1);

  

    if (fahrenheits < 95.00 && fahrenheits > 55.00  ){
       if(fahrenheits < posFahren && fahrenheits > negFahren or negFahren == 0.00 && posFahren ==0.00){
   lcd.print(fahrenheits);

}}

if (fahrenheits > 75.99 && fahrenheits < 90.00 && lighty < 7.00){
  if(fahrenheits < posFahren && fahrenheits > negFahren or negFahren == 0.00 && posFahren ==0.00){
  if (digitalRead(h)==HIGH){
    digitalWrite(h,LOW);}}}
else if (fahrenheits <69.99 && fahrenheits >55.00 && lighty < 7.00){
   if(fahrenheits < posFahren && fahrenheits > negFahren or negFahren == 0.00 && posFahren ==0.00){
  if (digitalRead(h)==LOW){
    digitalWrite(h,HIGH);}}}
else if(lighty > 7.00 && fahrenheits < 68.00 && fahrenheits > 58.00){
     if(fahrenheits < posFahren && fahrenheits > negFahren or negFahren == 0.00 && posFahren ==0.00){
  if (digitalRead(h)==LOW){
    digitalWrite(h,HIGH);}}} 
else if (lighty > 7.00 && fahrenheits > 72.99 && fahrenheits < 90.00){
     if(fahrenheits < posFahren && fahrenheits > negFahren or negFahren == 0.00 && posFahren ==0.00){
  if (digitalRead(h)==HIGH){
    digitalWrite(h,LOW);}}}
  Serial.print("Temperature = ");
 Serial.println(fahrenheits);

   lcd.setCursor(0,1);
   lcd.print("Temp: ");
   
 int chk = DHT11.read(DHT11PIN);
  
  
   lcd.setCursor(11,1);
   lcd.print('F');
    lcd.setCursor(0,0);
    lcd.print("Light: ");
    lcd.print(lighty);
   lcd.setCursor(0,2);
   lcd.print("RH: ");
   lcd.setCursor(6,2);
   if((float)DHT11.humidity < 100.00){
   lcd.print((float)DHT11.humidity);}
   lcd.print("%");
    if (fahrenheits < 95.00 && fahrenheits > 55.00  ){
   negFahren = fahrenheits - 1.50;
   posFahren = fahrenheits + 1.50;}
  
    
     
     
}

Was there, perhaps, a question?

BTW, have

you noticed how hard it is to read stuff when it wanders all over the page?

part 3

void clearScreen()
{
  lcd.setCursor(0,0);
  lcd.print("                    ");
  lcd.setCursor(0,1);
  lcd.print("                    ");
  lcd.setCursor(0,2);
  lcd.print("                    ");
  lcd.setCursor(0,3);
  lcd.print("                    ");
}


void getLight(){
   

 
   lightVal= analogRead(lightSensor);
    lighty = lightVal/100;
    
  
   
  


 Serial.print("Light val = ");
 Serial.println(lightVal/100);
 ;}
 
 void getOut()
{

  clearScreen();
  lcd.setCursor(0,0);
  lcd.print("********************");
  lcd.setCursor(0,1);
  lcd.print("** ACCESS GRANTED **");
  lcd.setCursor(0,2);
   int time = 30 - millis()/1000;
  lcd.print(time);
  lcd.setCursor(0,3);
  lcd.print("********************");}
  
  void invalidCode()
{
  
  clearScreen();
  lcd.setCursor(0,0);
  lcd.print("********************");
  lcd.setCursor(0,1);
  lcd.print("** ACCESS DENIED! **");
  lcd.setCursor(0,2);
  lcd.print("**  INVALID CODE  **");
  lcd.setCursor(0,3);
  lcd.print("********************");
  
  delay(3000);
  lcd.noBacklight();
  clearScreen();
 
}


void getPAss()
{
      int l;
  
  char keY = keypad.getKey();
 
  if (int(keY) != 0) {
  
    
    lcd.setCursor(14,3);
    lcd.print("    ");
    lcd.setCursor(14,3);
    
    for (l=0; l<=currentPosition; ++l)
    {
      lcd.backlight();
      lcd.print("*");
    }
    
    if (keY == ourCode[currentPosition])
      {
        ++currentPosition;
        if (currentPosition == 2)
        {
         ++passWord;
          currentPosition = 0;
          clearScreen();
        }
      } else {
        invalidCode();
        currentPosition = 0;
        getPAss();
      }
    
    
  }
}







void getFahren2() {

  
  
  byte i;
  byte present = 0;
  byte type_s;
  byte data[12];
  byte addr[8];
  float celsius, fahrenheits;
  
  if ( !ds.search(addr)) {
   
    ds.reset_search();
    
    return;
  }

  ds.reset();
  ds.select(addr);
  ds.write(0x44,1);         // start conversion, with parasite power on at the end
  
     // maybe 750ms is enough, maybe not
  // we might do a ds.depower() here, but the reset will take care of it.
  
  present = ds.reset();
  ds.select(addr);    
  ds.write(0xBE);         // Read Scratchpad

 
  for ( i = 0; i < 9; i++) {           // we need 9 bytes
    data[i] = ds.read();
   
  }
 
  unsigned int raw = (data[1] << 8) | data[0];
  if (type_s) {
    raw = raw << 3; // 9 bit resolution default
    if (data[7] == 0x10) {
      // count remain gives full 12 bit resolution
      raw = (raw & 0xFFF0) + 12 - data[6];
    }
  } else {
    byte cfg = (data[4] & 0x60);
    if (cfg == 0x00) raw = raw << 3;  // 9 bit resolution, 93.75 ms
    else if (cfg == 0x20) raw = raw << 2; // 10 bit res, 187.5 ms
    else if (cfg == 0x40) raw = raw << 1; // 11 bit res, 375 ms
    // default is 12 bit resolution, 750 ms conversion time
  }
  celsius = (float)raw / 16.0;
 
   
  
  fahrenheits = celsius * 1.8 + 32.0;
 
  

if (fahrenheits > 75.99 && fahrenheits < 90.00 && lighty < 7.00){
  if(fahrenheits < posFahren && fahrenheits > negFahren or negFahren == 0.00 && posFahren ==0.00){
  if (digitalRead(h)==HIGH){
    digitalWrite(h,LOW);}}}
else if (fahrenheits <69.99 && fahrenheits >55.00 && lighty < 7.00){
   if(fahrenheits < posFahren && fahrenheits > negFahren or negFahren == 0.00 && posFahren ==0.00){
  if (digitalRead(h)==LOW){
    digitalWrite(h,HIGH);}}}
else if(lighty > 7.00 && fahrenheits < 68.00 && fahrenheits > 58.00){
     if(fahrenheits < posFahren && fahrenheits > negFahren or negFahren == 0.00 && posFahren ==0.00){
  if (digitalRead(h)==LOW){
    digitalWrite(h,HIGH);}}} 
else if (lighty > 7.00 && fahrenheits > 72.99 && fahrenheits < 90.00){
     if(fahrenheits < posFahren && fahrenheits > negFahren or negFahren == 0.00 && posFahren ==0.00){
  if (digitalRead(h)==HIGH){
    digitalWrite(h,LOW);}}}
   if (fahrenheits < 95.00 && fahrenheits > 55.00  ){
     negFahren = fahrenheits - 1.50;
   posFahren = fahrenheits + 1.50;}
   Serial.print("Temperature = ");
 Serial.println(fahrenheits);
     
     
}
  
  
  void MotionLocked(){
    if(digitalRead(mSensor) == HIGH){
         //the led visualizes the sensors output pin state
       if(lockLow){  
         //makes sure we wait for a transition to LOW before any further output is made:
         lockLow = false;            
         
         delay(600);
         digitalWrite(nightLight,HIGH);
         
         }         
         takeLowTime = true;
       }
       
         if(digitalRead(mSensor) == LOW){       
       //the led visualizes the sensors output pin state

       if(takeLowTime){
        lowIn = millis();          //save the time of the transition from high to LOW
        takeLowTime = false;       //make sure this is only done at the start of a LOW phase
        }
       //if the sensor is low for more than the given pause, 
       //we assume that no more motion is going to happen
       if(!lockLow && millis() - lowIn > pause){  
           //makes sure this block of code is only executed again after 
           //a new motion sequence has been detected
           lockLow = true;                        
         
           digitalWrite(nightLight,LOW);
         
          
           }
           
       }}
 
  void MotionUnlocked(){
    if(digitalRead(mSensor) == HIGH){
         //the led visualizes the sensors output pin state
       if(lockLow){  
         //makes sure we wait for a transition to LOW before any further output is made:
         lockLow = false;            
         
      
        
         
         }         
         takeLowTime = true;
       }
       
         if(digitalRead(mSensor) == LOW){       
       //the led visualizes the sensors output pin state

       if(takeLowTime){
        lowIn = millis();          //save the time of the transition from high to LOW
        takeLowTime = false;       //make sure this is only done at the start of a LOW phase
        }
       //if the sensor is low for more than the given pause, 
       //we assume that no more motion is going to happen
       if(!lockLow && millis() - lowIn > pause2){  
           //makes sure this block of code is only executed again after 
           //a new motion sequence has been detected
           lockLow = true;                        
         
          --passWord;
         
          
           }
           
       }}

The suspense is killing me.

They all get killed off in the season finale

Spoilsport