Tuesday, March 18, 2014

ZONE BASED HOME SECURITY SYSTEM


ZONE BASED HOME SECURITY SYSTEM


A microcontroller (ATMEGA16) based home security system.

The prototype we made have the following features:
                   o   Multi - zone security: The entire area is divided into different zones with customizable                  security levels and individual monitoring. The prototype comes with a three zone detections            and a two level security for each.
Customizable security levels: Each zone security level can be individually customized. A two level security is made available in the prototype
o   User Defined Password: Once activated, the system can be deactivated only upon the entry of the correct password. User can easily change the password using the keypad 
o   Fire alarm: Constant temperature  monitoring which triggers a fire alarm and motor at excess temperature levels
o   User friendly LCD interface and 4*4 keypad: The prototype comes with a 4*4 keypad and an LCD interface which can be used to change the password, change security levels etc.
o   Screensaver featuring current system status and current temperature
o   Multi LED display to indicate the current status of the system, zone security status and excessive temperature levels
Security breach is detected using IR-Photodiode (Tx-Rx) pair . A drop in light intensity on the receiver would trigger the alarm system. The detailed circuit diagram is given in the later section.



Block diagram


COMPONENTS USED


            List of hardware components:
o   ATMega 16
o   Resistors
o   LEDs
o   Transistor
o   4 x 4 keypad
o   IR LEDs
o   Photodiodes
o   Capacitors
o   16*2 LCD
o   Buzzer
o   LM35
o   BC547
o   Power LED
o   Push Button - Large
o   Push Button - Small
o   Crystal Oscillator
o   General PCB
o   DC Motor

            List of software components:
o   Proteus Isis 7
o   Programmer’s Notepad
o   WINAVR

Component Description



LM35 Temperature Sensor





LM35 is a precision IC temperature sensor with its output proportional to the temperature (in oC). The sensor circuitry is sealed and therefore it is not subjected to oxidation and other processes. With LM35, temperature can be measured more accurately than with a thermistor. It also possess low self-heating and does not cause more than 0.1 oC temperature rise in still air.
The operating temperature range is from -55°C to 150°C. The output voltage varies by 10mV in response to every oC rise/fall in ambient temperature, i.e., its scale factor is 0.01V/ oC.






Photodiode-IR sensor

IR Led is used as the transmitter and Photo diode as the receiver. A 10kohm resistor is given in series with the photo diode, with a terminal to ground. Photo diode, being reverse biased, conducts only when IR light falls on it. So when no light falls on the diode, the output will be low and high otherwise.

The transmitter and receiver are kept at two points, some 20cm apart, with the light coming from IR Led falling directly onto the photo-diode. So normally output will be high. When an intruder comes in between the two, the path is broken and the photo diode goes to off stage, and the output goes low. The output is connected to the interrupt pin of the MCU, which detects the high-low transition and initiates the corresponding set of actions. 

Circuit Diagram



CONCLUSION AND FUTURE SCOPE


Zone based Home Security System with features including user defined password, customizable level security for various zones and temperature monitoring was successfully designed and implemented.
The prototype we made consists of three zones. New zones may be easily added according to the need. We have demonstrated only the working of intruder sensor and temperature sensors. Others types of sensors to detect smoke, gas leak, indoor/outdoor motion etc. can be added/replaced with existing sensors. Sensors may be place in a distant location and microcontroller can monitor it using RF modules.



CODE


#include <avr/io.h>
#include <util/delay.h>
#include "lcd.c"
#include<avr/interrupt.h>
//#include <lcd.h>
char masterpswd[6]="1111",temp[6];
int reftemp=16, tempstat=0;
char x[2];

char key_check(int);

void setupint() //setup interrupts
{
GICR|=(1<<INT1)|(1<<INT0)|(1<<INT2);// int0 and int1 falling edge
MCUCSR|=(0<<ISC2); // int2 falling edge
MCUCR=0b01010;
}

void adcinit()  //initialize adc
{
ADCSRA=0b11010110;
ADMUX=0b01100111;
}

uint8_t getadc() // return temperature adc
{
uint8_t adc;
ADCSRA|=(1<<ADSC);                         // start conversion
while(!(ADCSRA & (1<<ADIF)));          // waiting for ADIF, conversion complete
ADCSRA|=(1<<ADIF);              // clearing of ADIF, it is done by writing 1 to it
adc=ADCH;
return adc;
}

void displays(char str[20])
{
lcd_clrscr();
lcd_home(); 
lcd_puts(str);
_delay_ms(200);
}



int getpassword(int n) // function to read //password
{
int i=0;
char key, temp[6];
lcd_clrscr();
lcd_home(); 
lcd_puts("Enter Password:");
_delay_ms(200);
lcd_gotoxy(0,1);

while(i<4)
{
key=key_check(0);
if(n==2)
{
if(key=='A')
return 2;

}
beep(1);
temp[i]=key;
lcd_puts("*");
_delay_ms(200);
i++;
}

temp[i]='\0';
//lcd_puts(temp);
//_delay_ms(1000);
if(strcmp(temp,masterpswd)==0)                           
{
return 1;
}
else
{
lcd_clrscr();
lcd_home(); 
lcd_puts("WRONG PASSWORD");
for(i=0;i<5;i++)
{
beep(1);
_delay_ms(100);
}
return 0;
}



}

void timer_start()
{

TIMSK |= (1 << TOIE1 ); // Enable overflow interrupt
TCNT1=40000;//26472
TCCR1B |= (0<<CS12) | (1<<CS11) | (1<<CS10); // Start timer at Fcpu /8

}

void timer_stop()
{
TIMSK |= (0 << TOIE1 ); // Disable overflow interrupt
}


struct security
{
int zone;
char mobno[11];
int sec;

}s[3];


void disjtag() //disable jtag
{
MCUCSR|=(1<<JTD);
MCUCSR|=(1<<JTD);
}


void checktemp()
{
uint8_t x;
x=getadc();
if(x>reftemp)
{
tempstat=1;  // above reference temperature
 PORTD|=(1<<6);
 PORTB|=(1<<7);
  displays("FIRE ALARM ON");
 _delay_ms(1000);
}
else
{
 PORTD &= ~(1<<6);
 PORTB &= ~(1<<7);
tempstat=0;
}
}

void ss() // Screen Saver
{
uint8_t x;
displays("SECURITY ON");
_delay_ms(1000);
displays("STATUS : SECURE");
_delay_ms(1000);
x=getadc();
x=(float)(x*1.8);
itoa(x,temp,10);
lcd_clrscr();
lcd_home(); 
lcd_puts("TEMPERATURE \n   ");
lcd_puts(temp);
lcd_puts(" 'C");
_delay_ms(1000);
displays("PRESS ANY KEY\nFOR MENU");
_delay_ms(1000);

}






char key_check(int n)                                                 //function to check and identify a character
{
uint8_t r,c,k;

while(1)
{
PORTC=0xEF;// row A=0

if((PINC & 0b01) == 0b0)
{
_delay_ms(10);
if((PINC & 0b01) ==0)
return '0';// r1 c1
}

else
if((PINC & 0b010) == 0b0)
{
_delay_ms(10);
if((PINC & 0b010) ==0)
return '1';// r1 c2
}

else
if((PINC & 0b0100) == 0b0)
{
_delay_ms(10);
if((PINC & 0b0100) ==0)
return '2';// r1 c3
}

else
if((PINC & 0b01000) == 0b0)
{
_delay_ms(10);
if((PINC & 0b01000) ==0)
return '3';// r1 c4
}

PORTC=0xDF;// row B=0

if((PINC & 0b01) == 0b0)
{
_delay_ms(10);
if((PINC & 0b01) ==0)
return '4';// r1 c1
}

else
if((PINC & 0b010) == 0b0)
{
_delay_ms(10);
if((PINC & 0b010) ==0)
return '4';// r1 c2
}

else
if((PINC & 0b0100) == 0b0)
{
_delay_ms(10);
if((PINC & 0b0100) ==0)
return '5';// r1 c3
}

else
if((PINC & 0b01000) == 0b0)
{
_delay_ms(10);
if((PINC & 0b01000) ==0)
return '6';// r1 c4
}          


PORTC=0xBF;// row C=0

if((PINC & 0b01) == 0b0)
{
_delay_ms(10);
if((PINC & 0b01) ==0)
return '8';// r1 c1
}

else
if((PINC & 0b010) == 0b0)
{
_delay_ms(10);
if((PINC & 0b010) ==0)
return '7';// r1 c2
}

else
if((PINC & 0b0100) == 0b0)
{
_delay_ms(10);
if((PINC & 0b0100) ==0)
return '8';// r1 c3
}

else
if((PINC & 0b01000) == 0b0)
{
_delay_ms(10);
if((PINC & 0b01000) ==0)
return '9';// r1 c4
}

PORTC=0x7F;// row D=0

if((PINC & 0b01) == 0b0)
{
_delay_ms(10);
if((PINC & 0b01) ==0)
return 'C';// r1 c1
}

else
if((PINC & 0b010) == 0b0)
{
_delay_ms(10);
if((PINC & 0b010) ==0)
return 'A';// r1 c2
}

else
if((PINC & 0b0100) == 0b0)
{
_delay_ms(10);
if((PINC & 0b0100) ==0)
return '0';// r1 c3
}

else
if((PINC & 0b01000) == 0b0)
{
_delay_ms(10);
if((PINC & 0b01000) ==0)
return 'B';// r1 c4
}

if(n==1)
return 'A';       
}
}



void initiate(struct security s)
{
if(s.sec==1)
{
PORTB=0x07;
}
else
if(s.sec==0)
{

PORTB=0x05;
}
if(s.zone==1)
{
PORTB|=(1<<4);
displays("ZONE 1 SECURITY\n BREACHED !!!!!!");
//timer_start();
_delay_ms(300);
}

else
if(s.zone==2)
{
PORTB|=(1<<5);
displays("ZONE 2 SECURITY\n BREACHED !!!!!!");
_delay_ms(300);
}
else if(s.zone==3)
{
PORTB|=(1<<6);
displays("ZONE 3 SECURITY\n BREACHED !!!!!!");
_delay_ms(300);
}


}



void bootup()
{
displays("WELCOME");
_delay_ms(500);
displays("ZONE BASED HOME\nSECURITY SYSTEM");
_delay_ms(500);
}



void menu()
{
char k;
int i;

lcd_clrscr();
lcd_home(); 
lcd_puts("MENU\nPress 0");
while((k=key_check(0))!='0')
{
if(k=='A')
return;
}
beep(1);

lcd_clrscr();
lcd_home();
lcd_puts("1.SETTINGS \n2.USER PROFILE");
while(1)
{
k=key_check(0);
beep(1);
if(k=='A')
return;
if((k=='1') || (k=='2') )
break;
}
if(k=='1')
            {
           
            displays("AREA \nPRESS 1, 2 OR 3 ");
            while(1)
            {
            k=key_check(0);
            beep(1);
            if(k=='A')
            return;
            if((k=='1')||(k=='2')||(k=='3'))
            break;
            }
           
            if(k=='1')
                        {
                        displays("ZONE 1\n1.LOW  2.HIGH  ");
                        while(1)
                        {
                        k=key_check(0);
                        beep(1);
                        if(k=='A')
                        return;
                        if((k=='1')||(k=='2'))
                        break;
                        }
                        s[0].sec=(k-0x30-1);
                        displays("CHANGES SAVED");
                        _delay_ms(200);
                        }
            else if(k=='2')
                        {
                        displays("ZONE 2\n1.LOW  2.HIGH  ");
                        while(1)
                        {
                        k=key_check(0);
                        beep(1);
                        if(k=='A')
                        return;
                        if((k=='1')||(k=='2'))
                        break;
                        }
                        s[1].sec=(k-0x30-1);
                        displays("CHANGES SAVED");
                        _delay_ms(200);
                        }
            else if(k=='3')
                        {
                        displays("ZONE 3\n1.LOW  2.HIGH  ");
                        while(1)
                        {
                        k=key_check(0);
                        beep(1);
                        if(k=='A')
                        return;
                        if((k=='1')||(k=='2'))
                        break;
                        }
                        s[2].sec=(k-0x30-1);
                        displays("CHANGES SAVED");
                        _delay_ms(200);
                        }
           
            }
           
            else
            {
            displays("RESET PASSWORD\nTYPE 0");
            while(key_check(0)!='0');
            beep(1);
            //k=getpassword();
            k=0;
            while((k=getpassword(2))!=1)
            {
            if(k==2)
            return;
            };
            i=0;
            displays("NEW PASSWORD\n");
            while(i<4)
            {
            k=key_check(0);
            beep(1);
            temp[i]=k;
            lcd_puts("*");
            if((k=='A')||(k=='B') )
            return;
            _delay_ms(200);
            i++;
            }

            temp[i]='\0';
            strcpy(masterpswd,temp);
            displays("PASSWORD CHANGED");
            _delay_ms(300);
            }
}


void stop()
{
beep(1);
displays("DEACTIVATED");
PORTB=0x0C;  // safe indication + int
PORTD=0x0F;
_delay_ms(200);
}

void beep(int n)
{
int i=0;
while(i<(2*n))
{
PORTD ^= 0x80;
_delay_ms(100);
i++;

}
PORTD=0x0F;
}





int main(void)
{
DDRC=0xF0;
DDRD=0xF2;
DDRB=0xFB;
PORTB=0x0C;
PORTD=0x0F;
disjtag();
lcd_init(LCD_DISP_ON_CURSOR); /* initialize lcd, display on, cursor on for more options lcd_init(), view lcd.h file */lcd_init(LCD_DISP_ON_CURSOR); /* initialize lcd, display on, cursor on for more options lcd_init(), view lcd.h file */
lcd_home();  
lcd_clrscr();
adcinit();
setupint();
sei();
char x[3]="a",key='c';
s[0].zone=1;
s[1].zone=2;
s[2].zone=3;
s[0].sec=0;
s[1].sec=0;
s[2].sec=1;



beep(1);
bootup();
beep(1);
//timer_start();

while(1)                      /* run continuously */
    {
            ss();     
            checktemp();
            key=key_check(1);
            if((key<='9')&&(key>='0'))
            {
            beep(1);
            menu();
            }
            }
}


ISR(INT0_vect)
            {
            initiate(s[0]);
            while(key_check(1)=='A');
            while(!getpassword(1));
            stop();
            }
           


ISR(INT1_vect)
            {
            initiate(s[1]);
            while(key_check(1)=='A');
            while(!getpassword(1));
            stop();
            }
           


ISR(INT2_vect)
            {
            initiate(s[2]);
            while(key_check(1)=='A');
            while(!getpassword(1));
            stop();
            }
           
ISR ( TIMER1_OVF_vect )
{
TCNT1=40000;
if(tempstat==1)
PORTD|=(1<<5);
else
{
//PORTD &= ~(1<<5);
PORTB^=0x80;
 }
}
           






No comments:

Post a Comment