of Things is the technology of the future which is slowly coming up and gaining momentum in the telecom industry. Here, we have tried to create a security system which is controlled by the Internet. The aim of the project was to develop a web application/tool which will give the user access to door locks and other appliances in the house. The existing applications which provide similar solutions have limitations such as, range, the number of devices that can be controlled, power consumption, high cost, low security and scalability. In our project the scalability is high as it is dependent on the Internet, low powered circuits are being used, high amount of data can be handled easily through Python coding, high security and privacy are possible due to the use of existing Internet protocols such as ‘https’.
Our project allows the user to lock the doors and open hem at any point, from any part of the world using the Internet. Sensors and motors are used to control the door and appliances which work based on the commands from the microcontroller, which has been interfaced with the Internet. The frontend of the project is based on PHP, HTML and CSS, while the backend is based on Python coding.
This project aims to provide a real time application, with the least amount of delay and maximum precision to improve the security systems in our homes and, increase accessibility to the users. It is a highly robust web tool compared to existing GSM based tools, which gives us real time notifications. What makes our tool robust is its ability to continuously update the sensor data such as the room temperature to the webpage.
Keywords – Arduino, Python, PHP, Serial communication, File handling, Automation
Step 1: Architecture
To briefly explain the entire architecture of the project. The frontend of the project is based on a XAMPP server, which uses Apache to simulate a client-server architecture environment.
The frontend consists of the webpage which can be accessed by the user from anywhere around the world, provided they have an Internet connection.
The XAMPP server is used to communicate with the Arduino UNO microcontroller through serial communication, based on Python code embedded in a PHP page. The Arduino UNO in turn accesses and controls the appliances connected to it via the PHP page. The devices have been connected in a star topology which makes it easy to add and remove new devices. Certain amount of sensor data is stored in text files which are refreshed every ten hours, to keep the data up to date.
Step 2: Front End And Back End
approach for automating the devices involves developing the Python code for controlling each device. The PHP page then has buttons for accessing the devices; each button is embedded with a Python code, on clicking the button a call is made to the Python code from within the PHP code. The Python code upon execution sends a character to the Arduino through serial communication. This character is then read by the Arduino, within the Arduino code a switch case exists, which then executes the code corresponding to the character received by it.
For the temperature and ultrasonic sensors a few additional steps exist; the Arduino first writes this character to a Python code serially, which is read by a separate Python code which along with the data received by the sensors through the Arduino is written to a text file and the values are finally displayed on the webpage.
The serial communication takes place at the back end which is responsible for connection of python and Arduino code , the python and Arduino code interact with each other by sending characters .Now at first the python code sends the character according to the button clicked . Once the serial character is sent to the Arduino code, based on a switch case it runs a specific program to execute the action. The result is again sent back to the python code through serial communication. Python code now interacts with the PHP code where it is called; once this is done the output is displayed from there in the webpage.
The frontend is that part of the webpage that is visible to the user. It is the representation of the tool that the user accesses to control the devices.
It is a simple user interface with tabs for home, access, tutorial and help pages. The access page diverts to the login and control panel pages. The control panel has buttons to control the devices and after a task is completed or unsuccessful, the result is displayed on the webpage for the user’s convenience.
The frontend figure describes the frontend control mechanism.
The backend comprises of the inner workings of the
webpage, which are not visible to the user. It comprises of Python, Arduino and PHP scripting that run in the background to execute the tasks as commanded by the user when using the webpage.
The backend figure describes the backend control mechanism.
Step 3: Circuit Design
Check the code of Arduino temperaturelockcontrolpanel.txt to get the pins to be connected and you can see the connection in the fritzing diagram regarding giving voltage , ground etc . For ultrasonic sensor the echo and trigger pin specifed in the program .. Temperature sensor LM35 analog pin used is A2 and for MQ2 A0 is used . The digital pins used can be seen in the text file
Below i am specifying the digital pins
The normal LED : digital pin : 9
The Fan 12V DC: digital pin : 13
Servo motor , Attach pin : digital Pin: 5
Buzzer : Digital Pin : 2
Echo for Ultrasonic Sensor . : Digital pin :6
Trigger for Ultrasonic Sensor : Digital Pin : 7
For the Intrusion Detection , RED LED : digital pin :11
GREEN LED : digital pin : 10
Step 4: Intrusion Detection
Here there Are two pictures , One where the LED is green showing no Intrusion . When Intrusion occurs the red light detects . The code can be seen temperaturelockcontrolpanel.txt file in the previous step in switch case ' h '. See through it You will understand how this works .
Step 5: XAMPP Setup
Before making the webpage . Please download xampp . You can do the same from the following link
Once you are done downloading you need to do the following changes as described so that your python codes can run in it .
follow these instructions
========================= Step 1: Edit the Apache httpd.conf scripts to run cgi .py scripts --------------------------------------- AddHandler cgi-script .cgi .pl .asp .py ---------------------------------------
Step 2: Add a test script of python called "new.py" in cgi-bin folder of xampp.
Step 3: Created a PHP Code called Python.php ---------------------------------- $python = exec('python C:xamppcgi-binnew.py'); echo "Python is printing: " . $python; ----------------------------------
Step 4: Restart XAMPP Server...
I am attaching Screenshots of codes present in my cgibin . So that when u see the name of the codes in programs further you can relate to where it comes from . I will upload all the python codes in text formats in future steps with the required modules requied .
Step 6: HTDOCS in Xampp
Here all the text files attached need to be in the htdocs folder of your Xampp
The HTML codes for the webpage have been added in further Steps . They need to be present in this folder too .
The following Text files need to be created in the same name ( case sensitive) as mentioned below in the htdocs folder . They are used for file handling to get action related output from Arduino from python . Python code then stores result received from Serial Communication in these text files.These text files are further Accessed by PhP and displayed in the webpage . Hence Providing Real Time Data. This Way File handling happens .
The text files to be created (CASE SENSITIVE):
1.LED.txt- Has all the output coming while clicking the LED ON button
2.LEDOFF.txt- Has all the output coming while clicking the LED OFF button
3.FANON.txt-Has all the output coming while clicking the FAN ON button
4.FANOFF.txt-Has all the output coming while clicking the FAN OFF button
5.DOORCLOSED.txt- Has all the output coming while clicking the DOOR CLOSE button
6.DOOROPEN.txt- Has all the output coming while clicking the DOOROPEN button
7.temperature.txt-Has all the output coming while clicking the Get Temperature button
8.ultrasonictest.txt-Has all the output coming while clicking the Start the Inrusion Detection System button
Step 7: Python Codes To Be In CGI BIN Folder
All the python codes are uploaded . Store in your CGI bin Folder
Required modules for each code will be told in the future Steps . Please download them . Or else the code wont work . These codes are for Python 2.7 version . Will not work for Python 3 version .
Step 8: Webpage
If the images are seen they are in the order below
Dont worry regarding the codes . I will explain the codes in the future steps along with the CSS .
The codes for
1. Home page-lockhome.html ,
2.Login page - loginpage.html ,the css for the login page is stored as style.css . Store the same as style.css in htdocs
3.Help page- helplock.html
4.Tutorial page- tutorial.html
Step 9: Control Panel
This is the control panel you get after you login from the login page . As seen in the image the buttons are self explained .
Get camera image button : It turns on your web cam which clicks the image and send it to your browser . I will upload the python code in future steps which works with the openCV module . I will put a separate step to explain how to install the modules and work with it .
Start Intrusion System . I will add steps further to show how this particular button works .
I am uploading the code for the Control panel in the led.php.txt file . Please Give importance to the following work below
1. Please go through this tutorial link i have modified the code for the same . Please use the database name , password ,username according to your settings . http://mrbool.com/how-to-create-a-login-page-with-... .
Using this link you can understand the first few codes in the "led.php.txt" file before the execution it is important to set things right in MySql because you enter the Username and Password you want to allow in the database . It checks for the values you have entered in the loginpage after the submit button . If the values entered for username and password are same as stored in the database, you login. It is a very simple tutorial link .
2. " led.php.txt" Text File contains the php code . you need to save this code in htdocs folder of XAMPP as led.php because led.php is the action for POST method in loginpage.html
3.Check the led.php code further to know how it works .
I am adding Screenshots of how output comes in the Control among clicking of buttons . The backend code in Python for wokring of all the buttons will be put in the next step . Please Refer to the steps further
At times your Sensors are not Working hence . The code is made such that It tells if the sensors are not connected or not .
Step 10: MODULES
Following below are the modules required downloaded
1. OpenCv module in Python for image processing . - The following link below tells how to install this module and use it
2.Pyserial . For serial communication