Mohamed Maher
Published © CC0

Smart Home System [AHCS]

Very easy and effective home automation system based on PIC16F877A. Control home appliances remotely and monitor fire and break-ins.

AdvancedFull instructions provided10 hours1,744
Smart Home System [AHCS]

Things used in this project

Hardware components

PIC 16f877a
×2
Standard LCD - 16x2 White on Blue
Adafruit Standard LCD - 16x2 White on Blue
×2
Button Pad 4x4 - LED Compatible
SparkFun Button Pad 4x4 - LED Compatible
or normal keypad as i used
×1
Temperature Sensor
Temperature Sensor
×1
IR TX-RX sensor
×1
relays 5 volt coil
the quantity depends on the number of home appliances you will control
×5
DTMF decoder MT8870
×1
LEDS + Resistors + capacitors + buttons
as showed in schematics below
×1
Buzzer
Buzzer
×1

Software apps and online services

Protues 8
MikroC for PIC

Story

Read more

Schematics

main system simulation in protues

security system in protues

Code

Main system MikroC code

C/C++
this code uses a lot of MIkroC libraries , please refer to IDE help for instructions , if you are not familiar with MikroC
/* *******************************
** File: SH V2.1
** Developer :  M.Maher
**MUC : PIC 16F877A
       Clock - 20MHz
       MIkro C Compilier
All CopyRights Reserved for Infinity-Tech
Date : 12/3/2016
************************************
 * Please contact me for more information .
 * Mobile: +201060449214
 * Gmail : Mrjoe767@gmail.com
 * FB    : WWW.facebook.com/joe2050
 * Linkedin : www.linkedin.com/in/mohamed-maher-37b167a5
  ***********************************
*/



// LCD module connections
sbit LCD_RS at Rc0_bit;
sbit LCD_EN at Rc1_bit;
sbit LCD_D4 at Rc2_bit;
sbit LCD_D5 at Rc3_bit;
sbit LCD_D6 at Rc4_bit;
sbit LCD_D7 at Rc5_bit;

sbit LCD_RS_Direction at TRISc0_bit;
sbit LCD_EN_Direction at TRISc1_bit;
sbit LCD_D4_Direction at TRISc2_bit;
sbit LCD_D5_Direction at TRISc3_bit;
sbit LCD_D6_Direction at TRISc4_bit;
sbit LCD_D7_Direction at TRISc5_bit;
// End LCD module connections



// Var_Declare .



unsigned int LM_Temp = 0;
   float mV;
   unsigned char temp[16];



// Functions



void main() {
  portb=0;
  trisb=0b00111111;

  porta=0;
  trisa=0b00000001;
  portd=0;
  trisd=0;



ADC_Init();


    Lcd_Init();
    Lcd_Cmd(_LCD_CLEAR);
    Lcd_Cmd(_LCD_CURSOR_OFF);
    Lcd_Out(1,2 , "Mansoura Unvi.");
    Lcd_Out(2, 4, "SH-DTMF");
    Delay_ms(1500);
    Lcd_Cmd(_LCD_CLEAR);

while (1) {
  LM_Temp = ADC_Read(0);

  mV = LM_Temp * 5000.0 /1024.0;
  mV = mV/10.0;
    FloatToStr(mV, temp);
    temp[4]=0;
    Lcd_Chr(1,5,223);
    Lcd_Chr(1,6,'C');
    Lcd_Out(1, 1, temp);
    Delay_ms(500);
    
    //BUTTONS
          if(portb.b4==1){
                  portd=255;
                  lcd_out(1,10,"GAS/W");
                  lcd_out(2,10,"[ON]");
                  lcd_out(2,1,"Secure");
                  
                  }
                  
          if(portb.b5==1){
                  portd=0;
                  lcd_out(1,10,"GAS/W");
                  lcd_out(2,10,"[OFF]");
                  lcd_out(2,1,"UnSecure");

                  }
     //DTMF CONTROL States , google DTMF decoding table to understand how it works 
     
      if( portb.f3 ==0 && portb.f2 ==0 && portb.f1 ==0 && portb.f0 ==1)      //1- LH ON
          { portd.b0=1;  }

        else if( portb.f3 ==0 && portb.f2 ==0 && portb.f1 ==1 && portb.f0 ==0) //2- LH F
          {  portd.b0=0; }

        else if( portb.f3 ==0 && portb.f2 ==0 && portb.f1 ==1 && portb.f0 ==1) //3 - mot ON
          {  portd.b2=1; }

        else if( portb.f3 ==0 && portb.f2 ==1 && portb.f1 ==0 && portb.f0 ==0) //4 - mot F
          {  portd.b2=0; }

        else if( portb.f3 ==0 && portb.f2 ==1 && portb.f1 ==0 && portb.f0 ==1)  //5 - w/gas ON
          { portd.b3=1;
            lcd_out(1,10,"GAS/W");
            lcd_out(2,10,"[ON]"); }

        else if( portb.f3 ==0 && portb.f2 ==1 && portb.f1 ==1 && portb.f0 ==0)  //6 - w/GAS F
          { portd.b3=0;
            lcd_out(1,10,"GAS/W");
            lcd_out(2,10,"[OFF]");}

        else if( portb.f3 ==0 && portb.f2 ==1 && portb.f1 ==1 && portb.f0 ==1)  //7 - Secure ON
          {  portd.b4=1;
             lcd_out(2,1,"Secure"); }

        else if( portb.f3 ==1 && portb.f2 ==0 && portb.f1 ==0 && portb.f0 ==0)  //8 - secure  F
          {  portd.b4=0;
             lcd_out(2,1,"UnSecure"); }

        else if( portb.f3 ==1 && portb.f2 ==0 && portb.f1 ==0 && portb.f0 ==1)  //full ON
          {  portd.b1=1;
              }

          /*if( portb.f3 ==0 && portb.f2 ==0 && portb.f1 ==0 && portb.f0 ==0)  //0 alarm F
          {  portd=0;
             lcd_out(2,1,"UnSecure"); }  */



          }


}

}

Security System MikroC code

C/C++
/* *************************
   Task :  securty system
   PIC  : 16F877A
   Coder: M.Maher
   osc : 20 MHZ
***************************
 * Please contact me for more information .
 * Mobile: +201060449214
 * Gmail : Mrjoe767@gmail.com
 * FB    : WWW.facebook.com/joe2050
 * Linkedin : www.linkedin.com/in/mohamed-maher-37b167a5
  ******************************************************** */ 


#define d delay_ms(800)

sbit LCD_RS at Rc0_bit;
sbit LCD_EN at Rc1_bit;
sbit LCD_D4 at Rc2_bit;
sbit LCD_D5 at Rc3_bit;
sbit LCD_D7 at Rc4_bit;
sbit LCD_D6 at Rc5_bit;

sbit LCD_RS_Direction at TRISc0_bit;
sbit LCD_EN_Direction at TRISc1_bit;
sbit LCD_D4_Direction at TRISc2_bit;
sbit LCD_D5_Direction at TRISc3_bit;
sbit LCD_D7_Direction at TRISc4_bit;
sbit LCD_D6_Direction at TRISc5_bit;

/////////////////////////////////////////


char str[16];
int xx;
char  keypadPort at PORTD;
unsigned short password[6];
unsigned short pass();
unsigned short i,j;


unsigned int temp;
float volt;


void main() {
  
portb=0;
trisb=0b00000111;

keypad_init();
lcd_init();
Lcd_Cmd(_LCD_CLEAR);
lcd_cmd(_lcd_cursor_off);

    pass();
       Lcd_Cmd(_LCD_CLEAR);
       lcd_out(1,2,"Mansoura Univ.");
       lcd_out(2,3,"Home Security");
       d;d;
       Lcd_Cmd(_LCD_CLEAR);
    
    
while(1){
    check:
    if(portb.b0==1){
           portb.b3=1;
           Lcd_out(1,2,"Calling 911 ...");
           lcd_out(2,5,"UNSECURE");
           delay_ms(1000);
             }
    if(portb.b1==0){
           portb.b3=1;
           Lcd_out(1,2,"Calling 911 ...");
           lcd_out(2,6,"FIRE");
           delay_ms(1000);
             }
    if(portb.b2==1){
           Lcd_Cmd(_LCD_CLEAR);
           portb.b3=0;
           lcd_out(1,6,"SECURE");
           goto check ;
             }
    }
 
 }


// get passoword function 

unsigned short pass(){
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1, 1, "You Have 3 Tries");d;d;
loop:

Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1, 1, "Enter Password :");

for(i=0;i<4;i++){

while (password[i] == 0)
           {
            password[i] = Keypad_Key_Click();
           }
          if(password[i]==1)     password[i]  = '7';
          if(password[i]==2)     password[i]  = '4';
          if(password[i]==3)     password[i]  = '1';
          if(password[i]==5)     password[i]  = '8';
          if(password[i]==6)     password[i]  = '5';
          if(password[i]==7)     password[i]  = '2';
          if(password[i]==8)     password[i]  = '0';
          if(password[i]==9)     password[i]  = '9';
          if(password[i]==10)    password[i]  = '6';
          if(password[i]==11)    password[i]  = '3';
          Lcd_Chr(2, i+1,password[i]);
      }
    if (strcmp(password,"1993")==0){return 1;}
    else {
     j++;
    if(j==3){while(1){
     lcd_cmd(_lcd_clear);
     lcd_out(1,1,"Wrong User...");d;
     portb.B3=1;
     }}
    else {
    password[0]=0;
    password[1]=0;
    password[2]=0;
    password[3]=0;

     lcd_cmd(_lcd_clear);
     lcd_out(1,1,"Wrong password");
     d;d;
     goto loop;
}}}

Credits

Mohamed Maher

Mohamed Maher

1 project • 28 followers
Experienced Founder with a demonstrated history of working in the electrical and electronic manufacturing industry, Embedded System solution

Comments