Você está na página 1de 42

ABSTRACT

The aim of the project to design the SMS based vehicle locker security system. M-vehicle
has become one of the most familiar vehicle service providing technologies in different western
countries. Now-a-days billions of inhabitants are within a network through mobile network
coverage. But in the commercial vehicle like two wheeler. This technology has not been adopted
broadly yet. SMS based m-vehicle system has been proposed which is able to provide several
essential vehicle services only sending SMS to vehicle server from any remote location. This
proposed system is divided into five major phases: interfacing module, SMS technology
adoption module, SMS vehicle registration module, service generation module, and data failover
module. This system facilitates vehicle customers by providing four major services like balance
enquiry , balance transfer between authenticated customers, DPS payment and bill payment
without going to vehicle physically and save their precious time. At least, after evaluating each
module of this developed system a satisfactory accuracy rate 93.18 % is obtained.
BLOCK DIAGRAM
INTRODUCTION
According to the report published by National Crime Records Bureau (NCRB), in the
year 2011 alone 122,367 two wheeler vehicles were stolen in India. Out of which only 32,826
vehicles were recovered. Typically, two-wheelers are stolen right off streets or apartment parking
lots. By the time the police are alerted (which could be a few hours since the theft), the vehicles
are made underground leaving almost no traces. Later the vehicles are either dismantled or sold
in neighboring states/districts at throw-away prices, leaving the owner and police helpless in
bringing the thief to book. The story remains same for rest of the world. The only possible way
out of this problem is implementation of security system in the vehicle. The security system
should be capable of performing reasonably well even in unfavorable conditions to meet the
desired level of security The price of the security system should be reasonably low or else the
automobile manufacturers cannot implement such a system, as it will increase the overall cost of
the vehicle by a big margin. If the design of the security system is such that it is compatible with
most of the brands and classes of vehicles then it helps reducing the NRE cost. The overall
power consumption should be less as the source of supply for the security system is the 12V
battery of the vehicle. Keeping these requirements and constraints in mind we propose this new
design of Two Wheeler Vehicle Security System (TWVSS).
DESCRIPTION OF PROPOSED TWO WHEELER VEHICLE SECURITY SYSTEM
An overview of the complete system is described in this section before detailing the
specifications and the necessity for each module in the system. The general view of operation of
the proposed security system is shown in fig.ure. The conventional handle locking system is
replaced by a handle lock operated by servo motor and controlled by the Remote Keyless System
(RKS) . RKS has a transmitter and a receiver module. The receiver module is installed on the
vehicle and the owner of the vehicle has the remote (transmitter module). The RKS remote could
be used to lock/unlock the locking system (handle lock, fuel lock and rear wheel lock), switch
ON/OFF the engine and to turn off the alarm. Fuel lock replaces the knob at the nozzle of fuel
tank. Rear wheel lock is used to jam the sprocket of the wheel.

Figure: General view of TWVSS operation


The vehicle owner’s cell phone with the registered Subscriber Identity Module (SIM)
number acts as the master key of the security system. It is given higher priority over RKS and
hence it can override the instructions from RKS. A Short Message Service (SMS) is sent to the
registered SIM via the Global System for Mobile communication (GSM) module whenever the
vehicle is unlocked using the RKS remote. Owner can in turn send a SMS to initiate the locking
sequence, if he/she feels an unauthorized person has unlocked the vehicle [13]. Global
Positioning System (GPS) module is used to track the location and monitor the speed of the
vehicle. Piezoelectric sensors are used as vibration sensors to detect any tampering with the
vehicle. Two sensitivity levels are chosen so as to nullify the chance of false alerting [20]. The
owner is alerted by an SMS and loud alarm is activated, if there is
any physical tampering with the vehicle or if the vehicle has been moved from the place where it
was parked (>15m). The owner can, anytime, request the security system of the vehicle for its
status by sending an SMS.
HARDWARE REQUIREMENTS
Remote Keyless System (RKS)
RKS module is designed to operate at a frequency of 433 MHz with a half duplex
communication link. The Remote consists of a 433 MHz transmitter, encoder, power supply and
a simple loop antenna. The receiver module consists of 433 MHz receiver, decoder, power
supply and a simple loop antenna. As shown in fig. 2, the receiver module is interfaced with the
MCU. As shown in fig. 3, the remote consists of four buttons, each associated with different
operation. The chosen pair of encoder and decoder should have same number of addresses and
data format. We used 4 bit hot code to represent each button. The 12 bit parallel data is encoded
to serial data for transmission through RF transmitter. These 12 bits are divided into 8 address
bits and 4 hot code bits. This 8 bit address data is unique to every pair of receiver and transmitter
module as stated earlier. The received serial data is decoded to parallel data. The 8 bit address
data is compared with the local address data three times continuously. If these two address bits
matches, the 4 bit hot code is made available to the MCU. For our design (under standard
conditions), we obtained maximum communication range of approx. 100m, justifying the use of
low cost simple loop antenna.

 PIC 16F877A IC
 LCD
 MAX 232 IC
 3310 MOBILE(GSM 900)
 CRYSTAL OSCILLATOR
 LED

SOFTWARE REQUIRMENTS

 PIC C COMPILER
 PIC IC PROGRAMMER
MICROCONTROLLER (PIC16F87XA)

High Performance RISC CPU:


 Only 35 single word instructions to learn
 All single cycle instructions except for program branches, which are two-cycle
 Operating speed: DC - 20 MHz clock input DC - 200 ns instruction cycle
 Up to 8K x 14 words of FLASH Program Memory, Up to 368 x 8 bytes of Data Memory
(RAM), Up to 256 x 8 bytes of EEPROM Data Memory
 Pinout compatible to other 28-pin or 40/44-pin PIC16CXXX and PIC16FXXX
microcontrollers
Peripheral Features:
 Timer0: 8-bit timer/counter with 8-bit prescaler
 Timer1: 16-bit timer/counter with prescaler, can be incremented during SLEEP via
external crystal/clock
 Timer2: 8-bit timer/counter with 8-bit period register, prescaler and postscaler
 Two Capture, Compare, PWM modules
 Capture is 16-bit, max. resolution is 12.5 ns
 Compare is 16-bit, max. resolution is 200 ns
 PWM max. resolution is 10-bit
 Synchronous Serial Port (SSP) with SPI™ Master mode) and I2C™ (Master/Slave)
 Universal Synchronous Asynchronous Receiver Transmitter (USART/SCI) with 9-bit
address detection
 Parallel Slave Port (PSP) 8-bits wide, with external RD, WR and CS controls (40/44-pin
only)
 Brown-out detection circuitry for Brown-out Reset (BOR)
Analog Features:
 10-bit, up to 8 channel Analog-to-Digital Converter (A/D)
 Brown-out Reset (BOR)
 Analog Comparator module with:
 Two analog comparators
 Programmable on-chip voltage reference (VREF) module
 Programmable input multiplexing from device inputs and internal voltage
reference Comparator outputs are externally accessible
Special Microcontroller Features:
 100,000 erase/write cycle Enhanced FLASH program memory typical
 1,000,000 erase/write cycle Data EEPROM memory typical
 Data EEPROM Retention > 40 years
 Self-reprogrammable under software contro
 In-Circuit Serial Programming™ (ICSP™) via two pins
 Single supply 5V In-Circuit Serial Programming
 Watchdog Timer (WDT) with its own on-chip RC oscillator for reliable operation
 Programmable code protection
 Power saving SLEEP mode
 Selectable oscillator options
 In-Circuit Debug (ICD) via two pins
CMOS Technology:
 Low power, high speed FLASH/EEPROM technology
• Fully static design
 Wide operating voltage range (2.0V to 5.5V)
 Commercial and Industrial temperature ranges
 Low power consumption
Pin Diagram
BLOCK DIAGRAM
DEVICE OVERVIEW

This document contains device specific information about the following devices:

 PIC16F873A
 PIC16F874A
 PIC16F876A
 PIC16F877A

PIC16F873A/876A devices are available only in 28-pinpackages, while PIC16F874A/877A


devices are available in 0-pin and 44-pin packages. All devices in the PIC16F87XA family share
common architecture, with the following differences:

 the PIC16F873A and PIC16F876A have one-half of the total on-chip memory of the
PIC16F874A and PIC16F877A
 the 28-pin devices have three I/O ports, while the 40/44-pin devices have five
 the 28-pin devices have 14 interrupts, while the 40/44-pin devices have 15
 the 28-pin devices have five A/D input channels, while the 40/44-pin devices have eight
 the Parallel Slave Port is implemented only on the 40/44-pin devices

Block diagrams of the PIC16F873A/876A and PIC16F874A/877A devices are provided in


Figure . The Additional information may be found in the PICmicro™ Mid-Range Reference
Manual (DS33023), which may be obtained from your local Microchip Sales Representative or
downloaded from the Microchip website. The Reference Manual should be considered a
Complementary document to this data sheet, and is highly recommended reading for a better
understanding of the device architecture and operation of the peripheral modules
Pin Descriptions
VCC Digital supply voltage.
GND Ground.
Port A (PA7..PA0) Port A serves as the analog inputs to the A/D Converter. Port A also serves
as an 8-bit bi-directional I/O port, if the A/D Converter is not used. Port pins can provide internal
pull-up resistors (selected for each bit). The Port A output buffers have symmetrical drive
characteristics with both high sink and source capability. When pins PA0 to PA7 are used as
inputs and are externally pulled low, they will source current if the internal pull-up resistors are
activated. The Port A pins are tri-stated when a reset condition becomes active, even if the clock
is not running.
Port B (PB7..PB0) Port B is an 8-bit bi-directional I/O port with internal pull-up resistors
(selected for each bit). The Port B output buffers have symmetrical drive characteristics with
both high sink and source capability. As inputs, Port B pins that are externally pulled low will
source current if the pull-up resistors are activated. The Port B pins are tri-stated when a reset
condition becomes active, even if the clock is not running. Port B also serves the functions of
various special features of the ATmega16
Port C (PC7..PC0) Port C is an 8-bit bi-directional I/O port with internal pull-up resistors
(selected for each bit). The Port C output buffers have symmetrical drive characteristics with
both high sink and source capability. As inputs, Port C pins that are externally pulled low will
source current if the pull-up resistors are activated. The Port C pins are tri-stated when a reset
condition becomes active, even if the clock is not running. If the JTAG interface is enabled, the
pull-up resistors on pins PC5(TDI), PC3(TMS) and PC2(TCK) will be activated even if a reset
occurs. Port C also serves the functions of the JTAG interface and other special features of the
ATmega16.
Port D (PD7..PD0) Port D is an 8-bit bi-directional I/O port with internal pull-up resistors
(selected for each bit). The Port D output buffers have symmetrical drive characteristics with
both high sink and source capability. As inputs, Port D pins that are externally pulled low will
source current if the pull-up resistors are activated. The Port D pins are tri-stated when a reset
condition becomes active, even if the clock is not running. Port D also serves the functions of
various special features of the ATmega16.
RESET Reset Input. A low level on this pin for longer than the minimum pulse length will
generate a reset, even if the clock is not running. The minimum pulse length is given. Shorter
pulses are not guaranteed to generate a reset.
XTAL1 Input to the inverting Oscillator amplifier and input to the internal clock operating
circuit.
XTAL2 Output from the inverting Oscillator amplifier. AVCC is the supply voltage pin for Port
A and the A/D Converter. It should be externally connected to VCC, even if the ADC is not
used. If the ADC is used, it should be connected to VCC through a low-pass filter. AREF is the
analog reference pin for the A/D Converter.
General Purpose Register File
The Register File is optimized for the AVR Enhanced RISC instruction set. In order to achieve
the required performance and flexibility, the following input/output schemes are supported by
the Register File:
• One 8-bit output operand and one 8-bit result input
• Two 8-bit output operands and one 8-bit result input
• Two 8-bit output operands and one 16-bit result input
• One 16-bit output operand and one 16-bit result input
LCD

LCD (Liquid Crystal Display) screen is an electronic display module and find a wide
range of applications. A 16x2 LCD display is very basic module and is very commonly used in
various devices and circuits. These modules are preferred over seven segments and other multi
segment LEDs. The reasons being: LCDs are economical; easily programmable; have no
limitation of displaying special & even custom characters (unlike in seven
segments), animations and so on.
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. Click to learn
more about internal structure of a LCD.

Pin Diagram:
Pin Description:

Pin No Function Name


1 Ground (0V) Ground
2 Supply voltage; 5V (4.7V – 5.3V) Vcc
Contrast adjustment; through a
3 VEE
variable resistor
Selects command register when low; Register
4
and data register when high Select
Low to write to the register; High to Read/wri
5
read from the register te
Sends data to data pins when a high to
6 Enable
low pulse is given
7 DB0
8 DB1
9 DB2
10 DB3
8-bit data pins
11 DB4
12 DB5
13 DB6
14 DB7
15 Backlight VCC (5V) Led+
16 Backlight Ground (0V) Led
GSM MODULE
GSM/GPRS module is used to establish communication between a computer and
a GSM-GPRS system. Global System for Mobile communication (GSM) is an
architecture used for mobile communication in most of the countries. Global Packet Radio
Service (GPRS) is an extension of GSM that enables higher data transmission
rate. GSM/GPRS module consists of a GSM/GPRS modem assembled together with
power supply circuit and communication interfaces (like RS-232, USB, etc) for computer.
The MODEM is the soul of such modules.

Wireless MODEMs
Wireless MODEMs are the MODEM devices that generate, transmit or decode data from a
cellular network, for establishing communication between the cellular network and the computer.
These are manufactured for specific cellular network (GSM/UMTS/CDMA) or specific cellular
data standard (GSM/UMTS/GPRS/EDGE/HSDPA) or technology (GPS/SIM). Wireless
MODEMs like other MODEM devices use serial communication to interface with and
need Hayes compatible AT commands for communication with the computer (any
microprocessor or microcontroller system).
GSM/GPRS MODEM
GSM/GPRS MODEM is a class of wireless MODEM devices that are designed for
communication of a computer with the GSM and GPRS network. It requires a SIM (Subscriber
Identity Module) card just like mobile phones to activate communication with the network. Also
they have IMEI(International Mobile Equipment Identity) number similar to mobile phones for
their identification. A GSM/GPRS MODEM can perform the following operations:

1. Receive, send or delete SMS messages in a SIM.


2. Read, add, search phonebook entries of the SIM.
3. Make, Receive, or reject a voice call.

The MODEM needs AT commands, for interacting with processor or controller, which
are communicated through serial communication. These commands are sent by the
controller/processor. The MODEM sends back a result after it receives a command. Different AT
commands supported by the MODEM can be sent by the processor/controller/computer to
interact with the GSM and GPRS cellular network.

GSM/GPRS Module
A GSM/GPRS module assembles a GSM/GPRS modem with standard communication
interfaces like RS-232 (Serial Port), USB etc., so that it can be easily interfaced with a computer
or a microprocessor / microcontroller based system. The power supply circuit is also built in the
module that can be activated by using a suitable adaptor.

Mobile Station (Cell phones and SIM)


A mobile phone and Subscriber Identity Module (SIM) together form a mobile station. It is
the user equipment that communicates with the mobile network. A mobile phone comprises of
Mobile Termination, Terminal Equipment and Terminal Adapter.

Mobile Termination is interfaced with the GSM mobile network and is controlled by a baseband
processor. It handles access to SIM, speech encoding and decoding, signaling and other network
related tasks. The Terminal Equipment is an application processor that deals with handling
operations related to keypad, screen, phone memory and other hardware and software services
embedded into the handset. The Terminal Adapterestablishes communication between the
Terminal Equipment and the Mobile Termination using AT commands. The communication with
the network in a GSM/GPRS mobile is carried out by the baseband processor.

Difference between GSM mobile and GSM/GPRS module


A GSM mobile is a complete system in itself with embedded processors that are
dedicated to provide an interface between the user and the mobile network. The AT commands
are served between the processors of the mobile termination and the terminal equipment. The
mobile handset can also be equipped with a USB interface to connect with a computer, but it
may or may not support AT commands from the computer or an external processor/controller.

The GSM/GPRS module, on the other hand, always needs a computer or external
processor/controller to receive AT commands from. GSM/GPRS module itself does not provide
any interface between the user and the network, but the computer to which module is connected
is the interface between user and network.

An advantage that GSM/GPRS modules offer is that they support concatenated SMS
which may not be supported in some GSM mobile handsets. Also some mobile handsets can’t
receive MMS when connected to a computer.

Applications of GSM/GPRS module


The GSM/GPRS module demonstrates the use of AT commands. They can feature all the
functionalities of a mobile phone through computer like making and receiving calls, SMS, MMS
etc. These are mainly employed for computer based SMS and MMS services.

AT Commands
AT commands are used to control MODEMs. AT is the abbreviation for Attention. These
commands come from Hayes commands that were used by the Hayes smart modems. The Hayes
commands started with AT to indicate the attention from the MODEM. The dial up and wireless
MODEMs (devices that involve machine to machine communication) need AT commands to
interact with a computer. These include the Hayes command set as a subset, along with other
extended AT commands.

AT commands with a GSM/GPRS MODEM or mobile phone can be used to access


following information and services:
1. Information and configuration pertaining to mobile device or MODEM and SIM card.
2. SMS services.
3. MMS services.
4. Fax services.
5. Data and Voice link over mobile network.

The Hayes subset commands are called the basic commands and the commands specific to a
GSM network are called extended AT commands.

Command, Information response and Result Codes:


The AT commands are sent by the computer to the MODEM/ mobile phone. The MODEM
sends back an Information Response i.e. the information requested by or pertaining to the action
initiated by the AT command. This is followed by a Result Code. The result code tells about the
successful execution of that command.
There are also unsolicited Result Codes that are returned automatically by the MODEM to
notify the occurrence of an event. For example the reception of a SMS will force MODEM to
return an unsolicited result code

AT commands' syntax
Case Sensitivity -
The AT commands are generally used in uppercase letters. However some MODEMs and
mobile phones allow both uppercase and small case letters.

Single Command -
The AT commands include a prefix AT which indicates the beginning of the command to
MODEM; and a carriage return which indicates the end of the command.
However string ‘AT’ itself is not the part of the command. For example in ATD, D is the
command name not ATD.

The extended AT commands have a ‘+’ in the command name.


For example: AT+CGMI<Carriage return>

Command Line -
Multiple AT commands can be sent to MODEM in a single command line. The commands in
a line are separated by a semi-colon (;).

For example: AT+CGMI; +CBS<Carriage return>

String in Command Line -


Strings in a command line are enclosed in double quotes.
For example: AT+CGML=”ALL”<Carriage return>
Information Response and Result Code –
The Information Response and Result Codes, returned by the MODEM, have a carriage return
and line feed in the beginning as well as at the end.

For example:
<Carriage return><Line feed>OK<Carriage return><Line feed>
<Carriage return><Line feed>ERROR<Carriage return><Line feed>
<Carriage return><Line feed>+CBC: 0, 60<Carriage return><Line feed> etc.

Sequence of Execution -
In the command line, the command appearing first is executed first. The execution then
follows for second appeared command and so on. The execution of commands in a command
line takes place in sequential manner.

If an error occurs in the execution of a command, an error result code is returned by the
MODEM and the execution of the command line is terminated irrespective of presence of other
commands next in the command line.

Types of commands:
There are four types of AT commands:
1) Test commands
2) Read commands
3) Set commands
4) Execution commands
For more details, see AT Commands.
Different Result Codes:
RESULT CODE DESCRIPTION
OK Successful Execution of a command
ERROR Execution of a command failed
+CMS ERROR Message service failure, is returned with an error code

Unsolicited Result Codes


+CDS Notify receipt of SMS status report of a new message to computer
Notify receipt of SMS status report of a new message and its location in
+CDSI
memory to computer
+CMT Notify forwarding of a new SMS to computer
Notify receipt of SMS status report of a new message and its location in
+CMTI
memory to computer

Interfacing MODEM/Mobile phone with Windows platform


The Windows (XP and lower versions) comes with an application
called HyperTerminal for data communication through serial port of the computer. The
interfacing of the GSM/GPRS module with the serial port of the computer involves following
steps:
1) Connect RS-232 port of GSM module with the serial port of the computer. Insert a SIM card
in the module.
2) Open HyperTerminal from Start -> All Programs -> Accessories -> Communications -
> HyperTerminal.
3) Enter a name for the connection and press OK.
4) Now select the communication port (COM) at which GSM module is connected.
5) Create a new connection set on HyperTerminal. Set parameters, like baud rate as 9600,
handshaking mode as none, parity bit as none, stop bit as 1 and data bit as 8.
REGULATED POWER SUPPLY

Regulated power supply is an electronic circuit that is designed to provide a


constant dc voltage of predetermined value across load terminals irrespective of ac
mains fluctuations or load variations.

A regulated power supply essentially consists of an ordinary power supply and a


voltage regulating device, as illustrated in the figure. The output from an ordinary
power supply is fed to the voltage regulating device that provides the final output.
The output voltage remains constant irrespective of variations in the ac input
voltage or variations in output (or load) current.

Figure given below shows the complete circuit of a regulated power supply with a
transistor series regulator as a regulating device. Each part of the circuit is
explained in detail.

Transformer

A step down transformer is used to step down the voltage from the input AC to the
required voltage of the electronic device. This output voltage of the transformer is
customized by changing the turns ratio of the transformer according the electronic
device specs. The input of the transformer being 230 Volts AC mains, the output is
provided to a full bridge rectifier circuit.

Full Wave Rectifier Circuit

The FWR consists of 4 diodes which rectifies the output AC voltage or current
from the transistor to its equivalent DC quantity. As the name implies the FWR
rectifies both half’s of the AC input. The rectified DC output is given as input to
the filter circuit.

Filter Circuit

The filter circuit is used to convert the high rippled DC output of the FWR to
ripple free DC content. Filter is used to make the waveforms ripple free.

IC7805

A variable regulated power supply, also called a variable bench power supply, is one
which you can continuously adjust the output voltage to your requirements. Varying
the output of the power supply is recommended way to test a project after having
double checked parts placement against circuit drawings and the parts placement
This type of regulation is ideal for having a simple variable bench power
supply. Actually this is quite important because one of the first projects a
hobbyist should undertake is the construction of a variable regulated power
supply. While a dedicated supply is quite handy e.g 5V or 12V,it’s much handier to
have a variable supply on hand, especially for testing.

Most digital logic circuits and processors need a 5 volt power supply. To use
these parts we need to build a regulated 5 volt source. Usually you start with an
unregulated power to make a 5 volt power supply, we use a LM7805 voltage regulator
IC (Integrated Circuit).

LM 7805 block diagram

Pin representation of LM 7805


The LM7805 is simple to use. You simply connect the positive lead of your
unregulated DC power supply(anything from 9VDC to 24VDC) to the Input pin,
connect the negative lead to the Common pin and then when you turn on the
power, you get a 5 volt supply from the Output pin.
Circuit features:

 Brief description of operation: Gives out well regulated +5V output,


output current capability of 100mA.
 Circuit protection: Built-in overheating protection shuts down output
when regulator IC gets too hot.
 Circuit complexity: Very simple and easy to build.
 Circuit performance: Very stable +5V output voltage, reliable
operation
 Availability of components: Easy to get, uses only very common basic
components.
 Design testing: Based on datasheet example circuit, I have used this
circuit successfully as part of many electronic projects.
 Applications: Part of electronics devices, small laboratory power
supply
PROGRAM

#undef SIMULATION

// ----------------- CUSTOMIZABLE VALUES --------------------------

#ifdef SIMULATION

#define _XTAL_FREQ 5000 // with MPLAB X IDE simulation mode this

// value works best

#else

#define _XTAL_FREQ 6000000 // 6 MHz external crystal. Required for

// symbol definition of __delay_ms() macro

#endif

// These are delays for recurring SMS sending, defined separately for every

// single trigger type.

#define STEPS_CYCLES 7200 // send another SMS after this value x 3 secs

//#define STEPS_CYCLES 100 // send another SMS after this value x 3 secs

#define DOOR_CYCLES 7200 // send another SMS after this value x 3 secs

#define MAINS_CYCLES 7200 // send another SMS after this value x 3 secs

// ----------------- Pin definitions --------------------------

#define LED_SMS RA0 // digital OUT

#define GSM_POWER RA1 // digital OUT for GSM power enable pin

#define TRIGGER_STEPS RC0 // digital IN for PIR sensor trigger

#define TRIGGER_DOOR RC1 // digital IN for door opening sensor trigger

#define TRIGGER_MAINS RC2 // digital IN for mains power outage trigger


// ----------------- AT command declarations ------------------

// every string are in the EEPROM program memory to save data RAM space

//const char * AT_CREG = "AT+CREG?"; // query network status

char AT[] = "AT";

char power_off[] = "AT+CPWROFF";

char mode_text[] = "AT+CMGF=1"; // to set text mode

char char_mode[] = "AT+CSCS=\"GSM\""; // to set character mode

char param[] = "AT+CSMP=17,167,0,16"; // set a one day validity

char mobile_no[] = "AT+CMGS=\"+36301111111\""; // recipient's number

char terminator = 0x1A; // Control+Z terminator character

// ------------------------------------------------------------

/*

WDTE Watchdog Timer Enable bit

CP Program memory code protection bit

CPD Data Code Protection bit

BOREN Brown Out Detect

IESO Internal/External Switchover bit

FCMEN Fail-Safe Clock Monitor Enabled bit

FOSC FOSC<2:0>: Oscillator Selection bits:

100 = INTOSCIO oscillator: I/O function on RA4/OSC2/CLKOUT pin,

I/O function on RA5/OSC1/CLKIN

001 = XT oscillator: Crystal/resonator on RA4/OSC2/CLKOUT

and RA5/OSC1/CLKIN
When the SCS bit of the OSCCON register = 0, the system clock source is

determined by configuration of the FOSC<2:0> bits in the Configuration Word

register (CONFIG).

*/

#pragma config WDTE=ON, PWRTE=ON, MCLRE=ON, CP=OFF, \

CPD=OFF, BOREN=ON, IESO=OFF, FCMEN=ON, \

FOSC=XT

// ----------------- CONSTANT DEFINITIONS ---------------------

#define HIGH_LEVEL 1

#define LOW_LEVEL 0

#define ON 1

#define OFF 0

#define stealth 2 // stealth mode: no LED flashes

#define false 0

#define true 1

// ------------------------------------------------------------

#include <xc.h>

#include <PIC16F688.h>

#include <string.h>
// ----------------- GLOBAL VARIABLES -------------------------

char response_buffer[25]; // reusable buffer memory for texts

// ----------------- SUBROUTINES ------------------------------

void wait(unsigned char second, unsigned char isFast) {

CLRWDT();

for (unsigned char i = 0; i < second; i++) {

if (isFast == stealth) {

__delay_ms(900);

} else if (isFast == false) {

LED_SMS = OFF;

__delay_ms(499);

LED_SMS = ON;

__delay_ms(399);

} else {

LED_SMS = OFF;

__delay_ms(250);

LED_SMS = ON;

__delay_ms(200);

CLRWDT();

LED_SMS = OFF;

__delay_ms(250);
LED_SMS = ON;

__delay_ms(200);

CLRWDT();

void send_to_modem(char *s) {

while (*s) {

while(TXIF == 0);

TXREG = *s++;

CLRWDT();

while(TXIF == 0);

TXREG = 13; // carriage return

__delay_ms(800);

CLRWDT();

void send_sms(char *s) {

send_to_modem(s);

while(TXIF == 0);

TXREG = terminator; // "press" Ctrl-Z

wait(20, stealth);

}
// ------------------------------------------------------------

void main(void) {

// PIC init config

CMCON0bits.CM = 0b111; // comparators off

SCS = 0; // System Clock Select bit: 0, the system clock

// source is determined by configuration of the

// FOSC<2:0> bits in the Configuration Word

// register (CONFIG)

OSTS = 1; // Oscillator Start-up Time-out Status bit:

// 0 = Device is running from the internal

// oscillator (HFINTOSC or LFINTOSC)

// I/O port init

ANSEL = 0b00000000; // setting every pin to digital (not analogue)

PORTA = 0; // switch off every in/output

PORTC = 0; // switch off every in/output

TRISA = 0b00000000; // setting everything as output

TRISC = 0b00001111; // setting RC0,1,2,3 as input

// initially switch off the GSM modem

GSM_POWER = HIGH_LEVEL; // negated working, high means OFF

// power-up phase ---------------------------------------


wait(2, false); // at startup there is a double flash on SMS LED

__delay_ms(1000);

CLRWDT();

// to ignore recurring trigger events we need separated cycle counters

unsigned int cycleCounters[] = {

STEPS_CYCLES,

DOOR_CYCLES,

MAINS_CYCLES

};

char triggerCode = 0x0; // lower bits indicates trigger events

wait(120, true); // give the user some time after power on to leave the area

LED_SMS = OFF;

__delay_ms(1000);

CLRWDT();

__delay_ms(1000);

CLRWDT();

while (1) {

if (TRIGGER_STEPS == LOW_LEVEL && (STEPS_CYCLES <= cycleCounters[0])) {

// step trigger is a reversed sensor: LOW means activated

triggerCode |= 0b00000001; // set bit #0 to HIGH

cycleCounters[0] = 0; // start counting


}

if (TRIGGER_DOOR == LOW_LEVEL && (DOOR_CYCLES <= cycleCounters[1])) {

// door trigger is a reversed sensor: LOW means activated

triggerCode |= 0b00000010; // set bit #1 to HIGH

cycleCounters[1] = 0; // start counting

if (TRIGGER_MAINS == HIGH_LEVEL && (MAINS_CYCLES <= cycleCounters[2])) {

triggerCode |= 0b00000100; // set bit #2 to HIGH

cycleCounters[2] = 0; // start counting

if (triggerCode > 0) { // has any trigger set?

wait(40, stealth); // give the user 1 minute to turn off the alarm system

// is the modem in use by another (outer) device?

TRISA = 0b00000010; // setting RA1 (GSM_POWER) as input

__delay_ms(300);

if (GSM_POWER = LOW_LEVEL) { // negated working, low means ON

wait(5, stealth); // wait until the modem is available

} else {

TRISA = 0b00000000; // setting everything as output

__delay_ms(300);

// init UART
SPBRG = 9; // with this config this means 38400 bit/s

BAUDCTLbits.BRG16 = 0;

TXSTAbits.BRGH = 1; // high baud rate

RCSTAbits.CREN = 1; // RCSTA bit 4: enables the receiver circuitry of the


EUSART

TXSTAbits.SYNC = 0; // TXSTA bit 4: 0 = asynchronous operation

RCSTAbits.SPEN = 1; // RCSTA bit 7: enable serial port

TXSTAbits.TXEN = 1; // TXSTA bit 5: enables the transmitter circuitry

// power up the modem

GSM_POWER = LOW_LEVEL; // negated working, low means ON

wait(40, stealth); // wait for startup and the "+PBREADY" which indicates mobile
service connection

// build the custom alert message

char msg[8];

char message[25] = "Alarm: ";

if ((triggerCode >> 0) & 1) { // has bit 0 set?

memset(msg, '\0', 8);

strcpy(msg, "Steps\n");

strcat(message, msg);

if ((triggerCode >> 1) & 1) { // has bit 1 set?

memset(msg, '\0', 8);

strcpy(msg, "Door\n");
strcat(message, msg);

if ((triggerCode >> 2) & 1) { // has bit 2 set?

memset(msg, '\0', 8);

strcpy(msg, "Mains\n");

strcat(message, msg);

// negotiate baud rate

send_to_modem(AT); // send "AT" string then wait a while

__delay_ms(1000);

// prepare and send SMS

send_to_modem(mode_text);

send_to_modem(char_mode);

send_to_modem(param);

send_to_modem(mobile_no);

send_sms(message);

triggerCode = 0x0; // clear triggers

// power off

GSM_POWER = HIGH_LEVEL; // negated working, high means OFF

TXSTAbits.TXEN = OFF; // turn off transmitter circuitry to save power


RCSTAbits.SPEN = OFF; // disable the serial port

} // end else

if (cycleCounters[0] < STEPS_CYCLES) {

cycleCounters[0]++;

if (cycleCounters[1] < DOOR_CYCLES) {

cycleCounters[1]++;

if (cycleCounters[2] < MAINS_CYCLES) {

cycleCounters[2]++;

// wait a while before the next trigger cycle

__delay_ms(1200); CLRWDT();

__delay_ms(1448); CLRWDT();

LED_SMS = ON;

__delay_ms(40);

LED_SMS = OFF;

ADVANTAGES
 Easy to operate.
 Sophisticated security.
 Simple and Reliable Design.
 Isolates both GSM and GPS signal.

LIMITATIONS
 It does not work without network.

APPLICATIONS
 Stolen Vehicle Recovery: Both consumer and commercial vehicles can be outfitted with
RF or GPS units to allow police to do tracking and recovery. In the case of LoJack, the
police can activate the tracking unit in the vehicle directly and follow tracking signals.
 Fleet Management: When managing a fleet of vehicles, knowing the real-time location
of all drivers allows management to meet customer needs more efficiently. Whether it is
delivery, service or other multi-vehicle enterprises, drivers now only need a mobile phone
with telephony or Internet connection to be inexpensively tracked by and dispatched
efficiently.
 Asset Tracking: Companies needing to track valuable assets for insurance or other
monitoring purposes can now plot the real-time asset location on a map and closely
monitor movement and operating status.
 Field Sales: Mobile sales professionals can access real-time locations. For example, in
unfamiliar areas, they can locate themselves as well as customers and prospects, get
driving directions and add nearby last-minute appointments to itineraries. Benefits
include increased productivity, reduced driving time and increased time spent with
customers and prospects.
 Transit Tracking: This is the temporary tracking of assets or cargoes from one point to
another. Users will ensure that the assets do not stop on route or do a U-Turn in order to
ensure the security of the assets.
 To avoid the accident dead ,immediately they give the instruction to nearby ambulance

CONCLUSION
This project presents vehicle accident detection and alert system with SMS to the user
defined mobile numbers. The GSM alert based algorithm is designed and implemented with
MCU in embedded system domain. The proposed Vehicle accident detection system can track
geographical information automatically and sends an alert SMS regarding accident.
Experimental work has been carried out carefully. The result shows that higher sensitivity and
accuracy is indeed achieved using this project. EEPROM is interfaced to store the mobile
numbers permanently. This made the project more user-friendly and reliable. The proposed
method is verified to be highly beneficial for the automotive industry.

Você também pode gostar