ARDUINO CODE

              ARDUINO UNO CODE:-
/*
This code is written by Masidur Rahaman to control the arduino from android app
Contact: 8172087979
This is the first project (S M A R T  D O O R)
Code written date 10-sep-2018
*/



#include<Servo.h>

Servo s1,s2;   //s1 for L/U and s2 for C/O
int m1=7;     //pin number of motor one
int m2=8;     //pin number of motor two     
int min1;     //minimum position of first servo (L/U)
int max1;     //maximum position of first servo
int min2;     //minimum position of second servo (C/O)
int max2;     //maximum position of second servo
int pos1,pos2;
char receve;

int d=250;     //delay to receve second request
int timeBetweenOC=3000; //it is requre for auto mode
int lightStatus;
int ledPin=12;  

void setup(){
           Serial.begin(9600);
           
           s1.attach(m1);
           min1=5; max1=70;
           pos1=max1;    //initialy unlocked door
           s1.write(pos1);
           delay(100);
           
           s2.attach(m2);
           min2=40; max2=141;
           pos2=max2;     //initialy closed door
           s2.write(pos2);
           delay(100);
           int lightStatus=0;
           int ledPin;
           pinMode(ledPin,OUTPUT);
          }

void loop() {
  receve='#';
  if(Serial.available())
  {
    receve=Serial.read();
  
     if( receve=='U' ||  receve=='O' || receve=='C' || receve=='L' || receve=='A'  || receve=='a'  || receve=='b' || receve=='S' )
        {
          Serial.write("PW");  //Please wait..
          
          if(receve=='U' || receve=='A'  || receve=='a')   // 'A' for automatic, 'a' for U & O
           {
             if(pos1==min1)                 //if the door is locked then Unlocked
              {
for (; pos1 < max1; pos1 += 1)
                { 
                 s1.write(pos1);             
                 delay(15);                      
                 }
                 Serial.write("DU");     //Door Unlocked
              }
              else                             
               {
                delay(d);
                Serial.write("AU");      //Already Unlocked
                }
            }
         if(receve=='O' || receve=='A'  || receve=='a')
           {
             if(pos2==max2)       //if the door is closed
              {
                if(pos1==max1)     //if the door is Unlocked then Opened
                  {
                  for (; pos2 > min2; pos2 -= 1)
                  { 
                   s2.write(pos2);             
                   delay(25);                     
                   }
                   Serial.write("DO");    //Door Opened
                   }
                 else
                     {
                       delay(d);
                       Serial.write("UDF");     //Please Unlocked the door first
                     }
              }
              else
               {
                delay(d);
                Serial.write("AO");      //Already Opened
               }
              if(receve=='A')
               delay(timeBetweenOC);  
           }
         if(receve== 'C' || receve=='A'  || receve=='b')         // 'b' for C & L
           {
             if(pos2==min2)                   //if the door is opened then closed
              {
                for (; pos2 < max2; pos2 += 1)
                { 
                 s2.write(pos2);             
                 delay(45);                      
                 }
                 Serial.write("DC");      //Door Closed
                }
               else
                {
                  delay(d);
                  Serial.write("AC");       //Already Closed
                }
            }
         if(receve=='L' || receve=='A'  || receve=='b')
           {
             if(pos2==max2 && pos1==max1)         //if door is close and unlocked then locked
              {
                for (; pos1 > min1; pos1 -= 1)
                { 
                 s1.write(pos1);             
                 delay(15);                     
                 }
                 Serial.write("DL");       //Door Locked
               }
             else if(pos1==min1)              //if door is already locked
               {
                delay(d);
                Serial.write("AL");   //Already Locked
               }
              else 
               {
                delay(d);
                Serial.write("CDF");    //Please Close the door first
               }
            }
          else if(receve=='S')
            {                                       //Status
               if(pos2==max2 && pos1==min1 && lightStatus==1)
               {
               delay(d);
               Serial.write("SCL1");           //Closed and Locked
               }
               else if(pos2==max2 && pos1==max1 && lightStatus==1)
                 {
                  delay(d);
                  Serial.write("SCU1");          //Closed and Unlocked
                 }
                 else if(lightStatus==1)
                  {
                    delay(d);
                    Serial.write("SOU1");       //Opened and Unlocked
                  }
               else if(pos2==max2 && pos1==min1 && lightStatus==0)
               {
               delay(d);
               Serial.write("SCL0");           //Closed and Locked
               }
               else if(pos2==max2 && pos1==max1 && lightStatus==0)
                 {
                  delay(d);
                  Serial.write("SCU0");          //Closed and Unlocked
                 }
                 else if(lightStatus==0)
                  {
                    delay(d);
                    Serial.write("SOU0");       //Opened and Unlocked
                  }
            }
         }
       else if(receve=='1' || receve=='0')
          {
            if(receve=='1' && lightStatus==0)
             {
              digitalWrite(ledPin,HIGH);
              lightStatus=1;
              delay(100);
              Serial.write("L1");              //Light On
             }
            if(receve=='0' && lightStatus==1)
             {
              digitalWrite(ledPin,LOW);
              lightStatus=0;
              delay(100);
              Serial.write("L0");              //Light Off
             }
          }
       else{
        Serial.write("CA");     //Click again
        delay(30);
       }
  }

}