Instructables

"Smart Shield" - Portable alarm system using Arduino

Picture of
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.
 
Remove these adsRemove these ads by Signing Up

Step 1: List of components

Picture of List of components
1.jpg
 
2. Motion detector (PIR sensor):
 
3. LCD screen (for showing the number of interrupts and their times of occurrences):
 
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.
 
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

Picture of 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:
http://www.instructables.com/id/Arduino-Basics-PIR-Sensor/
 

Step 3: Testing 2 - Adding a speaker and buttons to the simple circuit

Picture of 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:
 
crisnav091 month ago

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

Screenshot_2014-09-01-11-33-18.png

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

EranP (author)  crisnav091 month ago

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).

md1.pngScreenshot_2014-09-02-13-37-52.pngSearchingMode1.pngConnectedMode1.png
crisnav09 EranP1 month ago

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

crisnav09 EranP1 month ago

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 :) )

EranP (author)  crisnav091 month ago

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.

crisnav092 months ago

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.

EranP (author)  crisnav091 month ago

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.

BIGDOG12349 months ago

How do you add the app to your phone.

EranP (author)  BIGDOG12349 months ago

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/

BIGDOG123410 months ago
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.
EranP (author)  BIGDOG123410 months ago
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!
BIGDOG123410 months ago
I can not find StopWatch.h file.
EranP (author)  BIGDOG123410 months ago
Download the files (the rar files: StopWatch.rar, LiquidCrystal.rar) from step 9 and unrar them to your 'libraries' folder in the arduino files.
BIGDOG1234 EranP10 months ago
It did not work.
How do you unrar them.
EranP (author)  BIGDOG123410 months ago
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
BIGDOG123410 months ago
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.
EranP (author)  BIGDOG123410 months ago
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
BIGDOG123410 months ago
Could you post the code you use on your "Smart Shield" - Portable alarm system in one file.
EranP (author)  BIGDOG123410 months ago
Hi BIGDOG1234,

The Code for the arduino is in the first zip file (Smart_Shield.zip, 3KB).

The code for the app is in the second zip file (Smart Shield.zip, 853 KB).

The other 3 rar files containing the source code of the app. I've divided the source code to 3 smaller files in order to upload it successfully to the page (I've encountered some problems involving uploading large files).
sartikahusain11 months ago
pliss the tutorial with arduino uno....pleaseee
EranP (author)  sartikahusain11 months ago
Hi sartikahusain,

There are some differences between the two arduino cards: Leonardo & Uno, Mainly on the USB and serial communication.

The Arduino Leonardo differ from Arduino Uno in that it uses a single microcontroller to both run your sketches and for USB communication with the computer. The Arduino Uno uses separate microcontrollers for these two functions, meaning that the USB connection to the computer remains established regardless of the state of the main microcontroller.

you can read more on the differences by clicking on the link:
http://arduino.cc/en/Guide/ArduinoLeonardoMicro?from=Guide.ArduinoLeonardo#toc1

I've used the Leonardo card because it is cheaper and Leonardo is my favorite ninja turtle. I've not tried to build the alarm with Uno card, but I can't see why you can't try and build it with the Uno card, with minor adaptations and modifications.

The big change will be in the arduino code:
Choose Tools > Board > Arduino Uno.
In the arduino software code, before uploading it to the Arduino Uno, change all the serial1 lines to serial and erase all the duplicated lines (2 serial lines, one after another).

I can't see any reason why it won't work and when I'll get an arduino Uno card I'll start to experiment on it and add it to this tutorial.
sk8amazing1 year ago
it has problem with serial1
EranP (author)  sk8amazing1 year ago
Hi sk8amazing,

To verify the code successfully do the following on the Arduino software:

Tools -> Board -> Arduino Leonardo.

Note: Arduino Leonardo is the board which I worked with.

For more information with serial on other boards:
http://arduino.cc/en/Reference/Serial