Project Report
Project Report
A PROJECT REPORT
SUBMITTED BY
SHUBHAM BHALEKAR
PRATIK AVHAD
RUSHIKESH WAGHMODE
Diploma
IN
INFORMATION TECHNOLOGY
JUNE 2021
i
GOVERNMENT POLYTECHNIC MUMBAI
DEPARTMENT OF INFORMATION TECHNOLOGY
CERIFICATE
Mumbai.
PRINCIPAL
DECLARATION
ii
We hereby declare that the project entitled “LOCATION DETECTOR
Date :-
iii
ACKNOWLEDGMENTS
It is our privilege to express our sincerest regards to our project coordinator, Dr Rajesh A. Patil for their valuable
inputs, guidance, encouragement, whole-hearted cooperation and constructive criticism throughout the duration of
our project. Their useful suggestions for this whole work and co-operative behavior are sincerely acknowledged.
We also deeply express our sincere thanks to our Head of Department Dr Prof. Rajesh A. Patil for encouraging
and allowing us to present the project on the topic “Security System Using Ultrasonic Sensor And Gsm Module”
at our department premises for the partial fulfillment of the requirements.
We take this opportunity to thank all our lecturers who have directly or indirectly helped our project. We pay our
respects and love to our parents and all other family members and friends for their love and encouragement
throughout our career. Last but not the least we express our thanks to our friends for their cooperation and support.
iv
ABSTRACT
Home security is becoming necessary nowadays as the possibilities of intrusion are increasing day by
day .Lot of Security companies are available towards protecting house from getting vandalized or so. But still
there is no much guarantee that the house be safe or even if the house vandalized, security personnel safe and
sound to report to police nearby.
Lot of research been carried out employing sensors like PIR, Sensor Camera, GSM towards detecting the
intruder at home. But the drawback in all these systems is that they are all expensive to be deployed integrated
with LCD panel or Camera. Again with PIR sensor or Ultrasonic Sensor integrated with GSM, there is good
possibility of false intruder detection based on line of sight cut by any entity and not necessarily an intruder.
Currently homes in India still rely on security service personnel and no home security system been employed so
far.
So taking the above mentioned aspects into consideration, we here have developed an economical and
affordable Home security system which have integrated the security component by making use of sensors like
Ultrasonic Sensor to sense the motion. After Ultrasonic sense the motion, the busser will buzz. The owner of the
house is informed about any intruder by sending a text message by using of GSM module. All these activities are
controlled by Arduino Uno. This system would help all the users at any level of income to have one at their home
and secure home
v
Table of Content:
1. Introduction
1.1. Introduction to Project
1.2. Future Scope
2.Literature Review
3.Overview of the Major Concepts Used
3.1 Arduino UNO
3.2. GSM - Global System for Mobile communication
3.3. Ultrasonic Sensor
4.Requirement Analysis
4.1. Hardware Components
4.2. Software Components
5.System Design
5.1 Working of Ultrasonic Sensor
5.2 Working of BUZZER
5.3 Working of GSM
5.4 Working f Security System
vi
List of Figures
1. Introduction
2. Literature Review
3. Overview of the Major Concepts Used
Fig.No.3.1.1. Arduino Uno
Fig.No.3.1.2 Arduino Uno Pin Diagram
Fig.No.3.2.1. GSM Module
4. Requirement Analysis
Fig.No. 4.1.1. Piezo Buzzer
Fig.No.4.1.2. Bread Board
Fig.No.4.1.3. Male To Male
Fig.No.4.1.4. Male To Female
Fig.No.4.1.5. Micro USB
5. System Design
Fig.No.5.1.1. Ultrasonic Sensor
Fig.No.5.1.2. Ultrasonic Sensor Received Signal
Fig.No.5.1.3. Flowchart of Ultrasonic Sensor
Fig.No. 5.1.4. Connection of Ultrasonic sensor
Fig.No.5.2.1. Flowchart of Buzzer
Fig.No.5.2.2. Connection of Buzzer
Fig.No.5.3.1. Flowchart of GSM
Fig.No.5.3.2. Connection of GSM
Fig.No.5.4.1. Flowchart Of Security System
vii
Abbreviations
viii
CHAPTER 1
INTRODUCTION
1
1. INTRODUCTION
The ‘modern and smart’ security systems which do in fact cover other potential
threats and do function smartly by incorporating other forms of alarms notably phone-based
alarms for remote monitoring, costs a fortune to set up, operate and maintain, owing to the
nature of software design, type of materials used etc.
It consists of various types of sensors used for the task of monitoring. The system is fully
controlled by the ‘powerful’ Arduino Uno board. The Arduino Uno board, continuously
monitors all sensors, and if any security threat is detected from these sensors, then a
combination of three alarms are triggered, namely; visual, audio and/or phone-based alarm.
The system offers a safe security system, in that only the user can activate or deactivate
the two operational modes, through a phone call made only from his phone to the system,
unlike other systems. This capability means that the security system is in itself minimally
prone to attack.
2
CHAPTER 2
LITERAURE REVIEW
3
2. Literature Review
The tasks of a modern security system include identifying an intruder trying to gain access to the home,
alerting the homeowner about the intrusion or intrusion attempt, preventing the intruder from gaining access
to the home, and gathering or collecting evidence regarding the intrusion so that the perpetuators can be
brought to justice. The changing concept of security in modern homes has an impact on the advancement of
technology.
This setup can also be used in commercial offices where some areas are restricted for certain personnel, such
a system will immediately inform the administrator of any unauthorized personnel trying to access such an
area. Therefore the extensibility and applicability of such a system is only limited only by the imagination.
Some benefits of security system:
Cost Effective
Easy to implement
It provides security
4
5
CHAPTER 3
6
3.Overview of the Major Concepts Used
The Arduino Uno is a microcontroller board based on the ATmega328 (datasheet). It has 14 digital input/output
pins (of which 6 can be used as PWM outputs), 6 analog inputs, a 16 MHz crystal oscillator, a USB connection, a
power jack, an ICSP header, and a reset button. It contains everything needed to support the microcontroller;
simply connect it to a computer with a USB cable or power it with a AC-to-DC adapter or battery to get started.
The Uno differs from all preceding boards in that it does not use the FTDI USB-to-serial driver chip. Instead, it
features the Atmega8U2 programmed as a USB-to-serial converter
The Arduino Uno can be powered via the USB connection or with an external power supply. The power source is
selected automatically.
External (non-USB) power can come either from an AC-to-DC adapter (wall-wart) or battery. The adapter can be
connected by plugging a 2.1mm center-positive plug into the board's power jack. Leads from a battery can be
inserted in the Gnd and Vin pin headers of the POWER connector.
The board can operate on an external supply of 6 to 20 volts. If supplied with less than 7V, however, the 5V pin
may supply less than five volts and the board may be unstable. If using more than 12V, the voltage regulator may
overheat and damage the board. The recommended range is 7 to 12 volts.
7
Fig.No.3.1.2 Arduino Uno Pin Diagram
Summary:
Microcontroller ATmega328
Operating Voltage 5V
SRAM 2 KB (ATmega328)
EEPROM 1 KB (ATmega328)
8
The power pins are as follows:
VIN. The input voltage to the Arduino board when it's using an external power source (as opposed to 5
volts from the USB connection or other regulated power source). You can supply voltage through this pin,
or, if supplying voltage via the power jack, access it through this pin.
5V. The regulated power supply used to power the microcontroller and other components on the board.
This can come either from VIN via an on-board regulator, or be supplied by USB or another regulated 5V
supply
3V3. A 3.3 volt supply generated by the on-board regulator. Maximum current draw is 50 mA.
GND. Ground pins.
1. Power:
The Arduino Uno can be powered via the USB connection or with an external power supply. The
power source is selected automatically.
External (non-USB) power can come either from an AC-to-DC adapter (wall-wart) or battery. The
adapter can be connected by plugging a 2.1mm center-positive plug into the board's power jack.
Leads from a battery can be inserted in the Gnd and Vin pin headers of the POWER connector.
The board can operate on an external supply of 6 to 20 volts. If supplied with less than 7V,
however, the 5V pin may supply less than five volts and the board may be unstable. If using more
than 12V, the voltage regulator may overheat and damage the board. The recommended range is 7
to 12 volts.
The power pins are as follows:
VIN. The input voltage to the Arduino board when it's using an external power source (as
opposed to 5 volts from the USB connection or other regulated power source). You can
supply voltage through this pin, or, if supplying voltage via the power jack, access it
through this pin.
5V.This pin outputs a regulated 5V from the regulator on the board. The board can be
supplied with power either from the DC power jack (7 - 12V), the USB connector (5V), or
the VIN pin of the board (7-12V). Supplying voltage via the 5V or 3.3V pins bypasses the
regulator, and can damage your board. We don't advise it.
GND. Ground pins.
IOREF. This pin on the Arduino board provides the voltage reference with which the
microcontroller operates. A properly configured shield can read the IOREF pin voltage and
9
select the appropriate power source or enable voltage translators on the outputs for working
with the 5V or 3.3V.
Serial: 0 (RX) and 1 (TX). Used to receive (RX) and transmit (TX) TTL serial data. TThese
pins are connected to the corresponding pins of the ATmega8U2 USB-to-TTL Serial chip .
External Interrupts: 2 and 3. These pins can be configured to trigger an interrupt on a low
value, a rising or falling edge, or a change in value.
PWM: 3, 5, 6, 9, 10, and 11. Provide 8-bit PWM output with the analogWrite() function.
SPI: 10 (SS), 11 (MOSI), 12 (MISO), 13 (SCK). These pins support SPI communication,
which, although provided by the underlying hardware, is not currently included in the
Arduino language.
LED: 13. There is a built-in LED connected to digital pin 13. When the pin is HIGH value,
the LED is on, when the pin is LOW, it's off.
The Uno has 6 analog inputs, each of which provide 10 bits of resolution (i.e. 1024 different values).
By default they measure from ground to 5 volts, though is it possible to change the upper end of their range
using the AREF pin and the analogReference() function. Additionally, some pins have specialized
functionality:
2C: 4 (SDA) and 5 (SCL). Support I2C (TWI) communication using the Wire library.
There are a couple of other pins on the board:
AREF. Reference voltage for the analog inputs. Used with analogReference().
Reset. Bring this line LOW to reset the microcontroller. Typically used to add a reset button to shields
which block the one on the board.
3. Memory:
The ATmega328 has 32 KB (with 0.5 KB used for the bootloader). It also has 2 KB of SRAM and 1
KB of EEPROM (which can be read and written with the EEPROM library).
10
4. COMMUNICATION:
The Arduino Uno has a number of facilities for communicating with a computer, another Arduino,
or other microcontrollers. The ATmega328 provides UART TTL (5V) serial communication, which
is available on digital pins 0 (RX) and 1 (TX). An ATmega8U2 on the board channels this serial
communication over USB and appears as a virtual com port to software on the computer. The '8U2
firmware uses the standard USB COM drivers, and no external driver is needed. However, on
Windows, an *.inf file is required.
The Arduino software includes a serial monitor which allows simple textual data to be sent to and
from the Arduino board. The RX and TX LEDs on the board will flash when data is being
transmitted via the USB-toserial chip and USB connection to the computer (but not for serial
communication on pins 0 and 1).
A SoftwareSerial library allows for serial communication on any of the Uno's digital pins
The ATmega328 also support I2C (TWI) and SPI communication. The Arduino software includes a
Wire library to simplify use of the I2C bus; see the documentation for details. To use the SPI
communication, please see the ATmega328 datasheet.
11
data sent to the board after a connection is opened. If a sketch running on the board receives one-time
configuration or other data when it first starts, make sure that the software with which it
communicates waits a second after opening the connection and before sending this data.
The Uno contains a trace that can be cut to disable the auto-reset. The pads on either side of
the trace can be soldered together to re-enable it. It's labeled "RESETEN". You may also be able to
disable the auto-reset by connecting a 110 ohm resistor from 5V to the reset line; see this forum
thread for details.
7. Physical Characteristics:
The maximum length and width of the Uno PCB are 2.7 and 2.1 inches respectively, with the
USB connector and power jack extending beyond the former dimension. Four screw holes allow the
board to be attached to a surface or case. Note that the distance between digital pins 7 and 8 is 160 mil
(0.16"), not an even multiple of the 100 mil spacing of the other pins.
3.2 GSM - Global System for Mobile communication:
GSM is the most widely used network technology in Internet of Things (IoT) applications for its simplicity,
affordability, and accessibility. It uses the 2G network band. Our project uses GSM network to make the phone
call during an emergency. The project has a nano sim-card which gets registered on the 2G network and uses GSM
network to make the phone call. Structure of GSM networks –
Mobile Station (MS): The Mobile Station is essentially the access point someone uses to connect to the
network. It’s a device (such as an alarm system) with a Subscriber Identity Module (SIM). The SIM
associates the device with an individual subscriber, which allows the device to connect to the nearest Base
Station Subsystem.
Base Station Subsystem (BSS): The BSS contains Base Transceiver Stations and a Base Station Controller.
The Base Transceiver Stations include components like receivers and antenna, which allows connected
devices to send and receive signals, and the Base Station Controller allows the Base Transceiver Stations to
relay signals through the network, via the Network and Switching Subsystem
12
Network and Switching Subsystem (NSS): The Network and Switching Subsystem is a term for the major
components of a 2G core network. The NSS originally helped facilitate connection-oriented voice calls
with the Home Location Register (HLR), Authentication Center (AuC), Message Service Center (MSC),
and Visitor Location Register (VLR). With the introduction of the GPRS core network and its support
nodes (GGSN and SGSN), the NSS began playing a role in data connections as well.
Operations Support System (OSS): The Operations Support System is a conglomeration of processes, data,
applications, and tech that allows providers to manage their network.
GSM played a foundational role in modern cellular communications. While some operators are transitioning to
newer networks, this technology is still immensely popular for its global availability and extremely low-cost
connectivity.
Ultrasonic transmitter emitted an ultrasonic wave in one direction, and started timing when it launched. Ultrasonic
spread in the air, and would return immediately when it encountered obstacles on the way. At last, the ultrasonic
receiver would stop timing when it received the reflected wave. The principle of ultrasonic distance measurement
used the already-known air spreading velocity, measuring the time from launch to reflection when it encountered
obstacle, and then calculate the distance between the transmitter and the obstacle according to the time and the
velocity. Thus, the principle of ultrasonic distance measurement is the same with radar.
13
Fig.No.3.3.1. Ultrasonic Sensor
The HC-SR04 ultrasonic sensor uses sonar to determine distance to an object like bats do. It operation is not
affected by sunlight or black material like. It comes complete with ultrasonic transmitter and receiver module.
A. PRODUCT FEATURES
Ultrasonic ranging module HC - SR04 provides 2cm - 400cm non-contact measurement function, the
ranging accuracy can reach to 3mm. The modules includes ultrasonic transmitters, receiver and control circuit.
The basic principle of work: Using IO trigger for at least 10us high level signal, The Module automatically
sends eight 40 kHz and detect whether there is a pulse signal back. IF the signal back, through high level , time
of high output IO duration is the time from sending ultrasonic to returning.
B. ULTRASONIC APPLICATION
Ultrasonic Application Technology is the thing which developed in recent decades. With the ultrasonic
advance, and the electronic technology development, especially as high-power semiconductor device
technology matures, the application of ultrasonic has become increasingly widespread:
Ultrasonic measurement of distance, depth and thickness
Ultrasonic testing
Ultrasound imaging; Ultrasonic machining, such as polishing, drilling
Ultrasonic cleaning
Ultrasonic welding
C. APPLICATION AREAS
Robotics barrier
Object distance measurement
Level detection
Public security
14
D. MODULE OPERATING PRINCIPLE
Set low the Trig and Echo port when the module initializes , firstly, transmit at least 10us high level pulse
to the Trig pin (module automatically sends eight 40K square wave), and then wait to capture the rising edge
output by echo port, at the same time, open the timer to start timing. Need to supply a short 10uS pulse to the
trigger input to start the ranging, and then the module will send out an 8 cycle burst of ultrasound at 40 kHz
and raise its echo. The Echo is a distance object that is pulse width and the range in proportion. You can
calculate the range through the time interval between sending trigger signal and receiving echo signal.
Formula: uS / 58 = centimeters or uS / 148 =inch; or: the range = high level time * velocity (340M/S) / 2; we
suggest to use over 60ms measurement cycle, in order to prevent trigger signal to the echo signal.
15
CHAPTER 4
REQUIREMENT ANALAYSIS
16
4. Requirement Analysis
1. Arduino Uno
2. GSM Module,
3. Ultrasonic Sensor
4. Piezo Buzzer
5. Breadboard
6. Jump Wires.
7. Micro USB
Piezo Buzzer
A buzzer is used to alert the persons nearby. The buzzer produces a same noisy sound irrespective of the
voltages -applied to it. When potential is applied to it, they push on one conductor and pull on the other. This
results in producing sound. It can produce voltage of 2 to 4kHz.
Bread Board
A thin plastic board used to hold electronic components (transistors, resistors, chips, etc.) that are wired
together. Used to develop prototypes of electronic circuits, breadboards can be reused for future jobs. They can
be used to create one-of-a-kind systems but rarely become commercial products.
17
Fig.No.4.1.2. Bread Board
Jump Wires
A jump wire (also known as jumper, jumper wire, jumper cable, DuPont wire or cable) is an
electrical wire, or group of them in a cable, with a connector or pin at each end which is normally used to
interconnect the components of a breadboard or other prototype or test circuit, internally or with other
equipment or components, without soldering.
MALE TO MALE:
MALE TO FEMALE:
18
Micro USB
Micro USB is a miniaturized version of the USB (Universal Serial Bus) interface developed for connecting
compact and mobile devices such as your smartphones, MP3 players, GPS devices, photo printers, and
digital cameras. USB was designed to standardize the connection of peripherals to personal computers,
both to communicate with and to supply electric power. It has largely replaced interfaces such as serial
ports and parallel ports, and has become commonplace on a wide range of devices.
Arduino IDE
The Arduino integrated development environment (IDE) is a cross platform application written in Java, and
is derived from the IDE for the Processing programming language and the Wiring projects. It is designed to
introduce programming to artists and other newcomers unfamiliar with software development. It
includes a code editor with features such as syntax highlighting, brace matching, and automatic indentation, and is
also capable of compiling and uploading programs to the board with a single click.
A program or code written for Arduino is called a sketch Arduino programs are written in C or C++. The Arduino
IDE comes with a software library called "Wiring" from the original Wiring project, which makes many common
input/output operations much easier. Users only need define two functions to make a runnable cyclic executive
program:
The Arduino IDE uses the GNU tool chain and AVR Library to compile programs, and uses avrdude to
upload programs to the board.
As the Arduino platform uses Atmel microcontrollers, Atmel's development environment, AVR Studio or
the newer Atmel Studio, may also be used to develop software for the Arduino
19
20
CHAPTER 5
SYSTEM DESIGN
21
5. System Design And Coding
when a pulse of at least 10 µS (10 microseconds) in duration is applied to the Trigger pin. In
response to that the sensor transmits a sonic burst of eight pulses at 40 KHz. This 8-pulse pattern makes the
“ultrasonic signature” from the device unique, allowing the receiver to differentiate the transmitted pattern
from the ambient ultrasonic noise.
The eight ultrasonic pulses travel through the air away from the transmitter. Meanwhile the Echo pin goes
HIGH to start forming the beginning of the echo-back signal.
In case, If those pulses are not reflected back then the Echo signal will timeout after 38 mS (38 milliseconds)
and return low. Thus a 38 mS pulse indicates no obstruction within the range of the sensor.
If those pulses are reflected back the Echo pin goes low as soon as the signal is received. This produces a pulse
whose width varies between 150 µS to 25 mS, depending upon the time it took for the signal to be received.
22
Fig.No.5.1.2. Ultrasonic Sensor Received Signal
The width of the received pulse is then used to calculate the distance to the reflected object. This can be worked
out using simple distance-speed-time equation, we learned in High school. In case you forgot, an easy way to
remember the distance, speed and time equations is to put the letters into a triangle.
Let’s take an example to make it more clear. Suppose we have an object in front of the sensor at an unknown
distance and we received a pulse of width 500 µS on the Echo pin. Now let’s calculate how far the object
from the sensor is. We will use the below equation.
Here, we have the value of Time i.e. 500 µs and we know the speed. What speed do we have? The speed of
sound, of course! Its 340 m/s. We have to convert the speed of sound into cm/µs in order to calculate the
distance. A quick Google search for “speed of sound in centimeters per microsecond” will say that it is 0.034
cm/µs. You could do the math, but searching it is easier. Anyway, with that information, we can calculate
the distance!
But this is not done! Remember that the pulse indicates the time it took for the signal to be sent out and
reflected back so to get the distance so, you’ll need to divide your result in half.
Distance = 8.5 cm
23
Flowchart of Ultrasonic Sensor:
Now that we have a complete understanding of how HC-SR04 ultrasonic distance sensor works, we can
begin hooking it up to our Arduino!
Connecting the HC-SR04 to the Arduino is pretty easy. Start by placing the sensor on to your breadboard.
Connect VCC pin to the 5V pin on the Arduino and connect GND pin to the Ground pin on the Arduino.
When you’re done you should have something that looks similar to the illustration shown below.
24
Fig.No. 5.1.4. Connection of Ultrasonic sensor
Buzzers can be both fun and useful in electric circuits.We’ll use them a lot in MakeCrate projects, so let’s
take a look at what is going on inside a buzzer to produce sound.
The buzzer consists of an outside case with two pins to attach it to power and ground.
Inside is a piezo element, which consists of a central ceramic disc surrounded by a metal (often
bronze)vibration disc.
When current is applied to the buzzer it causes the ceramic disk to contract or expand. Changing the This
then causes the surrounding disc to vibrate. That’s the sound that you hear. By changing the frequency of
the buzzer, the speed of the vibrations changes, which changes the pitch of the resulting sound.
25
Flowchart of Buzzer
Connection of BUZZER
26
5.3 Working of GSM
Global System for Mobile Communications (GSM) uses a combination of Time Division Multiple Access
(TDMA) and Frequency Division Multiple Access (FDMA).
Frequency Division Multiple Access: It involves dividing a frequency band into multiple bands such that
each sub-divided frequency band is allotted to a single subscriber. FDMA in GSM divides the 25MHz
bandwidth into 124 carrier frequencies each spaced 200 KHz apart. Each base station is allotted one or more
carrier frequencies.
Time Division Multiple Access: It involves allotting same frequency channel to different subscribers by
dividing the frequency band into multiple time slots. Each user gets his/her own timeslot, allowing multiple
stations to share same transmission space.
For GSM, each sub divided carrier frequency is divided into different time slots using TDMA technique.
Each TDMA frame lasts for 4.164 milliseconds (ms) and contains 8 time slots. Each time slot or a physical
channel within this frame lasts for 577 microseconds and data is transmitted in the time slot in form of
bursts.
Flowchart of GSM
27
Connection of GSM
This system is a basic motion activated alarm. It is built around an Arduino Microcontroller. It is connected
to an Ultrasonic sensor, a buzzer, GSM module, and a pairs of jumper wires. The whole system is battery powered
so that it is easily portable. Once you have the code, you can connect all the external parts. The easiest way to do
this is with a breadboard. This will let you make temporary connections to test everything out.
If the Ultrasonic Sensor sense the object, Then Buzzer will start buzzing and GSM module will send text to
the smartphone.
28
Flowchart
Ultrasonic to Arduino:
VCC -> Arduino +5V pin
GND -> Arduino GND pin
Trig -> Arduino Digital Pin 9
Echo -> Arduino Digital Pin 10
Connection to Buzzer:
s -> Arduino pin 8
29
Connection of GSM:
GND -> Arduino GND pin
TX -> Arduino Digital Pin 2
RX -> Arduino Digital Pin 3
OVERVIEW:
30
CHAPTER 6
31
6 SOFTWARE CODE DEVELOPMENT
1] Introduction
Location Tracker using GSM module uses several hardware components connected with each other to track
location data and transmit it over GPRS network. However, in order for the hardware components to function, the
instruction need to be hardcoded into the ESP32 chip. The steps used in developing various elements of the code
are explained below along with a brief overview of all concepts used throughout the code.
2] What is Arduino?
Arduino is an open-source electronics platform based on easy-to-use hardware and software. The Arduino
software is easy-to-use for beginners, yet flexible enough for advanced users. It runs on Mac, Windows, and Linux
as well.
Fig.No.6.2.1. Arduino
The Arduino Integrated Development Environment - or Arduino Software (IDE) - contains a text editor for writing
code, a message area, a text console, a toolbar with buttons for common functions and a series of menus. It
connects to the Arduino hardware to upload programs and communicate with them. Programs written using
Arduino Software (IDE) are called sketches. These sketches are written in the text editor and are saved with the
file extension .ino. The editor has features for cutting/pasting and for searching/replacing text. The message area
gives feedback while saving and exporting and also displays errors. The console displays text output by the
Arduino Software (IDE) if any, including complete error messages and other information.
32
Fig.No.6.3.1. Arduino Software IDE
4] #include
#include is used to include outside libraries in the sketch. This gives the programmer access to a large group of
standard C libraries (groups of pre-made functions), and also libraries written especially for Arduino. It is also
used to use code from any local files in the code.
Syntax
#include <LibraryFile.h>
#include "LocalFile.h"
Parameters:
1. LibraryFile.h: When the angle brackets syntax is used, the libraries paths will be searched for the file.
2. LocalFile.h: When the double quotes syntax is used, the folder of the file using the #include directive will
be searched for the specified file, then the libraries paths if it was not found in the local path. This syntax is
usually used for header files in the sketch’s folder.
Example:
#include <SoftwareSerial.h>
The Arduino hardware has built-in support for serial communication on pins 0 and 1 (which also goes to the
computer via the USB connection). The native serial support happens via a piece of hardware (built into the
chip) called a UART. This hardware allows the Atmega chip to receive serial communication even while
working on other tasks, as long as there room in the 64 byte serial buffer.
33
The SoftwareSerial library has been developed to allow serial communication on other digital pins of the
Arduino, using software to replicate the functionality (hence the name "SoftwareSerial"). It is possible to
have multiple software serial ports with speeds up to 115200 bps. A parameter enables inverted signaling for
devices which require that protocol.
5] #define
#define is a useful C++ component that allows the programmer to give a name to a constant value before the
program is compiled. Defined constants in Arduino don’t take up any program memory space on the chip. The
compiler will replace references to these constants with the defined value at compile time. This can have some
unwanted side effects though, if for example, a constant name that had been #defined is included in some other
constant or variable name. In that case the text would be replaced by the #defined number (or text).
Syntax:
6.1] setup36()
The setup() function is called when a sketch starts. It is used to initialize variables, pin modes, start using libraries,
etc. The setup() function will only run once, after each powerup or reset of the board. The setup and loop functions
are mandatory. Trying to compile a code with one of these functions missing, results in an error. The code inside
the void setup will be executed once, and only once, at the beginning of the program.
Syntax:
void setup() {
body;
The method calls we used in setup() for the project are enlisted below along with their precise description and
syntax used.
Serial.begin(speed): It sets the data rate in bits per second (baud) for serial data transmission.
delay(ms):- Pauses the program for the amount of time (in milliseconds) specified as parameter. (There are
1000 milliseconds in a second.)
pinMode(pin, mode):- Configures the specified pin to behave either as an input or an output. See the
description of digital pins for details on the functionality of the pins.
34
As of Arduino 1.0.1, it is possible to enable the internal pullup resistors with the mode
INPUT_PULLUP. Additionally, the INPUT mode explicitly disables the internal pullups.
6.2] loop()
After creating a setup() function, which initializes and sets the initial values, the loop() function does precisely
what its name suggests, and loops consecutively, allowing the sketch to change and respond accordingly. It doesn’t
stop iterating until the board is powered off or the Arduino program is restarted by pressing the reset button /
uploading a new sketch / re-opening the Serial Monitor on the ESP32 board.
The method calls we used in loop() for the project are enlisted below along with their precise description and
syntax used.
digitalWrite(pin, value):- Write a HIGH or a LOW value to a digital pin.If the pin has been configured as
an OUTPUT with pinMode(), its voltage will be set to the corresponding value: 5V (or 3.3V on 3.3V
boards) for HIGH, 0V (ground) for LOW.
delayMicroseconds(us):- Pauses the program for the amount of time (in microseconds) specified by the
parameter. There are a thousand microseconds in a millisecond and a million microseconds in a second.
35
6.7.Uploading Code to the Board
After sketch is complete, the last yet an important step is Uploading the sketch onto the board. The steps used to
upload this sketch to the Arduino Uno are as follows:
Step 2: Connect the Arduino Uno module to the computer using a cable.
Step 3: Then Upload code to the Arduino Uno Using Arduino IDE.
Step 4: After Uploading code to Arduino compile the code, check if any error is there.
37
ADVANTAGES
• The given system is handy and portable, and thus can be easily carried from one place to another.
• The circuitry is not that complicated and thus can be easily troubleshooted.
• The given system sets off a powerful buzzer, and it is effective as any other alarm system available in the
market.
• This sensor is not affected due to atmospheric dust, rain, snow etc.
• It can work in any adverse conditions.
DISADVANTAGES
38
Conclusion
Thus, we have designed a home security alarm system using Arduino and Ultrasonic sensor, which is
handy, portable, cost-effective and highly effective as well. Such alarm systems are hugely in demand for security
purposes, and thus the given system can be proved useful and effective in view of the above features.
The sensors placed on the door informs the home owner as soon as the door is opened by sending a Push
notification. The user will get this notification irrespective of whether the phone is locked or unlocked or even if
any other app is opened at the moment. This was the main objective of the project, which is the user feels safe and
not worry about any intrusion or break-ins when he is away from home. This setup can also be used in commercial
offices where some areas are restricted for certain personnel, such a system will immediately inform the
administrator of any unauthorized personnel trying to access such an area.
39
References
Books
[1] Michael Mcroberts, Beginning Arduino.
Software
[2] Arduino IDE 1.0.6 from https://www.arduino.cc/en/main/software.
World Wide Web
[3] www.circuitstoday.com
[4] www.engineersgarage.com
[5] www.learn.adafruit.com
[6] www.instructables.com
40
Appendices
#include<SoftwareSerial.h>
#define trigPin 9
#define echoPin 10
#define piezoPin 8
SoftwareSerial mySerial(2, 3);
int normalDistance;
boolean triggered = false;
long duration, distance;
void setup()
{
mySerial.begin(9600);
Serial.begin (9600);
delay(100);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(piezoPin, OUTPUT);
digitalWrite(piezoPin, HIGH);
long duration, distance;
while (millis() < 5000)
{
digitalWrite(piezoPin, HIGH);
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance= duration*0.034/2;
normalDistance = distance;
Serial.print("Distance: ");
Serial.println(distance);
digitalWrite(piezoPin, LOW);
}
}
void loop()
{
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
41
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance= duration*0.034/2;
Serial.print("Distance: ");
Serial.println(distance);
if (distance < normalDistance-5)
{
triggered = true;
}
else
{
triggered = false;
}
if (triggered)
{
tone(piezoPin, 635);
delay(500);
tone(piezoPin, 912);
delay(250);
mySerial.println("AT+CMGF=1");
delay(1000);
mySerial.println("AT+CMGS=\"+918850230418\"\r");
delay(1000);
mySerial.println("Someone Entered!!!");
mySerial.println((char)26);
delay(1000);
}
}
42
43