53
CALIFORNIA STATE UNIVERSITY, NORTHRIDGE Smart Home Security System A thesis submitted in partial fulfillment of requirements For the degree of Master of Science in Electrical Engineering By Orod Haghighiara December 2015

CALIFORNIA STATE UNIVERSITY, NORTHRIDGE Smart Home

  • Upload
    others

  • View
    2

  • Download
    0

Embed Size (px)

Citation preview

Page 1: CALIFORNIA STATE UNIVERSITY, NORTHRIDGE Smart Home

CALIFORNIA STATE UNIVERSITY, NORTHRIDGE

Smart Home Security System

A thesis submitted in partial fulfillment of requirements

For the degree of Master of Science in Electrical Engineering

By

Orod Haghighiara

December 2015

Page 2: CALIFORNIA STATE UNIVERSITY, NORTHRIDGE Smart Home

ii

The graduate project of Orod Haghighiara is approved:

__________________________ _______________

Dr. Ramin Roosta Date

__________________________ _______________

Benjamin Mallard Date

__________________________ _______________

Dr. Shahnam Mirzaei, Chair Date

California State University, Northridge

Page 3: CALIFORNIA STATE UNIVERSITY, NORTHRIDGE Smart Home

iii

Acknowledgment

I would like to thank Professor Shahnam Mirzaei for his motivation, guidance, patience,

and continuous support of my final project. I could not have imagined having a better

advisor and mentor for my master program study.

Besides my advisor, I would like to thank committee: Professor Ramin Roosta and

Professor Benjamin Mallard for their insightful comments and encouragement.

Last but not the least I would like to thank my parents and family for their love and

encouragement.

Page 4: CALIFORNIA STATE UNIVERSITY, NORTHRIDGE Smart Home

iv

TABLE OF CONTENTS

Signature page .................................................................................................................................ii

Acknowledgment ............................................................................................................................ iii

List of Figures .................................................................................................................................. v

Abstract ........................................................................................................................................... vi

Chapter1: Introduction .............................................................................................................. 1

1.1 Background ............................................................................................................................ 1

1.2. Objective ............................................................................................................................... 1

Chapter2: Design ...................................................................................................................... 3

2.1. Features and Specifications .............................................................................................. 3

2.2. Design Overview ............................................................................................................. 4

2.3. Control Home with Cell Phone ........................................................................................ 6

Chapter3: System Description: ................................................................................................. 8

3.1. Analog to Digital Converter (ADC): ............................................................................... 8

3.2. Data Transfer: ................................................................................................................ 11

3.3. Received Text ................................................................................................................ 15

Chapter4: System Components: ............................................................................................. 17

4.1. Processor: Zynq 7 Processing System (System on Chip) .............................................. 17

4.1.1. Zynq system on chip is divided two main subsystems .......................................... 18

4.2. Data Communication Module ........................................................................................ 19

4.2.1. AT Command Types: ............................................................................................. 21

4.2.2. Some Important and Useful Commands ................................................................ 22

4.3. Sensors ........................................................................................................................... 28

4.3.1. Motion Detector ..................................................................................................... 28

4.3.2. Gas Sensor (MQ-9) ................................................................................................ 31

4.3.3. Temperature Sensor: .............................................................................................. 33

Chapter5: Conclusion ............................................................................................................. 34

Appendix ........................................................................................................................................ 35

1. References .............................................................................................................................. 35

Page 5: CALIFORNIA STATE UNIVERSITY, NORTHRIDGE Smart Home

v

List of Figures

Figure1: Top Level Block Diagram ................................................................................................. 3

Figure 2: High level block diagram for Gas sensor ......................................................................... 4

Figure 3: High level block diagram for motion detector sensor ...................................................... 5

Figure 4: Zybo GPIO, LEDs that we used in zynq for showing gas level ....................................... 5

Figure 5: Block diagram for receive a text from user. ..................................................................... 6

Figure 6 :Vivado High level block diagram ..................................................................................... 7

Figure 7: ADC PMOD ..................................................................................................................... 8

Figure 8: This figure displays how the FPGA and ADC interface with each other. ........................ 9

Figure 9: Waveform displaying the timing requirements for the ADC ........................................... 9

Figure 10: Zybo USB-JTAG/UART Bridge .................................................................................. 11

Figure 11: Zynq Receive and transmit pin outs and Zybo LEDs connected to RX, TX. ............... 12

Figure 12: Xilinx Platform Studio for my design. ......................................................................... 13

Figure 13: UART 0's Peripheral changed to Pmod pin outs. ......................................................... 13

Figure 14: Two boards are communicating together with UART protocol with two wires. ......... 14

Figure 15: Sample confirmation response from GSM module ..................................................... 16

Figure 16: Zybo power circuit overview........................................................................................ 17

Figure 17: Zynq SOC Architecture ................................................................................................ 18

Figure 18:SIM 900 module and connected antenna ....................................................................... 20

Figure 19: PIR Sensor .................................................................................................................... 30

Figure 20: PIR with Fresnel lens ................................................................................................... 30

Figure 21: Lens information .......................................................................................................... 30

Figure 22: Circuit I used in our project for the MQ-9 Gas Sensor ................................................ 31

Figure 23:MQ9 Sensitivity ............................................................................................................ 32

Figure 24: Influences of temperature and humidity in MQ-9 ........................................................ 32

Figure 25: LM35-Temperature sensor ........................................................................................... 33

Page 6: CALIFORNIA STATE UNIVERSITY, NORTHRIDGE Smart Home

vi

Abstract

Smart Home Security System

By Orod Haghighiara

Master of Science in Electrical Engineering.

This project provides a device to manage the safety standard conditions for houses and

the control houses remotely. The device is designed to send text messages to the resident

by using Global System for Mobile Communications (GSM) Module. This system works

when an intruder enters the house or the level of existence of Methane gas or Carbon

Monoxide (CO) goes above the standard safety limit. On the other hand the residence can

send a predefined text message to the module to turn on and off the specific electrical

devices like HVAC or lights. The module will also send a confirmation text of the work

done to the user.

This device has two main processes for monitoring the safety conditions. The first part is

used to detect Methane gas by using Analogue to Digital Converter (ADC). This process

calculates the amount of the precise value of the gas density in the room to show the

density on the hyper-terminal continuously. If the level of gas goes higher than the health

limit it will send an alert text message to the user. The second part of this process detects

any motions in the room and also it will send an alert text message to the user.

This device consists of both hardware and software design sections. In the software part,

VHDL, C programming and AT Commands are used for telecommunications. In the

hardware section, Xilinx Zynq all Programmable System-on-Chip (AP SoC) architecture

is used that it tightly integrates a dual-core ARM Cortex-A9 processor with Xilinx 7-

Page 7: CALIFORNIA STATE UNIVERSITY, NORTHRIDGE Smart Home

vii

series Field Programmable Gate Array (FPGA). It also includes a gas sensor, a motion

sensor, a temperature sensor, a fire sensor, a GSM module, UART and ADC.

This System helps users to improve their house security by sending alerts in case of

incidents like fire or robbery that may put one's home in danger. Also, by early

notification, the home owner might be able to prevent the life threatening results of such

incidents.

Page 8: CALIFORNIA STATE UNIVERSITY, NORTHRIDGE Smart Home

Chapter1: Introduction

1.1 Background

There are many risks for homes like, most residential burglaries happen when no one is at

home to maintain the security. For example a family may have gone for a vacation. When

they come back home, they are faced with a home been robbed. There is another

possibility that might even be life threatening, and that is the existence of over the limit

of dangerous gases. The methane gas is used in heaters and some gas stoves. Sometimes

there might be gas leaks or someone may have forgotten to turn off stove that which can

cause fire. For these two main reasons this device is designed to prevent these financial

damaging and life threatening incidents.

1.2. Objective

As we know in today‟s world home security as well as remote controlling the home

appliances are very important. Due to several reasons such as higher costs, insurance

fees, and in general life safety people do whatever they can to lower the chance of having

unwanted incidents that some of which can be life threatening as well. Such incidents

include but are not limited to fire hazards, gas leak or robbery. In addition, people like to

use easier application and devices, like wireless or remote controlled devices to manage

their homes and appliances. As a result, I used Field Programmable Gate Array (FPGA)

and Microprocessor to improve the home security by detecting the entrance of an intruder

as well as the existence of over the limit of harmful gases or fire and send a text message

alert to the home resident. Some examples of these gases are CO and Methane that are

created as a result of a malfunction in the heating system or gas stove. The residents can

Page 9: CALIFORNIA STATE UNIVERSITY, NORTHRIDGE Smart Home

2

also monitor these changes from their computers, and in case the gas density exceeds the

standard limits, they will receive a warning message on their cell phone.

The following components were used to implement a system to support the

abovementioned functions a Motion sensor, a Methane gas sensor, Temperature sensor,

Fire sensor, Digilent Zybo board with Xilinx Zynq FPGA, a serial cable (RS232), a GSM

module (sim 900), an activated cell phone sim card, Xilinx ISE Design Tool and Vivado,

External Interrupts and GPIO (General Purpose Input and Outputs), XADC (Xilinx

Analog to Digital Converter).

Page 10: CALIFORNIA STATE UNIVERSITY, NORTHRIDGE Smart Home

3

Chapter2: Design

2.1. Features and Specifications

This device communicates with the user by sending and receiving text messages. The

device detects any motion as well as Methane gas or fire and it sends a text message to

the user‟s phone. It will indicate if a person enters the room or the level of Methane or

Carbon monoxide gas is above the standard safety limit.

The user also can send a predefined text message to the device to turn on and off some

special electrical devices like HVAC (Heating Ventilating Air Conditioning) or lights.

Then the board will send a confirmation text to user to notify user the task is successfully

done. You can see the high level block diagram of my design in figure.1.

Figure1: Top Level Block Diagram

Page 11: CALIFORNIA STATE UNIVERSITY, NORTHRIDGE Smart Home

4

2.2. Design Overview

The first part of my design flow is consists of a motion sensor, a gas sensor, and fire

sensor. Anytime a motion or Methane gas is detected in the room the sensors will send

data to the Zybo board. The output of the gas sensor will be sent to the Programmable

Logic (PL) of the Zynq, XADC converts the sensor‟s analog data to digital signals. Zynq

continuously displays density value level of gases on a hyper-terminal. If the gas density

is above the standard safety limit a text message alert will be sent to the user (Figure-2).

The motion sensor‟s data will be sent to the Processing system(PS) GPIO section and it

issues an external interrupt to the PS. Afterwards, Zynq will send a command to the GSM

Module that it sends the alert text message to the user to notify user that someone

entering the room (Figure-4 and Figure-5) .

Figure 2: High level block diagram for Gas sensor

Gas Detect

MQ-9 Sensor

XADC

Calculate the exact amount

of gas and displayed on

hyper-terminal

If exceeded the

standard limit an

External

Interrupt will be

sent to the board.

Compare with the

standard limit

(1000 PPM for

Methane, 200

PPM for CO).

Turn on the

LED on the

board.

Send a warning

through GSM.

Page 12: CALIFORNIA STATE UNIVERSITY, NORTHRIDGE Smart Home

5

Figure 3: High level block diagram for motion detector sensor

Figure 4: Zybo GPIO, LEDs that I used in zynq for showing gas level

Motion Detect

PIR Sensor

Turn on the LED

on the board.

Send a warning

text through

GSM.

Any movement

detected will send

External Interrupt

to the board.

Page 13: CALIFORNIA STATE UNIVERSITY, NORTHRIDGE Smart Home

6

2.3. Control Home with Cell Phone

The user can send a text message to the board to do a specific task like turning on or off

the air condition. When module receives a text message, first it checks the phone number

to make sure that the text message is from the home owner. Then the module will read

the text message. If content of that text is one of predefined messages that it is in the

memory of device, Zynq will send a command to the board to do that specific task. For

example if the module receives a text message with content of “On-1” then FPGA will

turn on the light. Or if it receives a text message with content “Off-1” then FPGA will

turn off the light. When the task is completely done board will send a confirmation text to

the user to let him/her knows that the job is successfully done (Figure-5).

Figure 5: Block diagram for receive a text from user.

Text received

To the board

Valid

phone

Defined

command

Do the task

Send confirmation

text to user.

Page 14: CALIFORNIA STATE UNIVERSITY, NORTHRIDGE Smart Home

7

The Xilinx zynq 7000 Processing System (System on Chip) is controlling all these

process. I used Xilinx Vivado for my design. You can see how different modules are

connected and communicated with the zynq in Vivado high level block diagram (figure

6).

Figure 6 :Vivado high level block diagram

Page 15: CALIFORNIA STATE UNIVERSITY, NORTHRIDGE Smart Home

8

Chapter3: System Description:

3.1. Analog to Digital Converter (ADC):

In this design, I used both internal ADC and External ADC modules provided on the

Zybo board (Figure-7). FPGA communicates with the ADC module that it uses SPI

interface. Then ADC will send its output as two 12_bit 2‟complement which are the

digital representation of the analog input signals (Figure-8).

Figure 7: ADC PMOD

Page 16: CALIFORNIA STATE UNIVERSITY, NORTHRIDGE Smart Home

9

Figure 8: This figure displays how the FPGA and ADC interface with each other.

To get the ADC working, FPGA needs to send a pulse to the AD_CONV on the ADC

module. After each pulse of AD_CONV, at the rising edge of the SPI clock, the ADC

takes in one analog sample, and outputs the digital value of the previous sample by one

sample latency. ADC sends its outputs in 12_bit 2‟complement format on the SPI_MISO

port to the FPGA. ADC takes 32 SPI clock cycles to convert the analog data to its digital

representation. Also before and after sending out each 12_bit data, the ADC leaves two

clock cycles on high impedance. Therefore, in total, every 34 clock cycles the ADC sends

out its output. For ADC SPI timing and signal names please refer to figure-9.

Figure 9: Waveform displaying the timing requirements for the ADC

Page 17: CALIFORNIA STATE UNIVERSITY, NORTHRIDGE Smart Home

10

It is important to note that the AD_CONV signal is not like a traditional slave enable for

the ADC module. As a result, I need to make sure that it waits for enough clock cycles so

that the ADC leaves the SPI_MISO in high impedance otherwise it will block other

devices from using the SPI bus.

One other very important point is that while I'm using ADC, I disable the other devices

that share SPI with FPGA, otherwise there will bus contention. Table-1 lists those

devices, their activation signal, and their disable value.

Table-1: The devices that share SPI with the FPGA, that need to be disabled when ADC are in

use.

After the device received ADC's output, in order to detect the gas level if it is at or above

the standard limit. Module compares it to the standard value. In the case that this value is

above the standard limit, it will initiate an interrupt, and FPGA will then send a message

to the GSM board and then GSM module will send a text message to informing the user

about the existence of the methane gas.

Page 18: CALIFORNIA STATE UNIVERSITY, NORTHRIDGE Smart Home

11

3.2. Data Transfer:

In my project I used Serial port for data transfer to the external modules or displaying

data in Hyper Terminal. For example whenever there is any movement in the room or

spreading of harmful gases like CO or Methane FPGA will send a warning text message

to the user cell phone.

I used UART protocol to compute data communication between module and computer

and between Zynq and GSM module. Zybo board has USB-JTAG/UART Port (Figure-

10) that it is connected to PC to program FPGA as well as communicate with

HyperTerminal. zynq has two serial ports, I used one of them(UART1) for communicate

to the computer and the other one (UART0) is used to communicate between FPGA

Board and GSM board.(Figure-11)

Figure 10: Zybo USB-JTAG/UART Bridge

Page 19: CALIFORNIA STATE UNIVERSITY, NORTHRIDGE Smart Home

12

Figure 11: Zynq Receive and transmit pin outs and Zybo LEDs connected to RX, TX.

As Zybo board has two UART connections that they communicate with Micro USB

UART bridges connector. GSM board comes with RS232 connector for UART

communication, to connecting these two boards I need to have two converters. One

converter is used to convert micro USB to USB and the other one converts USB to

RS232 and it‟s not easy to do all these conversion. So I used one of the features of zynq

to change UART's pins. I opened our design file in Xilinx Platform Studio (XPS)

(Figure-12). I selected I/O peripherals and then I changed the physical location of UART

0's pin out form USB port to location of 2 Pmod pins MIO-10 and MIO-11 for RX and

TX (Figure-13). Now I can connect directly Rx-Tx of Zynq processing system to the Rx-

Tx of GSM module with two wires (Figure-14).

Page 20: CALIFORNIA STATE UNIVERSITY, NORTHRIDGE Smart Home

13

Figure 12: Xilinx Platform Studio for my design.

Figure 13: UART 0's Peripheral changed to Pmod pin outs.

Page 21: CALIFORNIA STATE UNIVERSITY, NORTHRIDGE Smart Home

14

Figure 14: Two boards are communicating together with UART protocol with two wires.

Page 22: CALIFORNIA STATE UNIVERSITY, NORTHRIDGE Smart Home

15

3.3. Received Text

User can send a text message to module to do some predefined task. To do this

predefined task, the user needs to have the module's phone number.

When GSM module receives a text message it will immediately send the text messageto

the FPGA. FPGA will recognize the message. Then it can detect if this received message

is a valid AT command or not (Valid received notification is +CMTI: "SM", 1). If FPGA

found the message is a valid AT command then it will send another AT command to

SIM900 to read a specific text (AT+CMGR= 1). GSM reads the text message content and

it will send it to FPGA again. The Zynq's process system (ARM) will check the phone

number of text sender. If the number is matched with the database, it will start reading the

content of the text. If the text message contains one of predefine commands then ARM

processor sends a signal to the board to do that specific task. For example I defined that if

the user sent "On1”, the ARM would turn on living room's light. Then GSM will send a

confirmation text to the user like a “Living room's light is on ". This confirmation will

notify the user that the task is successfully done. (Figure-15)

Page 23: CALIFORNIA STATE UNIVERSITY, NORTHRIDGE Smart Home

16

Figure 15: Sample confirmation response from GSM module

Page 24: CALIFORNIA STATE UNIVERSITY, NORTHRIDGE Smart Home

17

Chapter4: System Components:

4.1. Processor: Zynq 7 Processing System (System on Chip)

I used zybo board as a main board of my project, because it has Xilinx Zynq-7000 as

processor that is based on Xilinx Zynq all Programmable System-on-Chip (AP SoC)

architecture, which tightly integrates a dual-core ARM Cortex-A9 processor (650 MHz)

with Xilinx 7-series Field Programmable Gate Array (FPGA) logic is used. It can work

with 5V/2.5A power adaptor or USB-JTAG-UART port. (Figure-16)

Figure 16: Zybo power circuit overview

Page 25: CALIFORNIA STATE UNIVERSITY, NORTHRIDGE Smart Home

18

4.1.1. Zynq system on chip is divided two main subsystems:

1- Programmable Logic (PL):It can do almost all Xilinx FPGA 7-series Artix and user

can configure and program it with JTAG port or it can program by processor (PS).

2- Processing System (PS):It includes processing unit Cortex-A9, as advanced

microcontroller. And it has a lot of components like Timers, DDR3 controller SPI, CAN,

UART that I used it for communication between zynq and computer. GPIO is used to

send a signal to relay to turn on and turn off electrical devices such as air condition.

These two parts are connected together with using AXI ports (Figure-17)

Figure 17: Zynq SOC Architecture

Page 26: CALIFORNIA STATE UNIVERSITY, NORTHRIDGE Smart Home

19

4.2. Data Communication Module:

One of the major components used in this design is the GSM (Global System for Mobile

Communications) SIM 900 Module from SIMCOM Corporation. This is a

telecommunication device that has a cell phone SIM card slot mounted on it. To use this

module, first it needs to insert an activated cell phone SIM card (Subscriber Identity

Module) in the slot on the module board. AT commands set are used to program this

module. The GSM module can be used to send text messages, make calls, receive calls

connect to internet through a second generation network among other application.

Sim900 is a quad-band GSM/GPRS engine that works with EGSM 900 MHz, DCS 1800

MHz and PCS 1900 MHz frequencies.SIM900 has a tiny dimension 24mm x 24mm x

3mm and it needs a little space on the board, physical interface of this mobile module can

connect to the board through a 68 pin dip connector and it also needs a RF antenna.RF

antenna connects to the module separately. RF antenna has two parts: antenna connector

(that connect to SIM) and antenna pad for connect to the Mobile networks, by connecting

RF antenna all features of this module are ready to use on the board.

SIM900 can work with TCP/IP protocol; AT commands can work easily with this

protocol (Figure-18).

Page 27: CALIFORNIA STATE UNIVERSITY, NORTHRIDGE Smart Home

20

Figure 18: SIM 900 module and connected antenna

The communication will be started when the user sends an "AT" command to the

module. ThenSIM900 will send TA answer to the user. All commands are started with

"AT" or "at" and they follow by other commands. In fact "AT" at starting of each

command is used to inform module. The user wants to write an AT command, so for

multiple commands, the user needs to write only one AT for all commands (AT+CMGL;

+CMGR).

To run AT commands, the user presses Enter then SIM module will detect that command.

At the end of each command there is a <CR><LF> and also all response commands have

the same structure.

Sample pattern:

<CR><LF><response><CR><LF>

(CR=Carrier Return, LF=Line Feed)

Page 28: CALIFORNIA STATE UNIVERSITY, NORTHRIDGE Smart Home

21

AT Command Final Result Code:

Result code is a message that module sends at the end of each response packet, and it

clarifies execution status of AT commands. Final result code could be either: “OK”

means command executed successfully or “Error” .And it should follow by carrier return.

4.2.1. AT Command Types:

At commands have three major categories:

Basic

S parameter

Extended

Basic Syntax:

Basic syntax is the simplest type of AT commands that it is started with "AT" and

continue with a single character.

Example: ATA to answer a call or ATD18053456789dial a phone number.

S Parameter Syntax:

This type of commands is using to access a special register in module, which

called S registers. General syntax of this type is ATS<n>=<m>, where n is index of S

register and m is value that should assign to register n.

Example: ATS0=3: Sets three rings before automatically answer the phone.

Page 29: CALIFORNIA STATE UNIVERSITY, NORTHRIDGE Smart Home

22

Extended Syntax:

These types are executable commands that they have four types (Table -2).

Command type Syntax Description

Test Command AT+<n>=? List all command's option.

Read Command AT+<n>? Shows the current value and state of command.

Write

Command

AT+<n>=<…> Set command as the value that user entered.

Execution

Command

AT+<n> Shows a non-variable command that affected

with internal process in GSM module

Table-2: Four types of extend syntax

4.2.2. Some Important and Useful Commands:

Some command for checking system status:

AT Ok means the board is

connected to the computer.

AT+CPIN ASK for PIN code, if module answers

“+CPIN: READY” it means that SIM

card doesn‟t have Pin code and ready to use.

Page 30: CALIFORNIA STATE UNIVERSITY, NORTHRIDGE Smart Home

23

AT+CMINS Display SIM status.

ATI Display SIM identification and its

manufacture.

AT+CGSN Shows IME (International Mobile

Equipment Identity) number.

AT&V Shows current configuration.

AT+CSPN Service provider of SIM card.

AT+CR Service reporting control.

AT+CREG SIM registration.

AT+CSQ Signal quality.

AT+CMEE=0 don‟t display errors.

AT+CMEE=1 Display errors with error number.

AT+CMEE=2 Display errors with more details

AT+CMGF=1 Set text mode

AT+CMGF=0 Set PDU mode

AT&W Save the user configuration

Page 31: CALIFORNIA STATE UNIVERSITY, NORTHRIDGE Smart Home

24

Dial Commands:

ATT Set mobile in Tone dialing

For dial:

ATD+1818123456 Call the phone number.

ATD<Mem>2 Call from memory (call from phonebook)

ATDL Redial last call.

ATH Disconnect existing connection.

For answer:

ATA Answer to All incoming calls.

ATS0 Set number of the beeps before answers

the call automatically.

Text Commands:

Set Text Center:

AT+CMGF=1 Set to text mode.

AT+CSCA=”01214001400” Set message center service.

Page 32: CALIFORNIA STATE UNIVERSITY, NORTHRIDGE Smart Home

25

AT+CSMS Set message service.

AT+CSAS Save message setting.

Send Text:

AT+CMGS=”+18181234567” put a phone number that board needs to text

to it, then press Enter, command line shows “>” .Now user can start typing

message contents and at the end he/she must presses ctrl-z to send text

message or press “Esc” to discard sending text.

User can send text that it was already stored in SIM card memory by

AT+CMSS=1,” 18181234567”. „1‟ is index of message that saved in

memory.

Read Text:

AT+CMGR=<n> For reading Text received, “n” is index

of received. When a SMS received

module respond a notification that

contains new SMS Number.

Delete Text:

AT+CMGD=<n> Delete specific Text “n” form memory.

AT+CMGDA=” ” Delete all Text messages.

Page 33: CALIFORNIA STATE UNIVERSITY, NORTHRIDGE Smart Home

26

user can delete specific type of messages by using AT+CMGDA= and then “DEL

READ” for delete read messages or “DEL UNREAD” to delete unread text messages, or

“DEL SENT”, “DEL UNSENT”, “DEL INBOX” and “DEL ALL”

Write and store Text in memory:

AT+CMGW after user press Enter and command line shows “>”. User type

message contents. For example +CMGW: 7

List SMS:

AT+CMGL = “ALL”

“STO SENT” command line shows list of all SMS that store in SIM card and sent.

“STO UNSENT” command line shows list of all SMS that store in SIM card and unsent.

Also we can write “REC READ”, “REC UNREAD”, “ALL” for list all kinds of SMS in

the memory.

Page 34: CALIFORNIA STATE UNIVERSITY, NORTHRIDGE Smart Home

27

Phonebook’s Commands:

AT+CPBS= “SM” Set phonebook mode to the SIM card

Memory

AT+CPBR=1,9 Shows contact numbers 1 and 9

AT+CPBF= “Bob” Search for Bob in

AT+CPBW= “0818123456”, “Orod” Add a new contact number

Page 35: CALIFORNIA STATE UNIVERSITY, NORTHRIDGE Smart Home

28

4.3. Sensors:

In this project I used three types of sensors:

1- Motion detector

For security and detect someone enter to home.

2- Gas detector sensor that can detect three different kinds of gas:

Carbon Monoxide detector

Methane detector

LPG (Liquid Petroleum Gas) detector.

3- Temperature sensor

To control home‟s temperature.

4.3.1. Motion Detector

I used motion detector sensor to detect any motion in the room and recognize home

entrance. Then I send a signal (External Interrupt) to the main board that will process this

data. There are three major motion detector sensors:

1. Passive Infrared Sensor (PIR):

It uses body heat for detecting motion. I used this sensor in my project .

2. Ultrasonic Sensors:

Ultrasonic is an active sensor, it means that it repeatedly sends high frequency

pulses and then receive them. If transmit and receive patterns are matched it

Page 36: CALIFORNIA STATE UNIVERSITY, NORTHRIDGE Smart Home

29

means that there is no movement. However, if the received pulse has changed in

terms of period or frequency, sensor detects that object has been moved.

3. Microwave Sensors:

These types of sensors are active components. They transmit microwave pulses

continuously and then compare them with received pulses. And measure the

reflection of the objects that have moved.

PIR Sensor:

The other component is used in this design is a Passive Infrared Sensor(PIR

sensor)(Figure-19). The PIR is a passive sensor which means nothing emits from this

sensor repeatedly. All objects emit black body radiation. One of these radiations is

infrared that the human‟s eyes are not able to see this radiation. Each object has own

specific Infrared radiation temperature.PIR sensor detects motions when a new infrared

source of temperature like human is across in front of another. Infrared source and PIR

can detect these changes in environment. It is usually useful to add a Fresnel lens (Figure-

20) in front of PIR to detect motion better. Adding this lens allows PIR to detect all

motions in sight radius 140 degree within 36-48 feet in corner and 60-80 feet in center of

its sight radius. (Figure-21)

When a person enters the room, the module will automatically turn on the zybo board's

LED. Then it sends a warning message to user's cell phone to let the user knows that

Page 37: CALIFORNIA STATE UNIVERSITY, NORTHRIDGE Smart Home

30

someone is entered in the room. The message in my project is “Zybo Alert! Intruder in

the house!!!” By this warning user will be notified that someone is in the house.

Figure 19: PIR Sensor

Figure 20: PIR with Fresnel lens

Figure 21: Lens information

Page 38: CALIFORNIA STATE UNIVERSITY, NORTHRIDGE Smart Home

31

4.3.2. Gas Sensor (MQ-9)

Another component that I used in my design is MQ-9 gas sensor. MQ-9 gas sensor

detects Carbon Monoxide (CO), Methane (CH4), propane and LPG. MQ-9 is a

semiconductor sensor and it is made out of sensitive materials like Tin Dioxide (Sn2O3)

and Aluminum Oxide (AL2O3).

This sensor does an interesting job in a repeatedly cycle because it has two modes of low

and high temperature. In high temperature mode (heated by 5V) it detects methane,

propane and LPG. In high voltage mode and after its clear the voltage will drop to the

low temperature mode (heated by 1.5V) for detecting CO. When it goes to 90s, the mode

cycle will be repeated. The best performance of this sensor happens when it is preheated

for 48 hours. Also, for working with this sensor I need to use a resistor for output voltage

and for our calibration (200ppm to 5000ppm CH4 and 1000ppm of LPG)(Figure-22).

Figure 22: Circuit I used in our project for the MQ-9 Gas Sensor

Page 39: CALIFORNIA STATE UNIVERSITY, NORTHRIDGE Smart Home

32

Sensitivity Characteristics

Figure 23:MQ9 Sensitivity

Ordinate means resistance ratio of the sensor (Rs/Ro), abscissa is concentration of gases.

Rs means resistance in different gases, Ro means resistance of in 1000ppm LPG.

Influence of Temperature/Humidity

Figure 24: Influences of temperature and humidity in MQ-9

Page 40: CALIFORNIA STATE UNIVERSITY, NORTHRIDGE Smart Home

33

4.3.3. Temperature Sensor:

To have a smart system I need to have some feature that the board can do it

without user‟s commands. I need to automate the system. One example of this situation

for sensors is a temperature sensor, which needs to initialize with three different

temperatures from the user in installation of the board. One temperature is to be set as a

room temperature (78 degree of Fahrenheit). Also the user defines minimum and

maximum temperature (min=70 F and max=85 F). If the temperature exceeds maximum

our board will send a signal to the Fan and turn it on automatically, or if temperature goes

down to the minimum it will turn on the electrical heater.

Figure 25: LM35-Temperature sensor

Page 41: CALIFORNIA STATE UNIVERSITY, NORTHRIDGE Smart Home

34

Chapter5: Conclusion

In this project I worked with the Zynq 7000 series as an embedded processor on the

Xilinx FPGA. Also I used the ADC module provided on the board. I used SPI to interface

the FPGA with the ADC, and the Serial port to interface with the FPGA with the Hyper-

Terminal and GSM module. In addition, I worked with four different types of sensors, a

gas, temperature, and fire and motion sensor.

The user can use this system to improve his/her home security to receive alerts in case of

incidents like fire or robbery that may put his/her home in danger. Also, by early

notification, the home owner might be able to prevent the life threatening results of such

incidents.

Future works:

There are few ways to improve this project. I can use a wireless module for each sensor,

so that they send data wirelessly to the main module. The other side of wireless module

in main board receives data, and uses it. Also instead of the computer monitor, I can add

a touch LCD for showing data and status of the system.

Page 42: CALIFORNIA STATE UNIVERSITY, NORTHRIDGE Smart Home

35

Appendix

1. References

1.Zybo board datasheet

http://www.digilentinc.com/Data/Products/ZYBO/ZYBO_RM_B_V6.pdf

2. Xilinx zynq datasheet

http://www.xilinx.com/products/silicon-devices/soc/zynq-7000.html

3. SIM900hardware design V2.04 datasheet

http://www.simcom.eu/index.php?m=termekek&prime=1&sub=40&id=0000000147

4. AT command set for SIM900 V2.00 datasheet

5. MQ-9 gas sensor datasheet, e-radionica.com/productdata/mq-9.pdf

6. PIR datasheet https://www.mpja.com/download/31227sc.pdf7. LM35 datasheet

Page 43: CALIFORNIA STATE UNIVERSITY, NORTHRIDGE Smart Home

36

2. Design C Code

/* * GSM.c: simple test application * * This application configures UART 16550 to baud rate 9600. * PS7 UART (Zynq) is not initialized by this application, since * bootrom/bsp configures it to baud rate 115200 * * ------------------------------------------------ * | UART TYPE BAUD RATE | * ------------------------------------------------ * uartns550 9600 * uartlite Configurable only in HW design * ps7_uart 115200 (configured by bootrom/bsp) */ #include<stdio.h> #include"platform.h" #include"xgpiops.h" #include"xgpio.h" #defineledpin 7 #define PB 51 #define PIR 12 #define MQ 13 char data; /* #define XPAR_GPIOPS_NUM_INSTANCE 1 #define XPAR_PS7_GPIO_0_DEVICE_ID 0 #define XPAR_PS7_GPIO_0_BASEADDR 0XE000A000 #define XPAR_PS7_GPIO_0_HIGHADDR 0XE000AFFF */ //void print(char *str); intmain() { int m=0; u32ReadPin=0; // Read PB51 u32ReadMQ=0; // PIR value JF4 u32ReadPIR=0; // MIO 13 value JF1 init_platform(); // print("Hello World\n\r"); voiddelay(intdelay_time) // delay routine { intdelay_count;

Page 44: CALIFORNIA STATE UNIVERSITY, NORTHRIDGE Smart Home

37

for (delay_count = 0; delay_count<delay_time; delay_count++); } XGpioPsGpio; int Status; XGpioPs_Config *GPIOConfigPtr; GPIOConfigPtr = XGpioPs_LookupConfig(XPAR_PS7_GPIO_0_DEVICE_ID); Status = XGpioPs_CfgInitialize(&Gpio, GPIOConfigPtr, GPIOConfigPtr ->BaseAddr); if (Status != XST_SUCCESS) { return XST_FAILURE; } XGpioPs_SetDirectionPin(&Gpio, ledpin, 1); // set LED 7 out put XGpioPs_SetOutputEnablePin(&Gpio, ledpin, 1); // Enable LED XGpioPs_SetDirectionPin(&Gpio, PB, 0); // Set PB 51 As input XGpioPs_SetOutputEnablePin(&Gpio, PB, 1); // Enable PB 51 XGpioPs_SetDirectionPin(&Gpio, PIR, 0); // Set JF1 As PIR input XGpioPs_SetOutputEnablePin(&Gpio, PIR, 1); while(1) { ReadPin= XGpioPs_ReadPin(&Gpio, PB); ReadMQ= XGpioPs_ReadPin(&Gpio, MQ); ReadPIR= XGpioPs_ReadPin(&Gpio, PIR); // Read PIR value XGpioPs_WritePin(&Gpio, ledpin,0 ); // Write PIR value in LED if(ReadPIR==1) { XGpioPs_WritePin(&Gpio, ledpin,ReadPIR ); outbyte(0x41); //A outbyte(0x54); //T outbyte(0x2B); //+ outbyte(0x43); //C outbyte(0x4D); //M outbyte(0x47); //G outbyte(0x53); //S

Page 45: CALIFORNIA STATE UNIVERSITY, NORTHRIDGE Smart Home

38

outbyte(0x3D); //= outbyte(0x22); //" outbyte(0x2B); //+ outbyte(0x31); //1 outbyte(0x38); //8 outbyte(0x30); //0 outbyte(0x35); //5 outbyte(0x33); //3 outbyte(0x32); //2 outbyte(0x38); //8 outbyte(0x39); //9 outbyte(0x39); //9 outbyte(0x38); //8 outbyte(0x35); //5 outbyte(0x22); //" outbyte(0x0D); //\N outbyte(0x0A); //\R delay(2000000); outbyte(0x5A); //Z outbyte(0x59); //Y outbyte(0x42); //B outbyte(0x4F); //O outbyte(0x20); // SPACE outbyte(0x21); // ! outbyte(0x20); outbyte(0x20); outbyte(0x20); outbyte(0x20); // SPACE outbyte(0x49); // I outbyte(0x6E); // N outbyte(0x74); // T outbyte(0x72); // R outbyte(0x6F); // O outbyte(0x64); // D

Page 46: CALIFORNIA STATE UNIVERSITY, NORTHRIDGE Smart Home

39

outbyte(0x65); //E. outbyte(0x72); //R outbyte(0x20); // outbyte(0x49); // I outbyte(0x6E); // N outbyte(0x74); // T outbyte(0x68); //h outbyte(0x65); //e outbyte(0x20); // outbyte(0x48); // H outbyte(0x6f); // o outbyte(0x75); // u outbyte(0x73); //s outbyte(0x65); //e outbyte(0x21); // ! outbyte(0x21); // ! outbyte(0x21); // ! delay(2000000); delay(20000); outbyte(0x1A); //CTRL-Z delay(90000000); delay(90000000); delay(20000000); } if (ReadMQ == 1) {

Page 47: CALIFORNIA STATE UNIVERSITY, NORTHRIDGE Smart Home

40

outbyte(0x41); //A outbyte(0x54); //T outbyte(0x2B); //+ outbyte(0x43); //C outbyte(0x4D); //M outbyte(0x47); //G outbyte(0x53); //S outbyte(0x3D); //= outbyte(0x22); //" outbyte(0x2B); //+ outbyte(0x31); //1 outbyte(0x38); //8 outbyte(0x30); //0 outbyte(0x35); //5 outbyte(0x33); //3 outbyte(0x32); //2 outbyte(0x38); //8 outbyte(0x39); //9 outbyte(0x39); //9 outbyte(0x38); //8 outbyte(0x35); //5 outbyte(0x22); //" outbyte(0x0D); //\N outbyte(0x0A); //\R delay(2000000); outbyte(0x47); //G outbyte(0x61); //a outbyte(0x73); //s outbyte(0x20); // outbyte(0x44); //D outbyte(0x65); // outbyte(0x6e); // outbyte(0x7e); // outbyte(0x69); // outbyte(0x74); // outbyte(0x79); // outbyte(0x20); // outbyte(0x45); // outbyte(0x78); // outbyte(0x63 ); // outbyte(0x65); // outbyte(0x65); // outbyte(0x64); // outbyte(0x73); // outbyte(0x20); //

Page 48: CALIFORNIA STATE UNIVERSITY, NORTHRIDGE Smart Home

41

outbyte(0x53); // outbyte(0x74); // outbyte(0x61); // outbyte(0x6e); // outbyte(0x64); // outbyte(0x61); // outbyte(0x72); // outbyte(0x64); // outbyte(0x20); // outbyte(0x4c); // outbyte(0x69); // outbyte(0x6d); // outbyte(0x69); // outbyte(0x74); // outbyte(0x21);outbyte(0x21);outbyte(0x21); delay(2000000); delay(20000); outbyte(0x1A); //CTRL-Z delay(900000000); delay(90000000); } data = inbyte(); if (data=='+') data = inbyte(); if (data== 'C') data = inbyte(); if (data== 'M') data = inbyte(); if (data== 'T') data = inbyte(); if (data== 'I') { int h =0; for (h =0 ;h<8;h++) data = inbyte(); outbyte(0x41); //A outbyte(0x54); //T outbyte(0x2B); //+

Page 49: CALIFORNIA STATE UNIVERSITY, NORTHRIDGE Smart Home

42

outbyte(0x43); //C outbyte(0x4D); //M outbyte(0x47); //G outbyte(0x52); //R outbyte(0x3D); //= outbyte(data); // I outbyte(0x0D); //\N outbyte(0x0A); //\R delay(10); } data = inbyte(); if (data== 'O') data = inbyte(); if (data== 'n') data = inbyte(); if (data== '1') { outbyte(0x41); //A outbyte(0x54); //T outbyte(0x2B); //+ outbyte(0x43); //C outbyte(0x4D); //M outbyte(0x47); //G outbyte(0x53); //S outbyte(0x3D); //= outbyte(0x22); //" outbyte(0x2B); //+ outbyte(0x31); //1 outbyte(0x38); //8 outbyte(0x30); //0 outbyte(0x35); //5 outbyte(0x33); //3 outbyte(0x32); //2 outbyte(0x38); //8 outbyte(0x39); //9 outbyte(0x39); //9 outbyte(0x38); //8 outbyte(0x35); //5 outbyte(0x22); //" outbyte(0x0D); //\N outbyte(0x0A); //\R delay(200); outbyte(0x4F); //Z

Page 50: CALIFORNIA STATE UNIVERSITY, NORTHRIDGE Smart Home

43

outbyte(0x59); //Y outbyte(0x42); //B outbyte(0x4F); //O Print ("Living room light is on"); delay(200); outbyte(0x1A); //CTRL-Z } } cleanup_platform(); return 0; }

Page 51: CALIFORNIA STATE UNIVERSITY, NORTHRIDGE Smart Home

44

3. VHDL code

Generated by Xilinx Vivado

-------------------------------------------------------------------------------

-- System_1_stub.vhd

-------------------------------------------------------------------------------

library IEEE;

use IEEE.STD_LOGIC_1164.ALL;

library UNISIM;

use UNISIM.VCOMPONENTS.ALL;

entity System_1_stub is

port (

processing_system7_0_MIO :inoutstd_logic_vector(53 downto 0);

processing_system7_0_PS_SRSTB_pin : in std_logic;

processing_system7_0_PS_CLK_pin : in std_logic;

processing_system7_0_PS_PORB_pin : in std_logic;

processing_system7_0_DDR_Clk :inoutstd_logic;

processing_system7_0_DDR_Clk_n :inoutstd_logic;

processing_system7_0_DDR_CKE :inoutstd_logic;

processing_system7_0_DDR_CS_n :inoutstd_logic;

processing_system7_0_DDR_RAS_n :inoutstd_logic;

processing_system7_0_DDR_CAS_n :inoutstd_logic;

processing_system7_0_DDR_WEB_pin : out std_logic;

processing_system7_0_DDR_BankAddr :inoutstd_logic_vector(2 downto 0);

processing_system7_0_DDR_Addr :inoutstd_logic_vector(14 downto 0);

processing_system7_0_DDR_ODT :inoutstd_logic;

processing_system7_0_DDR_DRSTB :inoutstd_logic;

processing_system7_0_DDR_DQ :inoutstd_logic_vector(31 downto 0);

processing_system7_0_DDR_DM :inoutstd_logic_vector(3 downto 0);

processing_system7_0_DDR_DQS :inoutstd_logic_vector(3 downto 0);

processing_system7_0_DDR_DQS_n :inoutstd_logic_vector(3 downto 0);

processing_system7_0_DDR_VRN :inoutstd_logic;

processing_system7_0_DDR_VRP :inoutstd_logic;

axi_gpio_0_GPIO_IO_pin :inoutstd_logic;

processing_system7_0_GPIO_pin :inoutstd_logic

);

end System_1_stub;

Page 52: CALIFORNIA STATE UNIVERSITY, NORTHRIDGE Smart Home

45

architecture STRUCTURE of System_1_stub is

component System_1 is

port (

processing_system7_0_MIO :inoutstd_logic_vector(53 downto 0);

processing_system7_0_PS_SRSTB_pin : in std_logic;

processing_system7_0_PS_CLK_pin : in std_logic;

processing_system7_0_PS_PORB_pin : in std_logic;

processing_system7_0_DDR_Clk :inoutstd_logic;

processing_system7_0_DDR_Clk_n :inoutstd_logic;

processing_system7_0_DDR_CKE :inoutstd_logic;

processing_system7_0_DDR_CS_n :inoutstd_logic;

processing_system7_0_DDR_RAS_n :inoutstd_logic;

processing_system7_0_DDR_CAS_n :inoutstd_logic;

processing_system7_0_DDR_WEB_pin : out std_logic;

processing_system7_0_DDR_BankAddr :inoutstd_logic_vector(2 downto 0);

processing_system7_0_DDR_Addr :inoutstd_logic_vector(14 downto 0);

processing_system7_0_DDR_ODT :inoutstd_logic;

processing_system7_0_DDR_DRSTB :inoutstd_logic;

processing_system7_0_DDR_DQ :inoutstd_logic_vector(31 downto 0);

processing_system7_0_DDR_DM :inoutstd_logic_vector(3 downto 0);

processing_system7_0_DDR_DQS :inoutstd_logic_vector(3 downto 0);

processing_system7_0_DDR_DQS_n :inoutstd_logic_vector(3 downto 0);

processing_system7_0_DDR_VRN :inoutstd_logic;

processing_system7_0_DDR_VRP :inoutstd_logic;

axi_gpio_0_GPIO_IO_pin :inoutstd_logic;

processing_system7_0_GPIO_pin :inoutstd_logic

);

end component;

attribute BOX_TYPE : STRING;

attribute BOX_TYPE of System_1 : component is "user_black_box";

begin

System_1_i : System_1

port map (

processing_system7_0_MIO => processing_system7_0_MIO,

processing_system7_0_PS_SRSTB_pin => processing_system7_0_PS_SRSTB_pin,

processing_system7_0_PS_CLK_pin => processing_system7_0_PS_CLK_pin,

processing_system7_0_PS_PORB_pin => processing_system7_0_PS_PORB_pin,

processing_system7_0_DDR_Clk => processing_system7_0_DDR_Clk,

processing_system7_0_DDR_Clk_n => processing_system7_0_DDR_Clk_n,

processing_system7_0_DDR_CKE => processing_system7_0_DDR_CKE,

processing_system7_0_DDR_CS_n => processing_system7_0_DDR_CS_n,

Page 53: CALIFORNIA STATE UNIVERSITY, NORTHRIDGE Smart Home

46

processing_system7_0_DDR_RAS_n => processing_system7_0_DDR_RAS_n,

processing_system7_0_DDR_CAS_n => processing_system7_0_DDR_CAS_n,

processing_system7_0_DDR_WEB_pin => processing_system7_0_DDR_WEB_pin,

processing_system7_0_DDR_BankAddr =>

processing_system7_0_DDR_BankAddr,

processing_system7_0_DDR_Addr => processing_system7_0_DDR_Addr,

processing_system7_0_DDR_ODT => processing_system7_0_DDR_ODT,

processing_system7_0_DDR_DRSTB => processing_system7_0_DDR_DRSTB,

processing_system7_0_DDR_DQ => processing_system7_0_DDR_DQ,

processing_system7_0_DDR_DM => processing_system7_0_DDR_DM,

processing_system7_0_DDR_DQS => processing_system7_0_DDR_DQS,

processing_system7_0_DDR_DQS_n => processing_system7_0_DDR_DQS_n,

processing_system7_0_DDR_VRN => processing_system7_0_DDR_VRN,

processing_system7_0_DDR_VRP => processing_system7_0_DDR_VRP,

axi_gpio_0_GPIO_IO_pin => axi_gpio_0_GPIO_IO_pin,

processing_system7_0_GPIO_pin => processing_system7_0_GPIO_pin

);

end architecture STRUCTURE;