loading

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

Step 4: Testing 3 - Testing the LCD Screen

Picture of Testing 3 - Testing the LCD Screen
2.jpg
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

Picture of Testing 4 (optional) - Setting communication between the arduino and the PC with a USB cable, using processing
1.jpg
3.jpg
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:

Step 6: Testing 5 (optional) - Setting communication between the arduino and the PC with the bluetooth module, using processing

Picture of Testing 5 (optional) - Setting communication between the arduino and the PC with the bluetooth module, using processing
2.jpg
3.jpg
4.jpg
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

Picture of Building the system - Electrical diagram
3.jpg
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

Picture of Uploading the code to arduino

Connect the arduino card to the PC with the USB - 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

Picture of Android app
3.jpg

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.

crisnav0911 months 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)  crisnav0911 months 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 EranP10 months ago

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

crisnav09 EranP10 months 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)  crisnav0911 months 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.

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

BIGDOG12341 year ago

How do you add the app to your phone.

EranP (author)  BIGDOG12341 year 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/

BIGDOG12341 year 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)  BIGDOG12341 year 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!
BIGDOG12341 year ago
I can not find StopWatch.h file.
EranP (author)  BIGDOG12341 year 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.
It did not work.
How do you unrar them.
EranP (author)  BIGDOG12341 year 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
BIGDOG12341 year 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)  BIGDOG12341 year 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
BIGDOG12341 year ago
Could you post the code you use on your "Smart Shield" - Portable alarm system in one file.
EranP (author)  BIGDOG12341 year 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).
pliss the tutorial with arduino uno....pleaseee
EranP (author)  sartikahusain1 year 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