Smartly Secure Your Smart Home

by muhd18 in Circuits > Arduino

1122 Views, 13 Favorites, 0 Comments

Smartly Secure Your Smart Home

smartSec3.jpg
I am contesting for the safe and secure contest. If you like my instructable please vote for it!

I will show you how to easily and cheaply totally secure your home and its environment.
It contains of segments where you will learn how to:
1. Configure your fingerprint door lock system
2. Control your home and appliances even if you are absent
3. Configure cameras so as to have a large viewing range
4. Track stolen or lost devices and belongings
5. Activate some alarm systems due to certain reactions

Components

ethernetOn-Arduino.jpeg
9v-battery-cap.png
keypad3.jpeg
lcd-i2c2.jpg
lock2.jpeg
MKR-GSM.jpg
motor-driver.jpg
motor-dc.jpeg
PIRmotionSensor.jpeg
servo-motor.jpeg
white-led.jpeg
3.7v-2.jpeg
9v-battery.jpeg
buzzer.jpeg
0arduino-uno.jpg
cameraC1.jpeg
For the tracking system:
1x MKR GSM 1400 (https://www.store.arduino.cc)

For the camera:
1x Arduino Uno
1x Security camera
1x 100 uF capacitor
2x PIR motion sensor
1x Servo
Breadboard

For the fingerprint door lock system:
1x Arduino Uno
1x Adafruit LCD (16 x 2)
1x FPM1OA fingerprint sensor (Adafruit)
1x Motor
1x Motor driver
9V battery (optional)
2x 3.7V rechargeable battery
1x Lock
Veroboard

For the home monitoring system:
1x Arduino uno
1x Ethernet shield and RJ-45 network cable
1x LM35
1x Buzzer
1x LDR
1x PIR motion sensor
4x White LEDs
Breadboard/veroboard

Some of the above components can be gotten in any nearby retail store e.g the LED, batteries etc. Others can be gotten at AliExpress.com (https://aliexpress.com), ebay(ebay.com), Arduino(https://www.arduino.cc), Adafruit(https://www.adafruit.com) or Amazon(https://www.amazon.com)

Tools and Apps

3d_printer.jpg
_20190127_145332.JPG
_20190127_150139.JPG
3D printer
Multimeter
Soldering iron
Glue

APPS:
Arduino IDE (https://www.arduino.cc/en/Main/Software)
Fritzing (https://fritzing.org/download)

Overview of Components

The arduino board has a microcontroller acting as a brain, it receives and send signals for proper functioning.

The MKR GSM 1400 is an arduino board supporting GSM services like making call, sending messages etc. A sim card needs to be installed on it.

The Ethernet shield is normally mounted on the arduino board. It is used for communication over the internet. It has an SD slot so that the data in an SD card can be accessed.

Keypad is used for entering data into a system.

The L298N Motor driver is used for controlling the speed and direction of rotation of the motors.

PIR motion sensor consists of three pins, ground, signal, and power at the side or bottom. Large size PIR modules operate a relay instead of direct output.

Servo motors are geared DC motors with a circuitry incorporated within them. They compose of a DC motor, gearbox, potentiometer and control circuit. Normally used to turn devices to a required angle.

LM35 is a precision IC temperature sensor with its output proportional to the temperature (in degree Celsius).

LDR is a light dependent resistor, it can tell if a place is dark or not.

LCD is used as a display device. It displays alphanumeric characters.

FPM1OA fingerprint sensor is a sensor which determines and senses finger prints. It is used for security purposes.

Fingerprint Lock Electrical Wiring

finger_print&_sensor.JPG
finger_sensor_details.png
finger-lock-breadboard.jpeg
fingerprint.jpg
IMG_20190126_220202.jpg
lock00.jpg
keypad3.jpeg
lock2.jpeg
wiring-2-mine.jpeg
finger_sensor_back.png
As seen in the circuit diagram, all pins should be connected accordingly.
I used the 3.7V battery to power the motor, and used the USB connector to power the Arduino board. The 9V battery can be used if desired or as a backup.
The LCD connected to the Arduino board is used for interaction.
IDs are entered using the keypad connected to the Arduino board.
The fingerprint sensor checks for validity, also connected to Arduino board.
And finally, the DC motor controlled by the L298N module turns clockwise or counter-clock wise.
Note that the lock is attached to the motor and motor’s rotation opens/closes the door. There are several locks in the market, just get a suitable one.

Fingerprint Lock Code and Operation

Capture10.JPG
Capture1.JPG
Capture2.JPG
Capture3.JPG
Capture4.JPG
Capture7.JPG
Capture5.JPG
Capture6.JPG
Capture9.JPG
Capture8.JPG
For proper view, all the codes used in this instructable can be gotten here (https://drive.google.com/file/d/1CwFeYjzM1lmim4NhrlxIwW-xCREJmID6/view?usp=sharing). I have commented on every section of the codes for clarity.

To begin, I uploaded the “Enroll” code from the fingerprint library, and added a fingerprint.
Once the code is uploaded, the system is waiting for a finger to be placed on the sensor.
No need for fingerprint for someone inside, pressing the keypad opens the door. But for people coming in, the finger print is checked validity, if valid, the lock will open and a message is shown containing the name paired to the fingerprint ID, else door remains lock.

Let’s inspect the code!
The first line to the setup() function is just to set the stage ready.
Firstly, I included the libraries that I needed. (All the libraries are embedded in the link above)
Then configured the data transfer pins for my fingerprint sensor.
I then defined the pins used in the circuit diagram: i.e the pins for fingerprint sensor, the L298N driver module, the LCD.
I also declared some arrays, characters and integers. Also the passcode, which is 0000 by default, though can be changed.
I also configured the keypad by identifying its number of rows and columns; and its characters. Then I defined the digital pins it was connected to.
Then I configured the fingerprint module with the library and declared the ‘id’ variable.

Next is the setup() function that runs only one after when the system is on.
I set the baud rate of the serial communication to 9600; and that of the fingerprint to 57600.
I configured the L298N driver pin modes to ‘OUTPUT’.
I determined the LCD’s size, cleared the screen and displayed "Standby".

Then followed the loop() function, where execution occurs.
I determined the input character:
If it is ‘A’, it means a new template wants to be added. Therefore, a passcode is requested which is set to 0000 (can be modified), if it doesn’t match it "Wrong Passcode" will be displayed.
If it is ‘B’, door is opened for 6 seconds for exit.
Then "Place finger" is displayed after.

After the loop() are the OpenDoor() and CloseDoor() for opening and closing the door.
Next is the getPasscode() function. It gets the passcode typed and store them in c[4] array and compares if it is correct.

Next is the Enrolling() and getFingerprintEnroll() functions used for enrolling a new ID using the readnumber() and getImage() functions. After, "Place finger" and "Remove finger" are displayed when finger is to be placed or removed. I used the normal fingerprint scanning method i.e image of the same finger is taken twice.

The readnumber() function gets the ID number as 3 digits format and returns the number to the enrolling function. Note the ID range is from 1 to 127.

Finally comes the getFingerprintIDez() function, I called it in the loop. It scans a fingerprint and gives it access if recognised. If fingerprint is not recognised, "Access denied" is displayed, after 3 seconds "Place finger" message is displayed again.
For a recognised fingerprint, a “welcome” message and its ID is displayed. Then door opens.

Doors are now secured, it remains the environment and inside the house.

Extending the Ranges of Cameras

PIRmotionSensor.jpeg
cameraC1.jpeg
servo-disk.jpeg
Cameras are used both indoor and outdoor but sometimes the viewing and rotating ranges are not favourable. This might not make the security tight enough unless more are installed.
So instead of using up to three cameras where one can be used, I designed a stand for the cameras. This stand rotates the camera to different angles. So this enables me to have more than 230 degrees viewing range. This also save the cost of unnecessary cameras and unnecessary troubleshooting.
This was how I worked it out:
I used the servo motor and PIR motion sensors.
I got a base and installed the servo in it. Then installed two PIR motion sensors.
I got a bigger base to contain the wiring. I attached a plate on the servo and placed the camera on it so that the servo rotates the camera.
The 3D printer was used to print the plastic stand and plate.
Therefore, the servo turns to the direction of the PIR motion sensor that senses motion.

The Motion Following Camera Circuit Design

IMG_20190126_223001.jpg
circuit_bb.jpg
The Motion sensors are connected to the arduino uno, with the VCC to 5V, GNG to GND and the signal pin to pins 2 and 3.
The servo is connected to pin 4. The 100 uF capacitor is connected between the servo’s GND and VCC.
Note: The motor driver can also be used to drive the servo.

The Rotating Camera Code

Capture1.JPG
capture2.jpg
I included the needed library, then created a servo object. Next I defined the Pins for PIR sensors. I then declared the camera’s angle of rotation and initialize the previous and current states of the servo.
In the setup() function, I attached the servo’s pin and configured the pinModes for the PIR sensors, then set the camera to the middle.
In the loop() function, I declared variables to get the data at the pins. Then determined the state of the motion sensors so as to know where to turn to. If there is a change is state, the turning angle is set to the appropriate state; else position is maintained. Finally, I set previous to current State and loop starts over.

Controlling Home and Appliances

webpage.jpg
_20190126_222601.JPG
To reinforce the security of the house, I used the Ethernet module, LDR, LM35 and motion sensor to be on track with the house. With these, I was able to:
a) Control appliances via the Ethernet;
b) know the status of the environment like the temperature e.t.c;
c) Know if someone is in the house.

The Wiring and Circuit

circuit_room_control.jpg
The Ethernet shield is mounted on the Arduino Uno. The RJ-45 network cable is required for router connection or modem.
The buzzer, motion sensor, LED bulb are connected to the digital pins 2, 3 and 6.
I made the LED bulb by soldering 4 bright LEDs in parallel on a veroboard, then enclosed it with a transparent perspex. The two output wires go to the circuit. (A similar one can be gotten in the market).
The LDR and LM35 are connected to the analog pins 0 and 1.
The other pins go to the GND, the third pin for the PIR and LM35 goes to the power supply.

Home Control Code and Operation

Capture1.JPG
Capture2.JPG
Capture3.JPG
Capture5.JPG
Capture4.JPG
I included the libraries, the defined the Buzzer, PIR sensor, LED, LDR, LM35 pins.
The MAC address is on the shield, it should correctly be specified. The ip address should also be specified. Next is the request variable and web server address.
Next is the setup() function, I configured the pin modes and initialized the server and Ethernet shield connections.
In the loop() function, I declared some variable, called functions and took readings at inputs. Then rooms' brightness is checked whether to on the light. Then clients are listened to and http request is also checked. What comes after controls the webpage display showing room status and buttons to perform some actions.
After the loop comes some functions for light control:
The onLight() function on the light to its maximum brightness.
The offLight() function off the light.
The dimLight() function on the light to quarter of its brightness.

Tracking Devices

track_1_MyS8MNGN27.jpg
I designed a security system that can get the position of my devices on my smartphone via an SMS with a Google Maps link to it.
I used an Arduino MKR GSM 1400, an antenna and a LiPo battery pack. A working SIM card is also required. PIN, APN and other credentials are required to connect to the network.
When I sent an SMS with the request character, I received an SMS received containing the Longitude and Latitude and the Google Maps link.
To set it up, the antenna is connected to the board with the SIM card inserted, then the battery is connected to the JST connector as seen in the diagram above.
After, it can be attached to any device so that when stolen or lost, it can be recovered.

The Working Code

Capture1.JPG
Capture2.JPG
Capture3.JPG
The first section is to import needed libraries.
Then comes the PIN, APN, username and password. This should be filled.
Next is the setup() function, location object is initialized and data connection is established.
After is the loop() function, the getLocation() function was called, then if an SMS is received , it is checked if the correct request message is entered, which here “T”, if the character is correct, an SMS containing device location is sent. Note: The request character can be changed.
To minimize power consumption, the board is hibernated for 70 seconds.
The getLocation() gets the coordinates by cellular network, if new coordinate are available it updates it.
The connectNetwork() function uses the gsmAccess.begin and gprs.attachGPRS methods to connect the board to the data network.

Finalization

Implementing the above systems makes one secure. It is a technically driven system, therefore easy to control.
Note that to maximize power usage, USB ports can be used instead of the batteries (if the ports are readily available).
I have comprehensively commented on the codes for easy understanding and correct functionality, so also the working principles. Don't forget to extract the libraries to the correct directory.
Also, security cameras should be wisely installed in such a way that they camouflage with the environment.
Bye, wishing you a secured day ahead.