วันอาทิตย์ที่ 22 เมษายน พ.ศ. 2561

Smart home Energy conservation .






Equipment

1. Arduino NANO




2.HC-06 Bluetooth module




3. 4 relays







code

#include<SoftwareSerial.h>
SoftwareSerial mySerial(10,11);//rx,tx
//const int LDR=A0;
//int xx;

int Light   = 2;
int Loundry  = 3;
int TV   = 4;
int Radio   = 5;
char  receivedChar;


void setup() {
 // Serial.begin(19200);
  mySerial.begin(9600);
  pinMode(Light,OUTPUT);
  pinMode(Loundry,OUTPUT);
  pinMode(TV,OUTPUT);
  pinMode(Radio,OUTPUT);

             digitalWrite(Light,HIGH); 
             digitalWrite(Loundry,HIGH);//setting motorA's directon
             digitalWrite(TV,HIGH);
             digitalWrite(Radio,HIGH);//setting motorB's directon
  
  
}

void loop()

{

  

// xx = analogRead(LDR); 
// mySerial.print(xx);

//Serial.println(xx);
 // delay(500);

   while (!mySerial.available());   // stay here so long as COM port is empty

  receivedChar = mySerial.read();

  if (receivedChar == 'A') {

            //digitalWrite(ENA,LOW);
            // digitalWrite(ENB,LOW);// High is start driving car
              
             digitalWrite(Light,LOW);
             Serial.println(receivedChar);
            
  }
              
  if (receivedChar == 'B') {

             // digitalWrite(ENA,LOW);
             // digitalWrite(ENB,LOW);// High is start driving car
              
              
                    
             digitalWrite(Loundry,LOW);
            
                         
  }      
  if (receivedChar == 'C') 
  
              {

             // digitalWrite(ENA,LOW);
             // digitalWrite(ENB,LOW);// High is start driving car
  
             digitalWrite(TV,LOW);
            
             

  } // if it is a 3 flash the LED

  if (receivedChar == 'D') {
  
              //digitalWrite(ENA,LOW);
              //digitalWrite(ENB,LOW);// High is start driving car
              
                          
             digitalWrite(Radio,LOW);
             

  } // if it is a 4 print out lots of sensor data


  if (receivedChar == 'E') {
  
             
             digitalWrite(Light,HIGH); 

  }

   if (receivedChar == 'F') {
  
             
             digitalWrite(Loundry,HIGH);//setting motorA's directon

  }

   if (receivedChar == 'G') {
  
             
             digitalWrite(TV,HIGH);

  }


   if (receivedChar == 'H') {
  
             
             digitalWrite(Radio,HIGH);//setting motorB's directon

  }
             
             
             
  
  }




mit 

ไม่มีความคิดเห็น:

แสดงความคิดเห็น