You are on page 1of 18

ABSTRACT

GSM Based Home Security System is a simple microcontroller based embedded system with features
integrated for enabling warning for smoke, fire and human intruder .Smoke, fire and human presence are
detected using respective sensors. Microcontroller continuously monitors sensor status.The outputs are
displayed and also sms alert to a particular number is done.

1
COMPONENTS USED

STM32F103R8 Microcontroller

STM Development Board

GSM SIM900 Module

PIR Sensor

Gas Detector

16x2 LCD Display

2
BLOCK DIAGRAM

3
HARDWARE DETAILS
STM32F103R8

ARM 32 bit Cortex M3 CPU Core


72MHz max. freq
Single-cycle multiplication and hardware division
64 or 128 Kbytes of Flash memory
20 Kbytes of SRAM
Clock, reset and supply management
2.0 to 3.6 V application supply and I/Os
POR, PDR, and programmable voltage detector (PVD)
4-to-16 MHz crystal oscillator
Internal 8 MHz factory-trimmed RC
Internal 40 kHz RC
PLL for CPU clock
32 kHz oscillator for RTC with calibration
Low-power
Sleep, Stop and Standby modes
VBAT supply for RTC and backup registers
2 x 12-bit, A/D converters (up to 16 channels)
Conversion range: 0 to 3.6 V
Dual-sample and hold capability
Temperature sensor
DMA
7-channel DMA controller
Peripherals supported: timers, ADC, SPIs, I2 Cs and USARTs
Up to 80 fast I/O ports
26/37/51/80 I/Os, all mappable on 16 external interrupt vectors and almost all 5
V-tolerant
7 timers
Three 16-bit timers
16-bit, motor control PWM timer with dead-time generation and emergency stop
2 watchdog timers
Up to 9 communication interfaces
Up to 2 x I2 C interfaces
Up to 3 USARTs
Up to 2 SPIs (18 Mbit/s)
CAN interface
USB 2.0 full-speed interface
16 I/Os in each GPIO Port
Output states: push-pull or open drain + pull-up/down
Output data from
output data register (GPIOx_ODR) or peripheral (alternate function output)

4
Speed selection for each I/O
Input states: floating, pull-up/down, analog
Input data to input data register (GPIOx_IDR) or peripheral (alternate function input)
Each port bit of the general-purpose I/O (GPIO) ports can be individually configured
Supported Modes
Input floating
Input pull-up
Input-pull-down
Analog
Output open-drain with pull-up or pull-down capability
Output push-pull with pull-up or pull-down capability
Alternate function push-pull with pull-up or pull-down capability
Alternate function open-drain with pull-up or pull-down capability
During and just after reset, the alternate functions are not active and the I/O ports are
configured in input floating mode

GPIO DETAILS CONCERNED

The STM32F103xx microcontroller has 5 general purpose input/output (GPIO) ports named Port A, B, C,
D and F. Each port can have up to 16 pins, and each port has associated with it the following set of
registers:

Port configuration register low (GPIOx_CRL) (x=A..E)


Port configuration register high (GPIOx_CRH) (x=A..E)
Port input data register (GPIOx_IDR) (x=A..E)
Port output data register (GPIOx_ODR) (x=A..E)
Port bit set/reset register (GPIOx_BSRR) (x=A..E)
Port bit reset register (GPIOx_BRR) (x=A..E)

GPIO REGISTERS

Port configuration register low (GPIOx_CRL) (x=A..G)

Address offset: 0x00


Reset value: 0x4444 4444

CNFy[1:0]: Port x configuration bits (y= 0 .. 7)


These bits are written by software to configure the corresponding I/O port.

5
In input mode (MODE[1:0]=00):
00: Analog mode
01: Floating input (reset state)
10: Input with pull-up / pull-down
11: Reserved
In output mode (MODE[1:0] > 00):
00: General purpose output push-pull
01: General purpose output Open-drain
10: Alternate function output Push-pull
11: Alternate function output Open-drain
MODEy[1:0]: Port x mode bits (y= 0 .. 7)
These bits are written by software to configure the corresponding I/O port.
00: Input mode (reset state)
01: Output mode, max speed 10 MHz.
10: Output mode, max speed 2 MHz.
11: Output mode, max speed 50 MHz.

Port configuration register high (GPIOx_CRH) (x=A..G)


Address offset: 0x04
Reset value: 0x4444 4444

CNFy[1:0]: Port x configuration bits (y= 0 .. 7)


These bits are written by software to configure the corresponding I/O port.
In input mode (MODE[1:0]=00):
00: Analog mode
01: Floating input (reset state)
10: Input with pull-up / pull-down
11: Reserved
In output mode (MODE[1:0] > 00):
00: General purpose output push-pull
01: General purpose output Open-drain
10: Alternate function output Push-pull
11: Alternate function output Open-drain

MODEy[1:0]: Port x mode bits (y= 0 .. 7)


These bits are written by software to configure the corresponding I/O port.
00: Input mode (reset state)
01: Output mode, max speed 10 MHz.
10: Output mode, max speed 2 MHz.
11: Output mode, max speed 50 MHz.

6
Port input data register (GPIOx_IDR) (x=A..G)
Address offset: 0x08h
Reset value: 0x0000 XXXX

Bits 31:16 Reserved, always read as 0.


Bits 15:0 IDRy[15:0]: Port input data (y= 0 .. 15)
These bits are read only and can be accessed in Word mode only. They contain the input
value of the corresponding I/O port.

Port output data register (GPIOx_ODR) (x=A..G)


Address offset: 0x0C
Reset value: 0x0000 0000

Bits 31:16 Reserved, always read as 0.


Bits 15:0 ODRy[15:0]: Port output data (y= 0 .. 15)
These bits can be read and written by software and can be accessed in Word mode only.
Note: For atomic bit set/reset, the ODR bits can be individually set and cleared by writing to
the GPIOx_BSRR register (x = A .. G)

Port bit set/reset register (GPIOx_BSRR) (x=A..G)


Address offset: 0x10
Reset value: 0x0000 0000

Bits 31:16 BRy: Port x Reset bit y (y= 0 .. 15)


These bits are write-only and can be accessed in Word mode only.
0: No action on the corresponding ODRx bit
1: Reset the corresponding ODRx bit
Note: If both BSx and BRx are set, BSx has priority.

7
Bits 15:0 BSy: Port x Set bit y (y= 0 .. 15)
These bits are write-only and can be accessed in Word mode only.
0: No action on the corresponding ODRx bit
1: Set the corresponding ODRx bit

BSRR register allows us to set /clear a particular pin(or groups of pins) while preserving the state of the
rest of the pins on a GPIO peripheral as fast as possible without resorting to slower read-modify-
write(RMW)accesses.

So if I want to set PC8 independent of all other pins on GPIOC I could use

GPIOC->BSRR=(1<<8); or

GPIOC-BSRR=0x00000100;//(0x00000000000000000000000100000000)

To clear pin PC8 independent of all other pins on GPIOC you could use GPIOC->BSRR=0x01000000;Or
GPIOC->BSRR=(1<<24);

Notice both scenarios used a simple assignment operator = (atomic) rather than an |= or an &= which
denote RMW accesses.So to clear pin PC8 independent of all other pins on GPIOC you could use
GPIOC->BRR=(1<<8);

Port bit reset register (GPIOx_BRR) (x=A..G)


Address offset: 0x14
Reset value: 0x0000 0000

Bits 31:16 Reserved


Bits 15:0 BRy: Port x Reset bit y (y= 0 .. 15)
These bits are write-only and can be accessed in Word mode only.
0: No action on the corresponding ODRx bit
1: Reset the corresponding ODRx bit

GSM SIM900 MODEM

GSM/GPRS Modem-RS232 is built with Dual Band GSM/GPRS engine- SIM900A, works on
frequencies 900/ 1800 MHz. The Modem is coming with RS232 interface, which allows you connect PC
as well as microcontroller with RS232 Chip(MAX232). The baud rate is configurable from 9600-115200
through AT command. The GSM/GPRS Modem is having internal TCP/IP stack to enable you to connect
with internet via GPRS. It is suitable for SMS, Voice as well as DATA transfer application in M2M
interface. The onboard Regulated Power supply allows you to connect wide range unregulated power

8
supply . Using this modem, you can make audio calls, SMS, Read SMS, attend the incoming calls and
internet ect through simple AT commands.

Features
Dual band GSM/GPRS 900/1800MHz.
Configurable baud rate
SIM card holder
Built in network status LED
Inbuilt powerful TCP/IP protocol stack for internet data transfer over GPRS
Applications Access control devices
Supply chain management
Operating voltage +12v DC

1. Unlike mobile phones, a GSM modem doesnt have a keypad and display to interact with. It just
accepts certain commands through a serial interface and acknowledges for those. These
commands are called as AT commands. There are a list of AT commands to instruct the modem
to perform its functions. Every command starts with "AT". Thats why they are called as AT
commands. AT stands for attention. In our simple project, the program waits for the mobile
number to be entered through the keyboard. When a ten digit mobile number is provided, the
program instructs the modem to send the text message using a sequence of AT commands.

TESTING GSM

The GSM modem can be tested by connecting it with a PC. The modem is equipped with a RS232 cable.
Just use a Serial to USB converter and connect it with the PC. Now you can proceed with sending the
commands to the modem using any serial communication program like Hyperterminal, minicom etc.
Ensure the serial parameters are configured to 8N1 and the baudrate is set to 9600bps. For each
command you send the modem acknowledges with a message. Example: Just try sending "AT" to the

9
modem. It sends back a result code "OK" which states that the modem is responding. If its not working
fine, it sends "ERROR".

AT commands used in our project


AT (to get status of gsm;it will respond by an OK msg)
AT+IPSR (for setting the baud rate)
AT+CMGF=1(for message text mode)
AT+CMGS=+91xxxxxxxx50 (for sending sms to a mobile no)
ATD +91xxxxxxxx50; (for making a call)

1. Power ON reset switch.


2. Sliding SIM holder.
3. Network,Power and Status indicator.
4. MIC and Speaker Socket.
5. Power supply 12V/2A

10
6. FRC Connector.
7. RS232 header.
8. DC to DC Converter (29302WU IC).
9. ESD Protection enabled.
10. SIM900A stack on header.
11. Stub antenna with SMA connector.
12.General GPIO SIM900A

PIR SENSOR

PIR sensors allow you to sense motion, usually used to detect whether a human has moved in or out of
the sensors range. They are often referred to as PIR, "Passive Infrared", "Piezoelectric", or "IR motion"
sensors PIRs are basically made of a piezoelectric sensor, which can detect levels of infrared radiation.
PIR sensor detects the motion inside home if there is any motion in its range . The signal is sent to
microcontroller which has two actions, the first one is to send SMS message to the owner and the other
is to display the status on lcd.

TEMPERATURE SENSOR

The LM35 series are precision integrated-circuit temperature sensors, whose output voltage is linearly
proportional to the Celsius (Centigrade) temperature. The Vs pin is connected to 5V. (According to the
data sheet this maybe 4 to 20 V).

In the event of fire, the sensor reads a very high temperature, outputs the very high digital value to the
microprocessor (with the help of comparator) which is then compared to a predefined value to know if the
corresponding flag needs to be set. The threshold temperature is set as 50C.One can use ADC for which
corresponding ADC output value is ((50*10mv)/5)*255 corresponding to 0x1E. The maximum
temperature that can be sensed is 150C and gives an output of 1.5V.

Smoke Sensor

11
We use the Gas sensor MQ2 as the smoke detector .They are used in gas leakage detecting equipments in
households and industries, are suitable for detecting of LPG, i-butane, propane, methane, alcohol,
hydrogen, smoke. The enveloped MQ-2 has 6 pin, 4 of them are used to fetch signals, and other two are
used for providing heating current.

The output is connected to a comparator, which compares the voltage to a value that can be
adjusted.Thus,the sensitivity levels of the sensor can easily be adjusted to suit the surroundings(especially
useful when it needs to be used in a naturally smoky environment). When the voltage exceeds this preset
value, a high output is given to the microcontroller.

16x2 LCD DISPLAY

A 16x2 LCD means it can display 16 characters per line and there are 2 such lines. In this LCD each
character is displayed in 5x7 pixel matrix. This LCD has two registers, namely, Command and Data.

The command register stores the command instructions given to the LCD. A command is an instruction
given to LCD to do a predefined task like initializing it, clearing its screen, setting the cursor position,
controlling display etc. The data register stores the data to be displayed on the LCD. The data is the
ASCII value of the character to be displayed on the LCD.

Pin Description
Pin No: Function Name
1 Ground(0V) Ground
2 Supply voltage-5V(4.7V-5.3V) VCC
3 Contrast adjustment: variable resistance VEE
4 0-Selects command register Register select
1-Selects data register
5 0-Write to register Read/write
1-Read from register
6 Sends data when a high to low pulse is Enable
given
7
8
9
10 8 Data pins DB0-DB7
11
12
13
14
15 Backlight VCC(5V) Led+
16 Backlight Ground(0V) Led-
LCD Commands

12
There are some preset commands instructions in LCD, which we need to send to LCD through some
microcontroller. Some important command instructions are given below:
HEX CODE COMMAND TO LCD
0F LCD ON ,cursor ON
01 Clear display screen
02 Return home
04 Decrement cursor (shift cursor to left)
06 Increment cursor(shift cursor to right)
05 Shift display right
07 Shift display left
0E Display ON ,cursor blinking
80 Force cursor to beginning of line
C0 Force cursor to beginning of second line
38 2 lines and 5x7 matrix
83 Cursor line 1 position 3
3C Activate second line
08 Display OFF,cursor OFF
C1 Jump to second line position 1
0C Display ON,cursor OFF
C1 Jump to second line position 1

13
BLOCK DIAGRAM

14
WORKING
This project consist of three sensors namely a gas sensor(), a temperature sensor(), and a PIR sensor().
Here the temperature sensor has a resolution of 0.1V/deg Celsius. This sensor is connected to a
comparator which is matched with the normal room temperature for the optimal operation. The PIR
sensor which detects the motion from the surroundings trigger a pulse onto the microcontroller and it
will give an alarm and a message according to the mode provided. The gas sensor however is directly
connected on to the microcontroller which detects the smoke, lpg etc will give a corresponding output
as per the mode. Programming of the controller was done in embedded c.Simulation and debugging
done in Keil uvision 5.

INTEGRATION AND TESTING

In order to reduce the task of debugging piled on errors at the end, the whole system was split into various
modules. The modules were made as small as possible and were integrated gradually after individual
testing

Testing of the LCD:

Firstly, the working of LCD was ensured by connecting it alone to the microcontroller which was
loaded with the program to display a string. After the successful testing of the former arrangement, we
loaded the program for the menu display to the same setup. The working of the menu display was tested
and verified.

Testing of the sensors and buzzer:

The working of each sensor was ensured individually before including it to the main setup. The
PIR and the smoke sensor was tested by loading program to sound the buzzer when the respective sensor
output is high. The smoke sensor was tested using a cigarette lighter, the PIR using gestures and the
temperature sensor using soldering iron. The output of the temperature sensor was given to the
microcontroller through an ADC. When the ADC output was above a threshold, the buzzer was made to
sound.

Testing the GSM module:

The working of the GSM module was verified with the help of the software Hyperterminal. Later
it was connected to the microcontroller and program was loaded to send messages to the preprogrammed
numbers. The proper working was verified.

15
The modules were combined one by one. The sensor unit and the GSM module were put together.
Thus we could check the sending of the SMS on detection of an intruder, smoke or fire. Finally the LCD
module and the GSM-sensor module were combined and the proper functioning of the system was
verified both in the armed as well as in the disarmed mode.

A number of errors and problems came up, both in the hardware and software domains, when various
modules were integrated. It consumed a lot of time and effort to debug them. After eliminating all the
errors, the code size of the program was shortened to the extent possible.

16
3 2 3 2 3 2
gnd +Vs gnd +Vs gnd +Vs

LM35

o
o
o

1
1
1

50
49
46
45
44
43
42
41
23
22
21
20
16
17
15
30 61

PA9
PA8
PA4
PA2
PA3
PA1

PA 7
PA 6
PA 5
PB1 1 PB8

PA13
PA12
PA11
PA10

PA 15
PA 14
33 31
PB12 VSS_1
34 18
PB13 VSS_4
35 14
PB14 PA 0-WK UP
36 13
PB15 VddA
55 12
PB3 Vssa
52 54
PC 11 PD2
38 53
PC8 PC 12
56 26
PB4 PB0
40 59
PC9 PB7
32 7
Vdd_1 NRST
58 6
PB6 PD1-OS C_OUT
29 5
PB1 0 PD0-OS C_IN
4
57 PC15-OSC 32_OUT

ST M 3 2 F1 0 3 R8
PB5 3
51 PC 14-O SC 32_IN
PC 10 2
47 PC13-TAMPER-RTC
Vss_2

17
1
19 Vbat
VDD_4 62
PB9

Vdd_2
BOO T0
PC7
PC6
PC5
PC4
PC3
PC2
PC1
PC0
Vss_3
Vdd_3

PB2
PB1

9
8

48
60
39
37
25
24
11
10
28
63
27
64
U1
SCHEMATIC

RESISTOR VAR

1
GND
3
VEE
U2

2
VCC
VCC
R1

4
RS
5
RW
6
E

7
D0
8
D1
9
D2
10
D3
11
D4
12
D5
13
D6
16X2 ALPHA NUMERIC DISPLAY

14
D7
CONCLUSION

The embedded system was setup on the STM development board.The ability of the system to detect high
temperature,smoke and human intervention was verified.The system produced a display output as well as
a message to specified mobile number on alert situations.

Through this project we got familiarized of various interfaces with an ARM microcontroller.We have
done integration of GSM modem using serial communication ports.This system can stand as a model on
which further enhanced features have to be set for producing as a consumer product.This features include
design to an easily portable system and power efficiency since this system has to be powered throughout
its operation time.Further addons like determining the approximate location of intruder,high peak alarm
even at absolute small gas leak,ability to prevent gas explosion inside a kitchen can all make the system
smarter and easily acceptable.

18

You might also like