DogusLogo

 

 

T.C. DOĞUŞ UNIVERSITY

ENGINEERING FACULTY

DEPARTMENT OF COMPUTER ENGINEERING

COME 492

Project-2

Project Name

Home Security System with PC

Erdinc AYDIN

 

Advisor : Assist. Prof. Dr. Dilek TÜKEL

 


 

Preface

 

 

This thesis is based upon studies during October 2009 to February 2010 at the Department of Computer Engineering, Doğuş University, Istanbul. In the project microcontrollers, pc and cell phone is used.

 

I would like to express my sincere gratitude to my leading supervisor Associate Professor Dilek TÜKEL for his advice and unique support to this thesis. 

 

 

 

 

Istanbul, February 2010                                                                    Erdinç AYDIN

                                                                                                              200531018

                                                                      


 

Abstract

In this thesis, a home security system is describes and discussed which is developed by Erdinc AYDIN as graduation project of Dogus University in 2010. In the project microcontrollers based panels created and this report includes every component and module with combine of them to create panels.

This report includes AT Commands to drive a cell phone, CCS codes and connections of modules and C# Program to create Home Security System

 Also in the report there are lots of picture of system when they are working. A user manuel is included too.

Özet

 

Tez Erdinç AYDIN tarafından Dogus Universitesi için bitirme projesi olarak gelişmiş olan  ev güvenlik sistemini anlatıyor ve açıklıyor. Projede mikrodenetleyici tabanlı olarak geliştirilmiş paneller yaratıldı ve bu raporda her bileşen ve modül ve onların birbirleri ile yeni bileşen yaratmasını içeriyor.

Bu rapor, AT Komutları ile bir telefonu sürme, CCS kodları ile modullerin bağlantıları ve C# Programının ev güvenlik sistemini yaratmasını içeriyor.

Ayrıca raporda sistem çalışır halde iken sistemin bir çok resimi var. Kullanım klavuzunu da ayrıca rapor içeriyor.


 

Table of Contents

Preface. i

Abstract ii

Özet ii

1.      INTRODUCTOIN.. 1

1.1.       Why Security System Is Needed. 1

1.2.       Where System is Useful 1

1.3.       How System Works. 2

1.3.1.        Main Operations. 2

2.      COMPONENTS AND MODULES OF THE SYSTEM... 4

2.1.       RF Module. 4

2.1.1.        RF Receiver 4

2.1.2.        RF Transmitter 5

2.1.3.        Antenna. 5

2.2.       LCD Module  (2x16) 7

2.2.1.        CCS-C Codes for LCD.. 9

2.3.       MAX232. 11

2.4.       7805 Voltage Regulator 12

2.5.       Led. 12

2.6.       Keypad 4x4. 14

2.6.1.        CCS-C Code of Keypad. 15

2.7.       PIC Programmer 16

2.8.       PIC16F628A Microcontroller 20

2.9.       PIC16F877A Microcontroller 21

2.10.         Timers of PICs. 22

2.11.         ICSP/In-Circuit Serial Programming. 23

2.12.         Detectors. 24

2.13.         Relay. 25

3.      PANELS & SOFTWARES. 26

3.1.       RS-232 Panel 26

3.2.       Main Panel 27

3.3.       Door Panel 28

3.4.       Cell Phone - AT Commands – Connections for Cell Phone. 29

4.      HOW TO USE HOMESECURITY SYSTEM... 35

4.1.       Connections of Components. 35

4.2.       C# Program.. 36

4.2.1.        Log In Screen. 36

4.2.2.        Main Screen. 37

4.2.3.        Options Form.. 41

4.2.4.        Log Screen. 45

4.2.5.        New Design Form.. 46

4.3.       Web Site. 48

4.3.1.        Main Page of Web Site. 48

4.3.2.        Log In Page of Web Site. 49

4.3.3.        Detector Page of Web Site. 50

4.3.4.        About Page of Web Site. 51

4.3.5.        Log Out Page of Web Site. 51

4.4.       Using Main Panel 52

4.5.       Using Door Panel 54

4.6.       A Quick Set Up. 55

5.      CONCLUSION.. 56

6.      BIBLOGRAPHY.. 57

7.      BIOGRAPHY.. 58

 

 


 

Table of Figures

1.3.1‑1 Figure Main Panel Algorithm.. 3

1.3.1‑2 Figure Door Panel Algorithm.. 3

2.1.1‑1 Figure RF Receiver 4

2.1.2‑1 Figure RF Transiver 5

2.1.2‑2 Figure RF Protocol 5

2.2‑1 Figure (DataSheet ABC016002E) 7

2.2.1‑1 Figure LCD Module. 9

2.3‑1 Figure (MAX232 Serial level converter, 2007) 11

2.4‑1Figure 7805. 12

2.5‑1 Figure Led. 12

2.5‑2 Figure Led Connection. 13

2.6‑1 Figure Keypad. 14

2.6‑2 Figure Real Keypad. 14

2.6.1‑1 Figure Keypad Conn. 15

2.7‑1 Figure PIC Programmer 16

2.7‑2 Figure   PIC Programmer 17

2.7‑3 Figure PIC Programmer 17

2.7‑4 Figure PIC Programmer Progam.. 17

2.7‑5 Figure PIC Programmer Progam II. 18

2.7‑6 Figure PIC Programmer Progam III. 18

2.7‑7 Figure PIC Programmer Progam IV.. 19

2.7‑8 Figure PIC Programmer Progam V.. 19

2.8‑1 Figure PIC16F67A.. 20

2.9‑1 Figure PIC16F877A.. 21

2.9‑2 Figure Oscillator Crystal 21

2.11‑1Figure ICSP. 23

2.12‑1 Figure PIR Detector 24

2.13‑1 Figure Relay Conn. 25

3.1‑1 Figure RS-232 Panel 26

3.2‑1 Figure Main Panel 27

3.3‑1 Figure Door Panel 28

3.4‑1 Figure AT with Bloutooth. 33

3.4‑2 Figure AT Conn. 33

3.4‑3 Figure AT Test 34

4.1‑1 Figure RS-232 Conn. 35

4.2.1‑1 Figure Log In. 36

4.2.2‑1 Figure Main Screen I. 37

4.2.2‑2 Figure Main Screen II. 38

4.2.2‑3 Figure Main Screen III. 38

4.2.2‑4 Figure Main Screen IV.. 39

4.2.2‑5 Figure Main Screen V.. 39

4.2.2‑6 Figure Main Panel 40

4.2.3‑1 Figure Options Screen I. 41

4.2.3‑2 Figure Options Screen II. 42

4.2.3‑3 Figure Options Screen III. 43

4.2.4‑1 Figure Logs I. 45

4.2.4‑2 Figure Logs II. 45

4.2.5‑1 Figure New Design I. 46

4.2.5‑2 Figure New Design II. 47

4.3.1‑1 Figure Main Web Page. 48

4.3.2‑1 Figure Log In Web Page. 49

4.3.3‑1 Figure Detector Web Page. 50

4.3.4‑1 Figure Log In Screen. 51

4.3.5‑1 Figure Log Out Screen. 51

4.4‑1 Figure Main Panel 52

4.4‑2 Figure Main Panel II. 53

4.4‑3 Figure Keypad. 53

4.5‑1 Figure Door Panel 54

4.6‑1 Figure Quick Setup. 55

 


 


1.                INTRODUCTOIN

 

This project is home security system with microcontroller and computer. There is two panel and one computer connection module. Main panel controls all detectors and all detectors are connected to this main panel. Door panel is to activate and deactivate security system outside of house.  To communicate with computer RF (Radio Frequency) is needed. To detect a burglar or fire\smoke\gas detectors are used. If a system detects an alarm PC updates web site so if owner is not in the home they can see state of house. Computer sends a SMS to inform owners when an alarm detected too. Users can close Security System from SMS, outdoor panel and main panel.

1.1.         Why Security System Is Needed

 

This security system is for detection and informing user and any close neighbors who can hear beeps. This system can detect any threats like burglar, fire, carbon monoxide, water flood, smoke etc. Actually it can detect any threat if there is a detector which has relay connection. More on relay will be discussed later.  This system can be used when users is in the home or when they are not. Motion detectors (PIR) shouldn’t be used when owners are at home. But other detectors can be used any time.

1.2.         Where System is Useful

This system is developed for home security; in offices this system can be not effective as much as house. Efficiency of system is depend on used detectors, better detectors gives better results. This system is used for detecting threats not for preventing or protection from threats but can provide protection against burglars. So users will protect house actually. System uses RF communication so it has pros and cons of wireless communication. Provides less cable pollution but not secure as much as cable. This system will not inform police, ambulance or fire department.

1.3.         How System Works

 

There are 3 components; outdoor panel, main panel and computer connection module. To make system work all of components must be working properly. Otherwise system cannot be used.

1.3.1. Main Operations

 

Outdoor panel is used to activate and deactivate security system with password. Password is not checked by outdoor panel. Password is sent to main panel, main panel checks if password is correct or not. If password is correct then main panel skips all signals from detectors and sends signal to door panel and computer to inform security system is deactivated. If password is not correct then main panel sends signal to computer to log this event. (1.3.1‑2 Figure)

Main panel controls whole system and gives update to computer and door panel. All detectors are connected to main system and searched for alarm state for all connected detectors by this panel. Main panel triggers buzzer to give alarm to neighbors too. Every closing or opening for a detector or whole system can be controlled by this panel. So every detector can be activated or deactivated with not changing state of other detectors. System can be deactivated with password in main panel or door panel and with computer.

Computer has a C# program to control website, logging and sending signals to main panel according to user wishes. C# program has same password with main panel and controlled by main panel if password is right or not. Main panel sends information about state of house to computer and computer logs this information. If something is wrong, this will be written in logs and showed in website. Computer has to have a module to give signals to main panel.


With SMS sending, system can be activated or deactivated too. Every phone cannot do that. Phone number should be in the C# program as a security precaution. It will be discussed later how cell phones can be used to control system.

All communication is provided with RF (Radio Frequency at 433 MHz). That’s why this system is a wireless system. Main panel, door panel and computer communicate with RF communication. Walls and some solid objects can decrease signal strength, System should be tested before using. According to sources there should be no problem in a house for signal strength. But it is important to use right antenna for more effective signal strength. Later that will be discussed


1.                   

1.3.11 Figure Main Panel Algorithm

When an alarm detected system, main panel triggers buzzers to warning neighbors and anyone who can hear buzzer. Then main panel sends signal to computer, computer understands message and sends SMS to owner of the house then updates C# program status and the website. Alarm mod is logged by C# program with date and hour.  After a while main panel shuts buzzers and stays in alarm mod. Alarm mod can be terminated by SMS, C# program or door and main panel with password. (1.3.1‑1 Figure )

 

1.3.12 Figure Door Panel Algorithm

2.                COMPONENTS AND MODULES OF THE SYSTEM

There is lots of module and components used in this security system. This report will give some information about these components and modules. Cables, capacitors, resistors will just be ignored in this report.

2.1.         RF Module

Radio frequency (RF) radiation is a subset of electromagnetic radiation with a wavelength of 100km to 1mm, which is a frequency of 300 Hz to 3000 GHz, respectively. This range of electromagnetic radiation constitutes the radio spectrum and corresponds to the frequency of alternating current electrical signals used to produce and detect radio waves. ((Radio frequency, 2010)  http://en.wikipedia.org/wiki/Radio_frequency)

In this project, UDEA ATX-34 is used as transmitter and ARX-34 is used as receiver. There are a lot more RF modules in market but this module is the simplest to find and this module is cheaper than others.

2.1.1.  RF Receiver

These modules work at 433.920 MHz and minimum 300 bps, maximum 2400 bps. They work with 5 Volt and 5 mA. Output (Audio) pin (in 2.1‑1 Figure) is used to test chip according to datasheet of ARX-34. An external antenna should be connected to get more strong RF signals. Antenna connection requires DC +5V and Ground connection and antenna should be connected with 50-Ohm Coax antenna. Size of Receiver is given blow in figure 2.1.1‑1 Figure. Digital output is used to get RF signals from this receiver.

2.1.11 Figure RF Receiver

Size of the RF receiver is not too small. It has a size of 3 times of transmitter. UDEA has same RF module with different types.  One which has crystal is safer other can have frequency shifts but it doesn’t happen so much.


 

2.1.2. RF Transmitter

These modules work at 433.920 MHz and minimum 300 bps, maximum 2400 bps. They work with 5 Volt and 5 mA. Digital input is used for giving RF signals to transmitter to spread RF signals to the air. An external antenna should be connected to get more strong RF signals. Antenna connection requires DC +5V and Ground connection and antenna should be connected with 50-Ohm Coax antenna. Size of Transmitter is given blow in 2.1.2‑1 Figure. Digital output is used to get RF signals from this receiver.

2.1.21 Figure RF Transiver

UDEA has same RF module with different types.  One which has crystal is safer other can have frequency shifts but it doesn’t happen so much. Some Transmitter modules get ground with two different pin.

To transmit RF signals accouring to datasheet, a protocol should be followed. Firstly preable should be send then secron and all data without any pause. In this project followed protocol given blow.

2.1.22 Figure RF Protocol

2.1.3. Antenna

Antenna should be 17.3 cm for 433 MHz and should be connected with 50-Ohm Coax antenna. Antenna is not a must but it is required to work on a long distance.  Accourding to reasearches, This system works in 200-250 m distance with a correct antenna.


 

CCS Code Of Transmitter

void setRFString(char *str )

{

   int curlen=0;

   for(x=0;x<5;x++)  // Make Preamble

         fputc('U',RF);

   for(x=0;x<5;x++)  // Make Sencron

     fputc(0xFF,RF);

   for(curlen = 0;curlen < (charlen-1) && *(str + curlen)  ;curlen++ )

   {

      fputc(*(str + curlen),RF) ;

   }

   fputc(0x00,RF);

}

CCS Code Of Reciever

 

 

void getRFString(char  *str )

{

   char ch;

   int curlen;

   if(getc(RF) == 'U' && getc(RF) == 'U' && getc(RF) == 'U'&& getc(RF) == 'U' && getc(RF) == 'U' &&

   getc(RF) == 0xFF && getc(RF) == 0xFF && getc(RF) == 0xFF && getc(RF) == 0xFF && getc(RF) == 0xFF)

   {

      ch = getc(RF);

      for(curlen = 0; curlen < (charlen-1) && ch ; curlen++)

      {      

         *(str+curlen) = ch;

         ch = getc(RF);

      }

 

      *(str+curlen) =0; // Last byte of array must be 0 

   }

   else

      *str =0;

}

2.2.         LCD Module  (2x16)

These LCD (Liquid Crystal Display) Module is used to inform user with charactrers. Every character formed with 5x7 matrix. All ASCII characters are installed in module in the manufacturing. But manufacturers let users to design few special characters and keep them in the LCD Module too. There are lots of LCD module 2x8, 1x16, 2x16, 4x20, GLCD (Graphical LCD). GLCDs can create graphs too as well as characters. In this project, LCD 2x16 module is used.

 

2.21 Figure (DataSheet ABC016002E)

http://www.av-display.com.cn/en/Products_show.aspx?NOID=1013

 

Programming LCD is a standard, there are some differences with times but it is possible to wait more and use same program with all of LCD modules. Program can be written for 8-bit or 4-bit. If 4-bit is used then it takes twice as more time as compared to 8-bit mode but uses 4-bit less than 8-bit. CCS-C has a class to program these modules “LCD.c”. It uses port B as defaults and support 4 bit programming.

LEDA and LEDK are used for background light, LEDA is 5V and LEDK is Ground. Backlight makes easy to read characters. VSS is ground and VDD is 5V for logic of LCD module. Vo is used to give current for 5x7 matrixes (VDD –Vo). It can be controlled with a potentiometer (controllable resistor).  


 

 

The three control lines are referred to as EN, RS, and RW.

The EN (Enable) control line is used to tell the LCD that you are sending it data. To send data EN must be LOW. When data and other control bits are ready, EN should rise to high and wait for the minimum amount of time required by the LCD datasheet, then make EN LOW again to indicate command ended.

The RS (Register Select) line is low when data is to be treated as a command. When RS is high, data is taken to display on the module.

When RW (Read/Write) control line is low, the information on the data bus is being written to the LCD. When RW is high, data is taken as reading command like Get LCD status (Busy flag) is a read command. It is possible to read what is written in the LCD too but this project doesn’t use this function of the LCD module.

The eight data lines are referred to as DB0, DB1, DB2, DB3, DB4, DB5, DB6, and DB7.

In eight-bit programming all data lines are used to write to LCD and give commands. If four-bit programming is used than DB0, DB1, DB2, DB3 are used. Other bits are free and not used.

Pin

Function

Vss

Ground

Vdd

Supply Voltage

Vo

Contrast Setting

RS

Register Select

R/W

Read/Write Select

En

Chip Enable Signal

DB0-DB7

Data Lines

A/Vee

Gnd for the backlight

K

Vcc for backlight

2.21 Table LCD Table

 

If LCD is working then user should see Squares (high in all of the matrixes) before programming. This means logic part is working and if you see every dot in the matrixes then LCD screen works perfectly too. If user doesn’t see dots, it can be broken or Contrast is low. User should check Vo with potentiometer. In this project microcontroller programs LCD module before human eyes see. So no one can see squares. They see welcome screen of the program.


 

2.2.1.                       CCS-C Codes for LCD

CCS-C has a class to control LCD modules to drive 2x16 LCD module lcd.c should be included or programmer should write manually. To use lcd.c class see codes blow.

 

#use delay(clock=4000000)

#define use_portb_lcd true

#include <lcd.c>

printf(lcd_putc,"\f     Erdinc     AYDIN");

2.2.11 Figure LCD Module

In this project, a structure and timer is used to control LCD screen too. Structure keeps text which will be displayed and status is this new text or old (which means it is already being showed).  

In Main:

enable_interrupts(INT_TIMER1);  //Timer1 kesmesi aktif

 enable_interrupts(GLOBAL);

 

#int_timer1

void  TIMER1_isr(VOID)

{

disable_interrupts(int_timer1);

 

   timer_multiply++;

    

      displayToLCD();

 

    enable_interrupts(int_timer1);

}

 


 

 

void displayToLCD()

{

   char l1[16];

   char l2[16];

   int curlen;

   int lineLen1;

   int lineLen2;

  

   lineLen1=strlen(lcdScreen.line1);

   lineLen2=strlen(lcdScreen.line2);

  

   // Find Line1 to display

   if( lineLen1>lcdLen)

   {

       

      for(curlen = 0; curlen < lcdLen ; curlen++)

      {

        if(*(lcdScreen.line1+(curlen+lcdScreen.curline1)%lineLen1) == "\0")

         continue;

        

        l1[curlen]= *(lcdScreen.line1+((curlen+lcdScreen.curline1)%lineLen1));

      }

      lcdScreen.curline1=(lcdScreen.curline1+1)%lineLen1;

   }

   else

      stringFromPointer(lcdScreen.line1,l1);

     

   // Find Line2 to display

   if(lineLen2 >lcdLen)

   {

       

      for(curlen = 0; curlen < lcdLen ; curlen++)

      {

        if(*(lcdScreen.line2+((curlen+lcdScreen.curline2)%lineLen2)) == "\0")

         continue;

        

        l2[curlen]= *(lcdScreen.line2+((curlen+lcdScreen.curline2)%lineLen2));

      }

      lcdScreen.curline2=(lcdScreen.curline2+1)%lineLen2;

   }

   else

      stringFromPointer(lcdScreen.line2,l2);

  

   printf(lcd_putc,"\f%s\n%s",l1,l2 );

}

2.3.         MAX232

MAX232 is used to convert voltage level of RS232 to TTL level. This chip can deal with two RS232 at the same time. It not just convert to TTL level, it can produce voltage which RS232 can understand from TTL level. This chip only needs an external 5V supply and can provide 12 V level from the 5 voltage. In some source it is written that RS232 can be used to get voltage for MAX232 (VCC). But RS232 is not designed to get voltage from.

max 232 circuit

2.31 Figure (MAX232 Serial level converter, 2007)

RS232 can be get from computer or other devices like other microcontrollers. In the DE-9 connector only 3 pin is used to provide communication (2nd, 3rd and 5th pin).

·         5th pin is the ground of RS232 and must be connected to ground of the external voltage source.

·         14th pin of MAX232 should be connected to 2nd pin of DE-9 which is Receiver for DE-9. If first channel is going to be used.  

·         13th pin of MAX232 should be connected to 3rd pin of DE-9 which is Transmitter for DE-9. If first channel is going to be used.  

·         11th pin of MAX232 should be connected to TX pin of microcontroller which is Transmitter for microcontroller. If first channel is going to be used.  

·         12th pin of MAX232 should be connected to RX pin of microcontroller which is Receiver for microcontroller. If first channel is going to be used.  

·         7th pin of MAX232 should be connected to 2nd pin of DE-9 which is Receiver for DE-9. If second channel is going to be used.  

·         8th pin of MAX232 should be connected to 3rd pin of DE-9 which is Transmitter for DE-9. If second channel is going to be used.  

·         10th pin of MAX232 should be connected to TX pin of microcontroller which is Transmitter for microcontroller. If second channel is going to be used.  

·         9th pin of MAX232 should be connected to RX pin of microcontroller which is Receiver for microcontroller. If second channel is going to be used.  


 

2.4.         7805 Voltage Regulator

7805 & 78L05 is used to drop voltage to 5 volt. Both have three pins Input, Com and Output. In The input, voltage source which will be regulated must be connected and ground of source must be connected to COM pin of 7805. Input should be bigger than 7,5V and smaller than 16V to get 5V as output. Ground of the regulated and original voltage source is same.

2.41Figure 7805

In the internet, there are lots of connection scheme even the straight connections are exits without any capacitors or resistors. But figure above is efficient and works. For input a 470µF capacitor and in the output 100nF capacitor are used. COM can be connected without and capacitors. It is possible to create a circuit with just resistors too.  

2.5.         Led

It can be seen easy to connect a led but it is important to use right resistor otherwise led can burn faster than it can stand. In this part of report, led will not be discussed. Led resistor calculation will be explained.

               2.51 Figure Led


 

Formula 2.51 Led

VS = Supplied Voltage

VL = LED voltage can be 2- 4 V

I = LED current which should be less than max current supported

Vs can be raised with connecting serial led to each other. It is possible to save Vs with parallel connections with more led but it is not recommended. If it is necessary to make parallel connections with led, it is important to use identical leds and use resistors for each parallel connection.

2.52 Figure Led Connection

 

Type

Colour

IF
max.

VF
typ.

VF
max.

VR
max.

Luminous
intensity

Viewing
angle

Wave length

Standard

Red

30mA

1.7V

2.1V

5V

5mcd @ 10mA

60°

660nm

Standard

Bright red

30mA

2.0V

2.5V

5V

80mcd @ 10mA

60°

625nm

Standard

Yellow

30mA

2.1V

2.5V

5V

32mcd @ 10mA

60°

590nm

Standard

Green

25mA

2.2V

2.5V

5V

32mcd @ 10mA

60°

565nm

High intensity

Blue

30mA

4.5V

5.5V

5V

60mcd @ 20mA

50°

430nm

Super bright

Red

30mA

1.85V

2.5V

5V

500mcd @ 20mA

60°

660nm

Low current

Red

30mA

1.7V

2.0V

5V

5mcd @ 2mA

60°

625nm

2.51 Table

(Hewes, 2009)


 

2.6.         Keypad 4x4

4x4 keypad has 16 keys on it; keypads are made up with just buttons and cables so they are very simple for manufacturing. But they need program to be written and CCS-C doesn’t have a written class for keypad. All keypads can be different as buttons and size. Keypad which is used in the project showed in 2.6‑1 Figure. It is really important to know that every keypad can have different connections. Keypad in 2.6‑1 Figure  shows keypad connection for this project and in 2.6‑2 Figure you can see keypad which is used. That keypad has a very low thickness.

2.61 Figure Keypad

In the connection it is important to use resistors because generally keypads don’t have internal resistors because voltage source can be different or a different program can be used. That’s why if circuit needs resistors, resistors should be connected externally. In this project, 4,7K resistors are used. Circuit and the code of the CCS-C program is showed blow.

2.62 Figure Real Keypad


2.6.1. CCS-C Code of Keypad

2.6.11 Figure Keypad Conn

   for( row=0; row<colNo; row++ )

     {

          PORTB= RowTable[row];

         if( input(col4) == 1  )

          {           while(input(col4) == 1);

              return KeyTable[3 + row*rowNo];

          } 

          else if( input(col3) == 1 )

          {          while(input(col3) == 1);

              return KeyTable[2 + row*rowNo];

          }

          else if( input(col2) == 1  )    

          {          while(input(col2) == 1);

              return KeyTable[1 + row*rowNo];

          }

          else if(  input(col1) == 1 )

          {             while(input(col1) == 1);

              return KeyTable[0 + row*rowNo];

          }

     }      return 0;

2.7.         PIC Programmer

PIC programmer is used to burn program into microcontroller. There are some which use serial port and some which use USB to communicate with computer. Every programmer has its properties and instructions. These programmers are created with a microcontroller and some component so they can be produce by everyone. They need a software and firmware to get them work.

http://www.mehmetyildiz.com/gittigidiyor/DSCI0647%20(Large).JPG

2.71 Figure PIC Programmer

 In the computer program it is possible to configure pic and it is possible to get configurations from .hex files. Hex file should be generated with another program like CCS-C. That program lets to burned hex file to save to computer too. But this program is special for that programmer and can change from one to another.

 

This PIC Programmer also has ICSP/In-Circuit Serial Programming property, which gives programmer to program a PIC in the circuit without removing microcontroller. For PICs which has 40 pins, it is too hard to remove and it is dangerous for chip too. That’s why ICSP is really important.


 

 

To start programming firstly, programmer have to connect PIC Programmer in the USB port then s/he should start computer program. If not, it is possible to detect PIC Programmer with DETECT PROGRAMMER button.

After detecting PIC Programmer PIC should be identified to realize this PIC should be placed correctly.

 

2.72 Figure    PIC Programmer                   

2.73 Figure PIC Programmer

 

Then family and pin numbers should be selected (example = 16Fxxx family, 40 PIN ). Then identify PIC can be selected and if PIC is identified truly, programming can be started.  If ICSP Programming is going to used, PIC Family should be selected with IC Soket type       “18 Pins/ ICSP”

2.74 Figure PIC Programmer Progam

In the 2.7‑4 Figure, It is seen that hex file is not selected and PIC is not identified. Plus it is seen that Vdd is 5V which is the value needed. In ICSP Vdd is not used but otherwise Vdd is important.

2.75 Figure PIC Programmer Progam II

In the 2.7‑5 Figure, it is seen that PIC is identified and it is PIC16F628A. Vpp voltage is 13V as expected; now program is ready to select and burn a HEX file into PIC16F628A. Other than this, it is possible to erase PIC, compare PIC with selected HEX file and saving HEX in the PIC to local disks.

2.76 Figure PIC Programmer Progam III

In the 2.7‑6 Figure it is seen that how PIC can be configured manually, it is also possible to configure PIC with hex file. If configurations are embedded into HEX file, these configurations will detect automatically by PIC Programmer. Then If any configuration is skipped in HEX file, it can be configured manually.


 

When HEX file is selected in the programmer, Compare, Burn options can be used and hex file can be seen in the computer program of PIC Programmer.

2.77 Figure PIC Programmer Progam IV

In the 2.7‑7 Figure It is seen that all configurations are taken from “LCD.hex” file. These configurations are not editable manually with this PIC Programmer program, but it can be possible with a different one.

2.78 Figure PIC Programmer Progam V

 

In the 2.7‑8 Figure, it is seen that “LCD.hex” file is written into PIC16F2628A successfully and PIC is ready to use.

2.8.         PIC16F628A Microcontroller

This microcontroller is very useful and easy to set up because it doesn’t have any external clock generator. It has internal oscillator crystals with two different options (4 MHz & 37KHz) and 8 total different speeds maximum 20Mhz. It has 18 pins and two byte Input-Output (PortA and PortB). It has three timer modules (timer0, timer1 and timer2) which will be discussed later. It has a USART interrupt from portB which is important for serial communication. In this project, this PIC is not used to get an USART message. This PIC is used to open RF transmitter if a message is received from MAX232 chip.

 

2.81 Figure PIC16F67A

That PIC has EEPROM data which is important because password should be saved in this memory (more on later). 16F628A has a flash of 2048 words to burn program and ram data memory of 224 byte to store temporary variables. These memories are enough for this project. Because this chip is not used as microcontroller of main panel, it just opens RF transceiver. For main and door panel PIC 16F877A is used.

Supported oscillator types of the MCU are:

·         LP       Low Power Crystal

·         XT      Crystal/Resonator

·         HS      High Speed Crystal/Resonator

·         RC      External Resistor/Capacitor (2 modes)

·         INTOSC         Internal Precision Oscillator (2 modes)

·         EC      External Clock In

In this project, INTOSC with 4MHz is used to supply clock for 16F628A.

  

 


 

2.9.         PIC16F877A Microcontroller

This microcontroller has lots of ports (Port A,B,C,D)  this is the first advantage of this PIC. It has 40 pins on it and 33 of them can be used as IO. Port D is used for programming LCD, Port B is used to get key from keypad. Port A and C is used to control RF modules, Leds and detectors. One other advantage is that this PIC has a large memory on it. It has 8K Flash Program Memory. Main panel requires high program memory that’s why this PIC is needed.

2.91 Figure PIC16F877A

To make this PIC work, both power connections (Vdd,Vss) should be connected and MCLR should be connected to Vdd voltage. If reset is going to be used then a resistor should be connected to MCLR to avoid short circuit. This PIC requires an external crystal to get it work. In this project a 40 MHz oscillator crystal is used and two 33pF capacitors are used with this crystal.

      2.92 Figure Oscillator Crystal

PIC16F877A has three timer modules (timer0, timer1 and timer2) which will be discussed later. It has a USART interrupt on PINC7 as receiver and PINC6 as transmitter. This PIC also has Analog-To-Digital module, PWM modules and lots of interrupts which isn’t used in this project.


 

2.10.    Timers of PICs

PICs generally have three timer0, timer1 and timer2 and some of PICs have 4th timer (timer4) too, all of them can create their own interrupts.

Timer0: 0-255 (8 Bit)

Timer1: 0-65535  (16 Bit)

Timer2: 0-255 (8 Bit)

Timer3: 0-65565 (16 Bit)

 

PICS uses 4 clock cycle to instruct a command. This causes instruction time to be fosc/4, fosc is oscillator speed which can be external or internal.

 

Timer0 can counts to 255 and it has 3 bit prescalar so signal (fosc/4) can be divided to 2, 4, 8, 16, 32, 64, 128 or 256. It gives interrupt when value of this timer reaches to 0 (overflow). Timer1 can counts to 65535 and it has 2 bit prescalar which can be divided to 2, 4, 8. A different crystal can be selected and should be connected to T1OSO and T1OSI. Timer2 is generally used to program PWM module, it has settable count time and has no external oscillator option. Timer2 has 2 bit prescalar and 8-bit counter. Lots of PIC doesn’t have a timer3, it can be used as a 8-bit or 16-bit timer and has 2 bit prescalar.

To calculate overflow time, it is needed to know fosc, prescalar and count time.

       2.101 Formula Timer

Let’s see an example, which is also used in this project, to understand better how overflow time can be calculated.

Used oscillator frequency is 20 MHz.

Timer1 is used which means 65536 is count time

Prescalar is 8

 

Which gives us : 65536 * 1/( ( 20 000 000/4) / 8) ) = 0.1049 which means every 0.1049 second, timer1 interrupt will occur.

To get exactly 1 second Timer1 should be used with 32.768 kHz oscillator crystal should be used with prescalar 8. External oscillator will not be divided with 4 like others. This gives:

65536 * 1/( ( 32 768) / 1) ) = 2 (2 second).


 

2.11.     ICSP/In-Circuit Serial Programming

ICSP is used to program a microcontroller without removing microcontroller from its circuit. Legs of PICs get damaged because of removing process and it is harmful to breadboard too. Small PICs like 16f628A can easily be removed from circuit if no cable or component is on the PIC, but bigger PICs like PIC16F877A are too hard to remove from breadboard. Because to test circuit programmer should burn hex file in PICS, It is needed to make lots of burning program in the chip.

 

2.111Figure ICSP

Vdd = +5V (It is not recommended that you use this supply to power your target board.  Current capability is limited.)

Vpp = Programming Voltage (Vpp) - Connect to MCLR/Vpp pin on target device.

PGM Data = Programming Data - Connect to PGD or ICSPDAT on the target PICmicro

PGM Clock = Programming Clock - Connect to PGC or ICSPCLK on the target PIC MCU.

Ground = Ground

Vdd from ICSP module can be used to give power to PIC, but if this pin is connected to all components in the circuit, it is better to use an external power source. But if a external power source is used then it is important to not forget connecting ground of ICSP to ground of power source.

All power pins of PIC should be connected. If an MCLR is used then a diode is important to protect power source.

2.12.    Detectors

Detectors are one of the most important parts of the system. All system acts according to signals which came from detectors. Almost all alarm systems uses same detectors. These detectors are not wireless and has a relay connection on them. In this project, the detectors are working with 7,5 V to 16 V. Because they use 7805 or 78L05 voltage regulator which was discusses before. That means a 9V batter can be used to supply these detectors. Yet, it is not recommended to use a battery because a battery can die without any warning. It is recommended to use an adaptor to supply these detectors. 12V adapter should be ideal to use. When detector is supplied firstly it would give alarm for few seconds and then it starts to do its job. It is possible to see whether a alarm is detected or not with led which is on them and controlled by a jumper. Another jumper controls pulse width too. They also have a tamper switch to detect whether its shutter is removed or not.

 

2.121 Figure PIR Detector

 

In the figure 2.12‑1 Figure, Supply connection must be connected to 12V, Alarm is going to be used to connect to main system. When detector detects a threat two pins of alarm is going to be disconnected by Relay. Tamper works same way when tamper switch is closed but in this project, tamper is not used.


 

2.13.    Relay

In this project, relays are used in every detector and to activate buzzers (siren) because sirens are working with 12V but our circuit works with only 5V. (PS: In the project buzzers are not tested). What is Relays?

A relay is an electrically operated switch. Many relays use an electromagnet to operate a switching mechanism, but other operating principles are also used. Relays find applications where it is necessary to control a circuit by a low-power signal, or where several circuits must be controlled by one signal. The first relays were used in long distance telegraph circuits, repeating the signal coming in from one circuit and re-transmitting it to another. Relays found extensive use in telephone exchanges and early computers to perform logical operations. A type of relay that can handle the high power required to directly drive an electric motor is called a contactor. Solid-state relays control power circuits with no moving parts, instead using a semiconductor device to perform switching. Relays with calibrated operating characteristics and sometimes multiple operating coils are used to protect electrical circuits from overload or faults; in modern electric power systems these functions are performed by digital instruments still called "protection relays". (Relay, 2009) http://en.wikipedia.org/wiki/Relay

When high signal comes to base of transistor, current can flow from collector to emitter and this magnetizes coil which leads to switch C to NO. That was common is loaded with voltage of NO. ( see 2.13‑1 Figure )

2.131 Figure Relay Conn

 


3.                PANELS & SOFTWARES

That system requires a cell phone, 3 panel of the system, 2 serial port or converter to serial port.  In this section it will be discussed what are they and how can they be used?

3.1.         RS-232 Panel

RS-232 Panel is used to get and send RF messages to computer via serial port on the computer. This panel firstly uses a voltage regulator 7805 to reduce voltage from 7.5-16 to 5 volt. Then with MAX232 chip it gets signals from serial port of the computer and converts them to TTL voltage level and gets signal from RF Receiver then converts them to a voltage level which is around 12 V for computer.

3.11 Figure RS-232 Panel

In this panel PIC16F628A is used to open and close RF transmitter. Because RF Transmitter affects RF receiver to get other Transmitters signal. That’s why transmitter just should be open when a signal wanted to send. PIC16F628A scans signals of MAX232 to find a signal which is aimed to send with RF. When it finds the signal, PIC supply RF transmitter and signal can be sent.

But RF receiver doesn’t need a PIC, at the moment a signal comes, it sends to MAX232 to send signal to serial port to use in C# program.

LED1 is used to indicate whether a signal is sending with RF or not.

LED2 is used to indicate whether this panel is working or not.


 

3.2.          Main Panel

Actually all system is controlled by this panel, every detector is connected to this panel. All password checking, detector or alarm closing and opening event are done by this panel. This panel should be inside of the house and close to detectors because all detectors have to be connected to this panel with cable.

Again this panel firstly uses a voltage regulator 7805 to reduce voltage from 7.5-16 to 5 volt. It is highly recommended to use an adaptor with 12V instead of a battery. This system requires a high current level that’s why batteries can die very fast.

In the panel, there is a potentiometer to increase or decrease contrast of the LCD screen. Backlight is enabled and it works with high power for a battery, that’s a good reason to use an adaptor.

3.21 Figure Main Panel

 

There is a two colour led which indicates is system active or deactive. If system is active colour of the led will be red, if system is deactive colour will be green.

Other led is used to show a message is sending to other panels. When a RF message needs to be send, LED2 is going to be on and RF Transiver is going to be supplied.


 

3.3.         Door Panel

This panel is shows is system is active or not active and users can close and open alarm system with system password. Password will be sent main panel and if main panel approves password, system can be closed or opened according to sent signal from door panel.

Again this panel firstly uses a voltage regulator 7805 to reduce voltage from 7.5-16 to 5 volt. It is highly recommended to use an adaptor with 12V instead of a battery. This system requires a high current level just like main panel that’s why batteries can die very fast.

Just like main panel there is a potentiometer to increase or decrease contrast of the LCD screen. Backlight is enabled too.

3.31 Figure Door Panel

There is a two colour led which indicates is system active or deactive. If system is active colour of the led will be red, if system is deactive colour will be green. To decide is system is active or not PIC listens to RF signals and switches LED and writes in the LCD Module.

Other led is used to show a message is sending to other panels. When a RF message needs to be send, LED2 is going to be on and RF Transiver is going to be supplied.


 

3.4.         Cell Phone - AT Commands – Connections for Cell Phone

In 1977, Dennis Hayes developed a specific command-language to communicate with  his smartmodem 300 baud modem with the single RS232 communication channel to the attached computer to transfer both control commands and data. Every command has started with AT which is first 2 letter of attention. Today these codes improved and embedded to most of modem, fax, and cell phones.  Now, it is possible to read and send SMS with just using AT Commands and a cell phone or a modem. But a disadvantage is that every manufacturer can use different commands and give support to at commands they want. So it is not guaranteed that a command which worked in one system is going to work in others. For example some phones lets to use AT Commands to use reading SMS and reading telephone addresses in the cell phone but Nokia N70, N95 and lots of other don’t let that.

Here Some Examples :

Dialing a number : ATD+00901234567;

Sending SMS :

>>       AT+CMGF=1

OK

>>       AT+CMGS="7789952010"

>>       > Hello World <Ctrl>+<Z>

OK

Here <Ctrl>+<Z> is a key combination to  end writing message

 

There are few AT Commands given by Nokia:

Call Control

 

Command       Description

ATA     Answer command

ATD    Dial command

ATH    Hang up call

ATL     Monitor speaker loudness

ATM    Monitor speaker mode

ATO    Go on-line

ATP     Set pulse dial as default

ATT     Set tone dial as default

AT+CSTA       Select type of address

AT+CRC        Cellular result codes


 

Data card control commands

 

Command       Description

ATI      Identification

ATS     Select an S-register

ATZ     Recall stored profile

AT&F  Restore factory settings

AT&V  View active configuration

AT&W Store parameters in given profile

AT&Y  Select Set as powerup option

AT+CLCK      Facility lock command

AT+COLP      Connected line identification presentation

AT+GCAP     Request complete capabilities list

AT+GMI         Request manufacturer identification

AT+GMM       Request model identification

AT+GMR       Request revision identification

AT+GSN        Request product serial number identification (IMEI)

Phone control commands

 

Command       Description

AT+CBC        Battery charge

AT+CGMI      Request manufacturer identification

AT+CGMM    Request model identification

AT+CGMR     Request revision identification

AT+CGSN      Request product serial number identification

AT+CMEE     Report mobile equipment error

AT+CPAS      Phone activity status

AT+CPBF      Find phone book entries

AT+CPBR      Read phone book entry

AT+CPBS      Select phone book memory storage

AT+CPBW     Write phone book entry

AT+CSCS       Select TE character set

AT+CSQ        Signal quality


 

Computer data card interface commands

 

Command       Description

ATE     Command Echo

ATQ    Result code suppression

ATV     Define response format

ATX     Response range selection

AT&C Define DCD usage

AT&D Define DTR usage

AT&K Select flow control

AT&Q Define communications mode option

AT&S  Define DSR option

AT+ICF          DTE-DCE character framing

AT+IFC          DTE-DCE Local flow control

AT+IPR          Fixed DTE rate

 

Service

 

Command       Description

AT+CLIP       Calling line identification presentation

AT+CR           Service reporting control

AT+DR           Data compression reporting

AT+ILRR        DTE-DCE local rate reporting

 

Network communication parameter commands

 

Command       Description

ATB     Communications standard option

AT+CBST       Select bearer service type

AT+CEER      Extended error report

AT+CRLP      Radio link protocol

AT+DS           Data compression


 

Miscellaneous commands

 

Command       Description

A/        Re-execute command line

AT?     Command help

AT*C  Start SMS interpreter

AT*T   Enter SMS block mode protocol

AT*V   Activate V.25bis mode

AT*NOKIATEST       Test command

AT+CESP      Enter SMS block mode protocol

 

SMS commands

 

SMS text mode

 

Command       Description

AT+CSMS      Select message service

AT+CPMS      Preferred message storage

AT+CMGF     Message format

AT+CSCA      Service centre address

AT+CSMP      Set text mode parameters

AT+CSDH     Show text mode parameters

AT+CSCB      Select cell broadcast message types

AT+CSAS       Save settings

AT+CRES      Restore settings

AT+CNMI      New message indications to TE

AT+CMGL     List messages

AT+CMGR     Read message

AT+CMGS     Send message

AT+CMSS      Send message from storage

AT+CMGW    Write message to memory

AT+CMGD    Delete message

(Wiki, 2010) http://wiki.forum.nokia.com/index.php/AT_Commands


 

Testing AT Command with HyperTerminal

HyperTerminal is the simplest way to make serial communication but unfortunately this program is no longer a windows default component (Windows Vista & Windows 7). But there is a simple solution for this, copy two files hypertrm.dll and hypertrm.exe from Windows XP machine to your target machine Windows Vista or Windows 7. Now just click to hypertrm.exe and it is ready to use.

Firstly, it is needed to get a physical channel with device to make serial communication. It can be via a RS232 to serial port of computer or a Dial-up Networking (DUN) via Bluetooth. Then it should be seen in Device Management or Bluetooth properties as a COMX port.

3.41 Figure AT with Bloutooth

Use HyperTerminal to communicate with that serial port.

3.42 Figure AT Conn


 

Now it is ready to use. If it returns “OK” message to users “AT” message connection is established and device supports AT Commands.

3.43 Figure AT Test

In this project, phone needs to support AT Commands for reading SMS and sending SMS. Samsung X160 is tested via a RS-232 cable. But it is possible to use other cell phones too. RS-232 cable is recommended but Bluetooth is also possible to use.

In the project, C# program takes care of reading SMS to search for a Home Security System Code and takes action according to that code. If an alarm is given, C# program sends SMS to all recorded cell phones.

It is important to use a phone with SMS reading support with AT commands, otherwise C# program is not going to work expectedly. That’s why firstly cell phone should be tested with a SMS reading program with AT command or simply HyperTerminal program. After doing everything above, see below to test AT Command SMS reading.

AT Command to Reed SMS

Set to text mode firstly:

v  AT+CMGF=1

That code reeds all SMS in the selected memory.

v  AT+CMGL="ALL"

That code reeds first SMS to 20th SMS in the selected memory.

v  AT+CMGR=1,20


 

4.                HOW TO USE HOMESECURITY SYSTEM

To make system work, 2 panels is critical (RS-232 Panel & Main Panel). Third panel (Door Panel) is optional. Cell Phone is also optional but an important part of the system. Cell Phone warns owner of the house very fast. Also controls system with received messages.

4.1.         Connections of Components

Firstly RS-232 Panel had to be connected and then main panel has to be connected. After that,  C# program can be run in the computer and If cell phone wants to be used cell phone should be connected and Activate Phone Button needed to be clicked.

RS-232 Panel has to be connected to serial port of the computer or a serial converter. Because system is a wireless system with RF modules no connection is needed between panels. But using right antennas are important to use panels in higher distances. Antennas must be 17.3 cm length. Detectors need to be connected ground and detector pins on main panel. If no detector is going to be use for a pin, it is highly recommended to connect ground to that pin. All panels needs to be supplied externally, using a battery is possible but again it is highly recommended to use an adaptor instead of a battery. Voltage must be between 7.5V and 16V. 12V is recommended. Also all of the detectors need to be supplied externally with same voltage level 12V.

4.11 Figure RS-232 Conn

In the 4.1‑1 Figure, there is a working version of the prototype of the Door Panel on a breadboard. Voltage should be connected to “External Voltage 7.5 – 12 V” with right poles. Red cable represents positive voltage and black one is ground. Two coax cables are needed to be used as cable for antenna connection. In the second figure a D-Sub with 9 pin is used as connection to serial port of the computer.


 

4.2.         C# Program

This program controls most of functions of Security System with help of main panel. All SMS traffic is controlled with that program. Web site and properties, password, etc of web site is controlled with C# program. After all connections established it is possible to run C# Program in the computer. This program is needed to be open the whole time to get SMS and update Web Site.

4.2.1. Log In Screen

When C# program is run, Log In screen welcomes user. User firstly has to wait to end connection checking. Then user has to enter Password of the Home Security System. If no password set before, default password is 0001. This password only can be changed with Main Panel and Web Site has different password with Security System. Only main system can confirm password, so user can wait a moment after entering password. If Password is correct main screen can be seen otherwise Log In screen stays and user gets a password wrong message.

4.2.11 Figure Log In

If a message appears which indicates that COM port is not accessible, user has to enter to options and change COM port for Home Security System. User name is important for Logging but it is not needed to use this system. If signal form Main Panel comes “OK” button will be visible and password can be sent to Main Panel. In every wrong password connection is needed to be checked again.

 


 

4.2.2. Main Screen

After Log In screen, user reaches main screen of the C# Program. In this screen it is possible to see all detectors. Opening and closing a detector, opening and closing all detectors in the selected type, closing alarm, activating and deactivating the Home Security System, activating cell phone option. It is also possible to change options, viewing logs and creating a new design.

4.2.21 Figure Main Screen I

State of 5 detectors can be seen in this screen. If detector is flushing in green tones that means detector is active and not in alarm. If detector is flushing in grey tones that means detector is not active. If detector is not connected, it will not appear on this screen at all. If detector is flushing in red tones, that means detector gives alarm. There are 5 types of detectors: PIR Detector, Carbon Monoxide Detector, Magnetic Detector, Fire/Smoke Detector and Water Flow detector. As caption of the program state of system is going to appear (Active/Not_Activate).


 

In the first time, All detectors are PIR detector and not active but connective. After user makes a new design, it stays in Flash memory in the PIC16F877A. That’s why user has to make first design to use system.

Opening\Closing a Detector:

4.2.22 Figure Main Screen II

When user clicks one of the detectors on the screen, s/he can see Open / Close choices. When user clicks one of the choices, RF signal goes to Main Panel and all detectors are sent to PC again. PC draws new design according to RF signal.

Opening\Closing a Detector Type:

4.2.23 Figure Main Screen III

To Open\Close a detector type, user has to make a right click on one of the PictureBox of the detector type. When user clicks one of the choices, RF signal goes to Main Panel and all detectors are sent to PC again. PC draws new design according to RF signal. All messages can be read from Message Board.


 

Activate\Deactivate System:

4.2.24 Figure Main Screen IV

To activate system click Activate buttons & to deactivate system click Deactivate button. If Deactivate clicked, RF signal goes to Main Panel and then Main Panel closes checking detectors and sending State Messages. Instead it sends System is “not active” messages after “System Deactivated” message.  If Activate clicked, RF signal goes to Main Panel and then Main Panel starts to checking detectors and sending State Messages and it continues to send System is “active” messages after “System Deactivated” message.  It is possible to see in the led and LCD screen of Door & Main panel (4.2.2‑6 Figure).

4.2.25 Figure Main Screen V

In the Main Screen it is seen, how Activate Button works. Page caption changes and System Activated message is came from Main Panel.


 

4.2.26 Figure Main Panel

In the 4.2.2‑6 Figure, Main Panel can be seen. System is active and not in the alarm. Double color led shows the same message with LCD Module in the first line.

Closing Alarm:

If alarm is given it is possible to close alarm with just a button or SMS if Cell is activated. C# sends a “Close Alarm” message to Main Panel and main panel returns a message (“Alarm Closed”) in return. It is also possible to see that in the main panel.

Activate Cell:

Once cell phone is activated, C# program searches for all SMS to find a relevant message for Security System. It is important that Cell Phone has to support SMS reading with AT Commands. Otherwise C# program can crash. To control Security System, cell phone number which sends commands with SMS have to be registered in Options. If Main system sends alarm, C# program makes cell phone send SMS to all registered cell phones in Options of C# Program. Activate Cell button can be cliked only one time.

Others:

In the Main Screen, it is possible to reach to Log Form, Options and New Design Form. All of them will be discussed later with details.  ProgressBar shows how much progress taken for completing registering detectors. Message Board shows all received message from Main System and shows message which are sent by computer to Main Panel. So Message Board is used to inform user.


 

4.2.3. Options Form

Options Form is used to change program settings like serial ports for system and cell phone, web site local address and password and some other properties. It is possible to reach this form with two ways. First one is form Main Screen with Options Button and the second one is from Log In screen with Options Button.

HS System Properties:

4.2.31 Figure Options Screen I

In the 4.2.3‑1 Figure, HS System Options is seen. There are two options about the system: connection lost alarm time & COM port number for connection between Main System and Computer. It is clear what COM port number is. This dropdown list fills according to COM ports on the computer and user have to select one of them.

Give alarm if, last signal received …(second) before indicates when C# program will give error if that time expired but no signal reached in that time form Main Panel. If that time expires C# Program gives alarm and sends that with a signal to Main Panel but probably Main Panel is unavailable any way. It is possible to close that alarm with C# program, SMS or Main & Door panel like detector alarms. Again this alarm type sends SMSs to all registered cell phones too.


 

Cell Phone Properties:

4.2.32 Figure Options Screen II

In that page, it is possible to change COM port which indicates connected COM port for cell phone. Again dropdown list fills according to COM ports on the computer and user have to select one of them.

Speed of Port (Baudrate) is speed to communicate with cell phone. Cell Phones support very high speeds on the serial port but it is possible to use a slower one. User can use same supported baudrate with HyperTerminal if they tested cell phone with it.

Cell Phones to Send and Get Messages is used to register cell phones. These cell phones are important because C# program only accepts SMSs from these four phone numbers. When an alarm is given, these phones are going to get alarm messages with SMS too.

Test Cell Button is used to checking cell phone with AT command. Basically it sends AT message via serial port to cell phone and waits for message from cell phone. If OK message is received Testing is successful. If “ERROR” message is received or time out occurred testing gives error. That means either port is inaccessible or cell phone doesn’t support AT commands.


 

Web Site Properties:

4.2.33 Figure Options Screen III

Web Site is used to inform user about system status in the internet when they cannot reach to actual computer which runs C# program. C# program controls web site and gives password to it. Without this program web site can only show same page again and again. C# program changes page according to detectors. 

First option is local location of the web site. With Browse Button it is possible to select web root with directory browse. That means in the given path, all Web site files must be located. Root of the web site must be correct otherwise options cannot be saved. It is also possible to write web root in the text box instead of selecting with directory browse dialog.

Web site password is not same with System’s password. Default password is “asd” for the web site.  This password is encrypted with MD5 password encryption algorithm and it is embedded to code of web site (ASP Code) by C# program. Also a copy of the password is kept in the configuration file of C# Program like all other options. Copy of the password is kept with MD5 encryption too. So it is not possible to see if password is forgotten. But it is possible to change it in the configuration file. To get a MD5 encrypted string, users can use internet to search a web site which gives MD5 encrypted string according to typed string. Example: http://www.bilgiportal.com/md5.php


 

It is very important that doesn’t matter which way used to enter Option Form, changes requires resetting program. In other words, user can use Main Screen or Log In Screen to enter Options Screen. But any way if any change done, program should be closed and opened after changes. Because some variables like COM Port for system can only be load at the beginning of the program. In the caption of the Options Screen there is a warning about that too.

All of the options are saved as a text file in the start-up path of the program with the name “security.conf”. All of the variables in this file are very important and any manual change can cause crashing of the program. If user needs a change in this file, it is highly recommended to take a copy of old file. Let’s see inside of the file:

security.conf

numberOfDetector = 5

Detector0 = 196,127,49,True,True

Detector1 = 456,165,50,False,True

Detector2 = 379,83,51,True,True

Detector3 = 308,228,52,False,True

Detector4 = 303,72,53,False,True

SecurityPort = COM1

AlarmTime = 15

CellPort = COM4

CellPhone0 = 0535-7964468

CellPhone1 = 0

CellPhone2 = 0

CellPhone3 = 0

CellPortSpeed = 115200

WebPass = 7815696ecbf1c96e6894b779456d330e

WebRoot = C:\Users\Erdoi\Desktop\HomeSecurity I.6\Web_Page

 

As seen, WebPass is encrypted with MD5 algorithm. Changing here doesn’t affect Web Site. But C# makes old password check according to this file. So any change can affect password confirmation of C# Program about Web Site password.

Detector properties are: Detector0 = LocationX,LocationY,DetType,isActive,isConnected

Bound rate of the cell phone is CellPortSpeed and it has to be a standard like ..., 9600, 14400, 19200, 38400, 57600, 115200, 128000, 230400, …


 

4.2.4. Log Screen

Like every security system this system has a logging system too. Every Log is kept in text files and every month a new file is created. That logs can be seen in C# program. But if user wants to take a backup of them, s/he has to make it manually or can use a different program to make it regularly.

User can reach Logs from Main Screen by clicking Logs Button. After that user reaches to main screen of the Log Screen which shows all monthly logs (4.2.4‑1 Figure).  By clicking one of the monthly saved log file, user can reach to file and see inside of the file. With scroll bar user can read all files.

 

4.2.41 Figure Logs I

If user clicks Close File Button, main screen of the log file will appear again and user can select a new file or close logs.

4.2.42 Figure Logs II


 

4.2.5. New Design Form

One of the most important forms of C# program is this screen. Because at the first time this system is opened a new design is necessary. Then when ever a new design is needed, this form has to be used to reflect that in the security system. Some of the properties are kept in the microcontroller in the flash (eeprom memory). So they cannot erase with resetting microcontroller. But if some way they get corrupt user can build a new design with this screen again. Every time someone closes or opens and detector, microcontroller sends saved design in the microcontroller. It is possible to reach this form from Main Screen with New Design Button.

4.2.51 Figure New Design I

In this page, in the right side there are detectors according to configuration file. So they are dynamically created it is possible to add detector if system is updated. User can use any picture for their home (plan of the house, pictures of the house, drawing of the house …). Then user can drag the detector in the screen according to their design in real life or any way they wanted.

When mouse is over on one of the detector, detector number will appear and that’s way user can know which detector they are dragging. 


 

There are 5 detector type PIR Detector, Carbon Monoxide Detector, Magnetic Detector, Fire/Smoke Detector and Water Flow detector. All of the detectors can be selecting with making a right click on the preferred detector picture. After selected type user can set is detector active, not active, connected or disconnected with left clicks. Every time user makes a left click color of the detector picture will change. Green means detector is connected and active, gray means it is connected but not active, black means it is not connected so it will not appear on the Main Page.

4.2.52 Figure New Design II

After clicking OK Main Screen will appear again and about 4 seconds C# program will send new design to Main Panel then C# program will wait for taking new design from Main Panel to show user design is taken right or wrong from C# Program. That can take about 10 seconds and will be showed with Progress Bar. If something is wrong user can create the design again with same steps. In the test, there was no error.


 

4.3.         Web Site

From the web site user can see state of the security system and so house. To reach web site from outside of the network (including internet), user has to make port forwarding (NAT). Network Address Translation can be simply done but every router/modem has different ways to do it. That’s why it is not possible to write how it can be done in this report. Also user needs IIS (Internet Information Services) to publish web site because web site includes some asp codes and IIS supports asp pages. Every professional Windows Operating System (XP, Vista, 7, Server 2003, Server 2008, … ) has it and can be installed as a window component freely. It is important that C# program has to change web site so it has to have permission to make this. Otherwise web site will never get updates. If asp can be integrated to other web servers, they can be used too. It is also important that, this web site is design for Google Chrome and doesn’t support explorer. So to see this web site user has to use Google Chrome.

4.3.1. Main Page of Web Site

This page informs about using web site and cell phone. This page can be seen before log in to web site.

4.3.11 Figure Main Web Page


 

4.3.2. Log In Page of Web Site

This page is used to log in to the web site. Name and Surname is not really important. Name is going to appear on welcome message only. But sessions of server uses name to check is user logged in or not. With remember me check box, it is possible that username can be remembered by web page and user will not have to enter name every time. To make it work JavaScript has been used and to checking password ASP in “Log_In.asp” is used.

4.3.21 Figure Log In Web Page

Password is embedded in the code of “Log_In.asp” with C# program as encrypted.

Inside “Log_In.asp”

… <%

Dim pass,reqPass

pass= "7815696ecbf1c96e6894b779456d330e"

reqPass = Request.Form("lbl_sifre")

…

 

7815696ecbf1c96e6894b779456d330e is asd with MD5 encryption algorithm. It can be changed with Option Screen of C# Program.


 

4.3.3. Detector Page of Web Site

This page shows state of the house and controlled by C# program. Every second web site is updated by C# Program. To see this page users have to log in to web page. And they can see changed with Refresh Page Button. In this it is possible to see every detector. Are they active are they in alarm.

 

4.3.31 Figure Detector Web Page

To enter and refresh this page Refresh HS Page Button can be used which is in the left frame of the page. After Log In this page is automatically appears too. But after few minutes, user’s log information expiries and they have to log in again.

This page simply reads a text file to user with ASP code:

<%

                Dim OpenFileobj, FSOobj,FilePath

                FilePath=Server.MapPath("dets.txt") ' located in the same director

                Set FSOobj = Server.CreateObject("Scripting.FileSystemObject")

                if FSOobj.fileExists(FilePath) Then

                Set OpenFileobj = FSOobj.OpenTextFile(FilePath, 1)

               

                Do While Not OpenFileobj.AtEndOfStream

                Response.Write OpenFileobj.ReadLine & "<br>"

                Loop

               

                OpenFileobj.Close

                Set OpenFileobj = Nothing

                Else

                Response.Write "File does not exist"

                End if

                Set FSOobj = Nothing

….          

                %>


 

4.3.4. About Page of Web Site

This page gives a little information about Security System to users.

4.3.41 Figure Log In Screen

4.3.5. Log Out Page of Web Site

This Page simply removes Log In information of the user.

4.3.51 Figure Log Out Screen


 

4.4.         Using Main Panel

Main panel controls everything and user can use some functions on this panel too. For example changing password is only possible with this panel. But to use every function, user has to enter a password firstly.

4.41 Figure Main Panel

In this panel it is possible to:

·         Close System

·         Open System

·         Change Password

·         Close a Detector

·         Open a Detector

·         Close Alarm

But firstly, password has to be entered to use all of these functions. (4.4‑2 Figure Main Panel II)

4.42 Figure Main Panel II

Using Keypad:

·         Key A is Enter

·         Key B is Cancel

·         Key C is Back

·         Key D is Next

4.43 Figure Keypad


 

 

4.5.         Using Door Panel

Door Panel should be outside of the house and can only show user is System Active or Not Active. This Panel is optional for the system but very usable. Just like Main Panel, user has to enter password to use functions. It has same keypad combination and has two functions:

·         Close System

·         Open System

4.51 Figure Door Panel


 

4.6.         A Quick Set Up

To make system works mainly the following steps should be done.

4.61 Figure Quick Setup


 

5.                CONCLUSION

This project is a home security system with microcontroller and computer. Three panel, cell phone and a computer is used in this system. Main panel controls all detectors and all detectors are connected to this main panel. Door panel is to activate and deactivate security system outside of house and show user is system active or not. That system is a wireless system and uses RF signals to communicate with other panels. This system can detect a burglar or fire\smoke\gas and any treat against house if there is a detector with relay connection. If a system detects an alarm PC updates web site so if owner is not in the home they can see state of house. Computer sends a SMS to inform owners when an alarm detected too. There are lots of components and modules which are used to make this system works and it is possible to learn all about with this report. This system can be used for a house to inform users against any treat.


 

 

6.                BIBLOGRAPHY

 

DataSheet ABC016002E. (n.d.). Retrieved January 24, 2010, from Shenzhen AV-Display Co., Ltd: http://www.av-display.com.cn/en/Products_show.aspx?NOID=1013

Hewes, J. (2009). Light Emitting Diodes (LEDs). Retrieved january 24, 2010, from The Electronics Club: www.kpsec.freeuk.com

MAX232 Serial level converter. (2007, February 26). Retrieved January 24, 2010, from sodoityourself: http://sodoityourself.com/max232-serial-level-converter/

Radio frequency. (2010, January 15 ). Retrieved January 23, 2010, from Wikipedia, the free encyclopedia: http://en.wikipedia.org/wiki/Radio_frequency

Relay. (2009, November). Retrieved March 14, 2010, from Wikimedia Foundation, Inc: http://en.wikipedia.org/wiki/Relay

Wiki. (2010, January 22). AT Commands. Retrieved March 15, 2010, from forum.nokia.com: http://wiki.forum.nokia.com/index.php/AT_Commands

 


 

7.                BIOGRAPHY

Erdinç AYDIN was born on September 22, 1988 in İstanbul. He graduated from Ataşehir Lisesi in 2005. After that he entered the Department of Computer Engineering in Doğuş University. He still continues his education in Dogus University as a   Computer Engineering student. He wants to develop himself at the area of software engineering and management information systems.