"Smart Shield" - Portable Alarm System Using Arduino

15K3925

Intro: "Smart Shield" - Portable Alarm System Using Arduino

PIR Sensor is connected to the arduino card. When a motion is being detected, an alarm sound and flashing LEDs will start to act. The times of the motion detections are saved, and can be viewed later on a small LCD screen. The data (motion detections) is sent via bluetooth and can be viewed on a smartphone by a designated app for android.

STEP 1: List of Components

1. Arduino board:
2. Motion detector (PIR sensor):
http://www.dealextreme.com/p/intelligent-pir-infrared-motion-sensor-module-white-dc-5-24v-129559
3. LCD screen (for showing the number of interrupts and their times of occurrences):
http://dx.com/p/lcd-keypad-shield-for-arduino-duemilanove-lcd-1602-118059?item=1
4. Small Speaker / piezo speaker.
5. LED / Flashing LEDs.
6. Push-button + 10k resistor.
7. Network module (serial communication):
PC connection: mini-USB to USB cable.
Bluetooth module (wireless):
JY-MCU - Specifications:
Dimensions: 4.4 cm x 1.6 cm x 0.7 cm (1.73 in x 0.63 in x 0.28 in)
Weight: 7g (0.25 oz)
Range: ~10 m (~33 ft)
Supply voltage: 3.6-6V
BT-Name: linvor
BT-Pin: 1234
BT-Baudrate: 9600bps (standard)
8. Wiring components: solderless breadboard, board, wires, connectors, headers.
breadboard-adapter-kit: http://dx.com/p/arduino-breadboard-adapter-kit-3-piece-pack-139958
male-headers: http://dx.com/p/2-54mm-1x40-pin-breakaway-straight-male-header-10-piece-pack-144191?rt=1&p=2&m=2&r=3&k=1&t=1&s=152192&u=144191
9. Power input: 9V battery + battery case + connector + switch / external adaptor for arduino.
10.  A box (for containing all above, in a neat pack).
Software (the version I used mentioned in brackets, but a newer version for any software may work too):
1. Arduino Software (Ver. 1.0.1): http://arduino.cc/en/Main/Software
2. PC – Processing (Ver. 2.0b6), for testing purposes: http://www.processing.org/
3. Terminal - Tera Term (Ver. 4.75), for testing purposes: http://logmett.com/index.php?/download/tera-term-476-freeware.html
4. Android app "Smart Shield" (Android Developer Tools, Build: v21.0.0-531062), for developing in android (for anyone who wants to understand the code and to improve the app): http://developer.android.com/index.html

STEP 2: Testing 1 - Building a Simple Circuit With the Arduino, Motion Detector and LED Indicator

The PIR Sensor is connected to the arduino card. The LED is turned on by a motion detection for 15 seconds.

Instructions:
https://www.instructables.com/id/Arduino-Basics-PIR-Sensor/

STEP 3: Testing 2 - Adding a Speaker and Buttons to the Simple Circuit

I connected a speaker and a LED to the arduino and the PIR sensor.
The speaker makes an alarm sound that goes on and off and the LED turns on and off repeatedly.
Instructions:

STEP 4: Testing 3 - Testing the LCD Screen

1. The LCD Keypad Shield is connected to the arduino card.

Instructions:
http://www.hobbytronics.co.uk/arduino-lcd-keypad-shield

2. LCD Keypad Shield is connected to the arduino card. I uploaded the the code for a timer. The time in seconds, milli-seconds and micro-seconds can be shown on the LCD Screen. Pressing the 'RST' button resets the timer.

Instructions:
http://www.arduino.cc/playground/Code/StopWatchClass

STEP 5: Testing 4 (optional) - Setting Communication Between the Arduino and the PC With a USB Cable, Using Processing

Requires a LDR light sensor and a 1k resistor.

I connected LDR light sensor and the 1K resistor to the arduino.
When the light intensity is low, the LED 'L' on the arduino card is deactivated.
When the light intensity is high, the LED 'L' on the arduino card is activated.
Data is sent via USB cable to the processing software. Circle size changes when exposed to different light intensities.
Instructions:
http://webzone.k3.mah.se/projects/arduino-workshop/projects/arduino_meets_processing/instructions/ldr.html

STEP 6: Testing 5 (optional) - Setting Communication Between the Arduino and the PC With the Bluetooth Module, Using Processing

Requires a LDR light sensor, a 1k resistor and an external battery.
1. I connected the bluetooth component and the external battery to the circuit containing the LDR light sensor and the 1k resistor.
The red light on the bluetooth blinks when it is receives power
The red light on the bluetooth permanently lit when a stable connection is created to other communication component.
Instructions:
2. Attention: To create a successfull communication between the bluetooth (connected to the Rx / Tx inputs of the arduino) and the PC, I changed the "serial" in the code to "serial1".
The standard "serial" is reserved for the USB input and the "serial1" is reserved for the Rx / Tx inputs
 and is required to properly communicate via the bluetooth component.
3. Communication test via COM6 port using Tera Term terminal. The numbers represent the light intensity (from 0 to 1023, where 0 is the brightest and 1023 is the darkest).

STEP 7: Building the System - Electrical Diagram

Power input:
Internal input: By batteries (6 batteries, 1.5V each) or 9V battery to the power input of the arduino card.
External input: By an external transformer (9V, 1A) to the 2.1mm input or via USB cable to the mini USB input of the arduino card.
Wiring:
Arduino (Top: left to right):
GND - LED/s (GND), Speaker (GND).
Digital 13 - LED/s (Vcc).
Digital 12 - Pushbutton (right leg).
Digital 11 - Speaker (Vcc).
Digital 10, 9, 8, 7, 6, 5, 4 - LCD Keypad Shield (D10, D9, D8, D7, D6, D5, D4).
Digital 2 - PIR Sensor (OUT).
Digital 1 (TX) - Bluetooth module (RXD).
Digital 0 (RX) - Bluetooth module (TXD).
Arduino (Bottom: left to right):
Reset - LCD Keypad Shield (RST).
5V - Bluetooth module (Vcc), PIR Sensor (Vcc), LCD Keypad Shield (5V), 
Pushbutton (with a 10k resistor between the 5v and the middle leg of the pushbutton).
Gnd - Bluetooth module (GND), PIR Sensor (GND), LCD Keypad Shield (GND), Pushbutton (left leg).
Gnd - 9V connector (-).
Vin - 9V connector (with a switch between the Vin and the +).

STEP 8: Building the System - Into the Box

I installed all of the components in the box and wired them. I made some cuts to the box to make the components fit nicely and some holes in the box for a better sound from the speaker.
In the front view, you can see the LEDs with a plastic cap and the PIR Sensor.
In the rear view, you can see the LCD Screen and the Keypad.
In the right view, you can see the switch and the pushbutton.
In the left view, you can see the mini-USB input and the external power input of the arduino.

STEP 9: Uploading the Code to Arduino

Connect the arduino card to the PC with theUSB - mini-USB cable.

Run the Arduino software.

It can be downloaded here: http://arduino.cc/en/main/software
Download the zip file in this page: "Smart_Shield". Open the code in the zip file in the Arduino software (Fie -> Open...).

Download the libraries StopWatch and LiquidCrystal(Unzip them to the 'libraries' folder in the arduino folder).

For more information on these libraries, check out the following links:

http://playground.arduino.cc/Code/StopWatchClass

http://arduino.cc/en/Reference/LiquidCrystal

Choose the board: Tools -> Board -> Arduino Leonardo.

For other boards, see more information regarding the serial1 connection (to avoid compatibility issues): http://arduino.cc/en/reference/serial

Verify The code and upload to the arduino.

STEP 10: Android App

I wrote Android smartphone app (I have Samsung Galaxy S, running Android version 2.3.3) and it works.

The app connects to the "Smart Shield" device via bluetooth and receives alerts and notifications when a motion is detected.

I'm still trying to improve the app and develop more features and fix some bugs. This is an open source, so you can improve the app by changing the source code and adding to it.

You can view the source code in GitHub: https://github.com/EranPe/Smart-Shield/


Both the source code and the app are available to download in this page.

Smart Shield (ver. 1.1) for android.

25 Comments

thank you so much for the information sir :)

hhmm i still have a question, the android application smart shield v 1.1 is not functioning on the android phones that i have used. The bluetooth module which is hc-05 is already connected to the phone, but when i open the application the bluetooth sign on the upper part is not activated. Unlike on the screen shot that you have posted above. What should i do for this instances sir? thank you

and also, when i click the preferences and about. There's nothing happened.

Hi crisnav09,

I'm really glad that you've interest in this project.

The bluetooth communication between the Alarm System and the PC/android device is the most tricky part of the project, for my opinion. There are several things you need to check before using the android app. First, make sure that the bluetooth serial output of the Alarm System is working well. You can do this by a simple test*:

1. Connect a bluetooth dongle to your PC.

2. Power on the Alarm System. Wait for the "Alarm is active!" message.

3. Pair between the PC and the Alarm System by searching for the right bluetooth connection (HC-05, in your case) and insert the right code (1234 / 0000). Wait for pairing between the 2 devices.

4. Run the Tera Term software (You can download it here: Tera Term).

5. Make a new connection. Choose serial and insert the correct port (COM4 in my case, as seen in the attached photo).

6. Make sure that the baud rate is 9600 and the incoming data are as seen in the attached photo.

* you can also try this test on an android device with a compatible app. For more information on this, click on the link.

If the data, recieved from the Alarm System, are good ,then it's the time to check the android app.

Make sure that the phone and the Alarm System are within the bluetooth range (<10m). There are 2 states: "Trying to connect..." and "Connected" in the Android app (photos attached). I see that you "stuck" on the first state. Follow these steps to make sure the connection is good:

1. Wait for the "Alarm is active!" message to appear on the Alarm System, for a stable bluetooth transmission.

2. Try to disable and enable the bluetooth on the phone and then start the app.

3. If it doesn't work, restart the Alarm System and repeat stages 1-2.

I hope this will work for you. I tried it on my nexus 5 (Android 4.4.4) and it worked (photo attached).

it works on tera term, but still, it didn't work on the application :( it's still not connected

thank you so much for responding ^_^
i will now start doing what you've told .. hope it will works :)

(sorry for the english, i'm not use to it :) )

Hi crisnav09,

You're right. The app is still in development and a little bit "buggy", as mentioned in step 10. The menu is incomplete and the "preferences" and "about" options are not working yet, but the "clear history" option is working.

The app is adding a new alarm message to the list of the alarms and receiving a new notification in the notifications bar, when there's a new detection of motion from the Alarm System.

I'll consider on working on a new app that will replace the old one for improving the features.

good day ! hhmm I just want to ask , what if i would like to use a 9 volts charger as power source that is directly connected to the arduino power source. Do I still need to use rocker switch and push button switch? .. and oh by the way, I will no longer be using a 9 volts battery. Thank you.

Hi crisnav09,

The answer is Yes.

From the Arduino Leonardo website:

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.

You can also power with the board's USB port.

For example:

You can choose to power the Alram System with a charger connected directly to the board's USB port, like a contemporary smartphone charger, with a voltage of 5V and a current of 1A. It works fine and the charger is cheap.

Another example of power usage:

You can also choose a rechargeable battery (like the ones for charging smartphones) to power the Alarm system with a cable to the board's USB port.

In any case of external power (power jack or USB port), you won't need the rocker switch, however, you'll still need the push button switch if you want to switch between 2 states: "silent" alarm and "noisy" alarm.

How do you add the app to your phone.

Download the Smart Shield.zip in step 10 and unzip the apk file in your pc.

Use a USB cable to transfer the apk file to your android smartphone (no iOS or other moblie OS yet, sorry...).

On the smartphone, go to Settings, scroll down to Security, and select Unknown sources. Selecting this option will allow you to install apps outside of the Google Play store.

Install the apk file.

For more information on "How to install apps outside of Google Play" follow the link:

http://howto.cnet.com/8301-11310_39-57602654-285/how-to-install-apps-outside-of-google-play/

Now when I verified the code I got this:
Smart_Shield.ino: In function 'void setup()':
Smart_Shield:85: error: 'Serial1' was not declared in this scope
Smart_Shield.ino: In function 'void loop()':
Smart_Shield:135: error: 'Serial1' was not declared in this scope
Smart_Shield:165: error: 'Serial1' was not declared in this scope
Smart_Shield:188: error: 'Serial1' was not declared in this scope

What do I do.
It seems you have a serial problem.

What kind of board do you have?

The Arduino Leonardo board uses Serial1 to communicate via TTL (5V) serial on pins 0 (RX) and 1 (TX). Serial is reserved for USB CDC communication

All Arduino boards have at least one serial port (also known as a UART or USART): Serial. It communicates on digital pins 0 (RX) and 1 (TX) as well as with the computer via USB. Thus, if you use these functions, you cannot also use pins 0 and 1 for digital input or output.

You can use the Arduino environment's built-in serial monitor to communicate with an Arduino board. Click the serial monitor button in the toolbar and select the same baud rate used in the call to begin().

For more information, refer to:
http://arduino.cc/en/reference/serial

Good Luck!
I can not find StopWatch.h file.
Download the files (the rar files: StopWatch.rar, LiquidCrystal.rar) from step 9 and unrar them to your 'libraries' folder in the arduino files.
To use this library, make a folder in your SKETCHBOOKPATH\libaries with the name StopWatch and put the .h and .cpp there. Close all your IDE's and then it is ready to use.

For further information, go to the following link:

http://playground.arduino.cc/Code/StopWatchClass
When I verified the code I got this:
Smart_Shield:29: error: 'StopWatch' does not name a type
Smart_Shield:30: error: 'StopWatch' does not name a type
Smart_Shield:31: error: 'StopWatch' does not name a type
Smart_Shield:32: error: 'StopWatch' does not name a type
Smart_Shield:33: error: 'StopWatch' does not name a type
Smart_Shield:34: error: 'StopWatch' does not name a type
Smart_Shield.ino: In function 'void setup()':
Smart_Shield:83: error: 'Serial1' was not declared in this scope
Smart_Shield:85: error: 'sec' was not declared in this scope
Smart_Shield.ino: In function 'void loop()':
Smart_Shield:133: error: 'Serial1' was not declared in this scope
Smart_Shield:163: error: 'Serial1' was not declared in this scope
Smart_Shield:166: error: 'sec1' was not declared in this scope
Smart_Shield:167: error: 'sec2' was not declared in this scope
Smart_Shield:168: error: 'sec3' was not declared in this scope
Smart_Shield:169: error: 'sec4' was not declared in this scope
Smart_Shield:170: error: 'sec5' was not declared in this scope
Smart_Shield:186: error: 'Serial1' was not declared in this scope
Smart_Shield:196: error: 'sec' was not declared in this scope
Smart_Shield:211: error: 'sec' was not declared in this scope
Smart_Shield:214: error: 'sec' was not declared in this scope
Smart_Shield.ino: In function 'void KeypadPressed(int)':
Smart_Shield:321: error: 'sec' was not declared in this scope
Smart_Shield:351: error: 'sec1' was not declared in this scope
Smart_Shield:352: error: 'sec2' was not declared in this scope
Smart_Shield:353: error: 'sec3' was not declared in this scope
Smart_Shield:354: error: 'sec4' was not declared in this scope
Smart_Shield:355: error: 'sec5' was not declared in this scope
Smart_Shield:381: error: 'sec' was not declared in this scope
Smart_Shield:412: error: 'sec1' was not declared in this scope
Smart_Shield:413: error: 'sec2' was not declared in this scope
Smart_Shield:414: error: 'sec3' was not declared in this scope
Smart_Shield:415: error: 'sec4' was not declared in this scope
Smart_Shield:416: error: 'sec5' was not declared in this scope
Smart_Shield:442: error: 'sec' was not declared in this scope
Smart_Shield:459: error: 'sec' was not declared in this scope
Smart_Shield:485: error: 'sec' was not declared in this scope

What do I do.
Hi BIGDOG1234,

It seems there are some library files missing, such as StopWatch.h file.
Download the libraries from step 9 (Unzip them to your 'libraries' folder in the arduino files).

For more information on these libraries, check out the following links:

http://playground.arduino.cc/Code/StopWatchClass

http://arduino.cc/en/Reference/LiquidCrystal

For the serial1 problem, check that you have the right board (I've used the Arduino Leonardo board). Choose the board on the arduino software: Tools -> Board -> Arduino Leonardo (In my case).

For other boards, see more information regarding the serial1 connection (to avoid compatibility issues): http://arduino.cc/en/reference/serial
Could you post the code you use on your "Smart Shield" - Portable alarm system in one file.
More Comments