This project is a simple solution for those who want a smart-home system but do not have a big budget and for the lazy ones that do not want to get up from bed to turn the lights off or on.
It also is the project of a high school student for his final exams!
This is just a basic configuration but with a little more time and dedication you could customize by adding more sensors, LEDs, relays and scheduled jobs to start with the execution of a PHP script from the web server.
I am using a free web-hosting service called Altervista which includes the SQL database server (with phpMyAdmin) and the php server.
To realize this project you will need:
Hardware:
Software:
So, to send the requests from the Internet to Arduino we will use a web service called Teleduino.
Just register and wait for the email containing the unique key, after that follow the instructions on how to install the libraries and how to turn a LED on or off.
Make sure to download and correctly link the library.
If you have any problems you can contact the developer of this web service.
In order to save the data from the sensors we will need to set up a MySql database.
In this case there are 2 tables: sensor_log and users.
CREATE TABLE `sensor_log` ( `id` smallint(6) PRIMARY KEY AUTO_INCREMENT, `timeStamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `temp_0` float DEFAULT NULL, `hum_0` float DEFAULT NULL, `temp_1` float DEFAULT NULL, `hum_1` float DEFAULT NULL, `temp_2` float DEFAULT NULL, `hum_2` float DEFAULT NULL, `light_0` float DEFAULT NULL, `light_1` float DEFAULT NULL, `light_2` float DEFAULT NULL, ); CREATE TABLE `users` ( `username` char(30) PRIMARY KEY, `password` char(50) NOT NULL UNIQUE, `is_connected` tinyint(1) NOT NULL DEFAULT '0', );
The Arduino I am using for this project is the Mega 2560 so you
will have to adjust the functions / pins / libraries in the .ino file if you are using a different board.
The sketch's logic is pretty simple:
In the setup() function the Arduino gets an IP address, connects to the Teleduino server and initializes the sensors.
In the loop() function it loops until a request arrives and every 60 seconds it gets the data from the sensors and sends it with the POST method to a php page that adds it to the database.
There is a custom function called .getReset() and to make it work the files Teleduino2560.cpp and Teleduino2560.h (in the libraries/Teleduino2560 folder) must be replaced.
The web app is composed by:
The buttons send the GET request to the Teleduino server that turns on / off the pin on the Arduino.
The charts are made with a library called CanvasJS.
You will find everything in the .zip file.
N.B. You will have to add the Teleduino key and the credentials to access the database !