Free Smart Home

3,542

22

4

Who has never dreamed living in a smart home? Having all automated systems controllable from your smartphone and computer. Home automation is an increasingly important part of connected house. It makes daily life easier by automatically performing small and simple tasks. Unfortunately, the various brands on the market generally only offer expensive and not very flexible product range. We worked on a solution which makes home automation accessible to all by using a raspberry pi, ESP32 and some sensors and actuators.


The objectives are multiple but simple to understand. We want to offer all makers the opportunity to build their own home automation management system with a Raspberry pi. All our codes are open-source and available for you on this instructable. We design the programs so that they are simple and easy to install by people with little experience in electronics and computers. Be aware, however, that several different programming languages are used in different parts of the project. A person with very little experience in programming could unfortunately be quickly lost. Finally, we hope that the project will be easily scalable. You could choose what really interests you!

We plan to develop different modules such as:

  • Control camera
  • Central unit for weather and water tank
  • Lighting management
  • Heating management
  • Pet food management
  • Remotely controlled electric shutters.

As all the codes will be open-source, you will be able to easily appropriate the different programs. Eventually, you can even add your own module that will perform simple tasks for you. Everything is possible with home automation. The limit is your imagination

We made an humorous video to present the project, check it if you want:


Step 1: Preparing the Raspberry

For this project, you will need a raspberry pi with SD card, a charger and a housing. You can buy the raspberry pi board alone or in a pack.

Here some examples :

First of all, you need to install Raspbian operating system on the SD card following this tutorial: https://thepi.io/how-to-install-raspbian-on-the-r...

Once Raspbian installed, you need to connect a keyboard, mouse and monitor with the HDMI cable. Proceed to first start of the pi like explained in the following link:

Now, if everything is correctly installed, you should have access to the raspberry desktop.

You can configure your raspberry to access it from your computer. With this feature, you don’t need to connect a keyboard, mouse and monitor to access your raspberry anymore. There are two ways to do it :

Software : https://www.raspberrypi.org/documentation/remote-...

Step 2: Install Web Server

Now, your raspberry is ready. For this project you need to host the website in order to control all the system from your computer or your smartphone. To install the web server on your raspberry, follow this tutorial below. You need the part about the HTML and PHP, the SQL part is not used in this project so you don’t need to install it.

https://www.raspberrypi.org/documentation/remote-a...

Next, copy all website’s files on the Pi using WinSCP software. Follow the instruction of the installation software. Software : https://winscp.net/eng/download.php

All files needed for the website are available with the following Mega link in the folder “Web_programming”.

Méga link : https://mega.nz/#F!m8gwDADB!w0uWdQlT7ixLPJfP6khps...

Copy website : using pi’s address, go to /var/www/html and paste those files

When you have downloaded the website files to the raspberry, you need to add special access right in order to allow the modification of the files on the website. To do that, open WinSCP, right click on the “data” file, write 0777 inside the text area and select the “apply recursively” checkbox. Click the “OK” button.

On the “settings” webpage, there are two buttons to restart or turn off the raspberry. To make them work, you need to edit a file :

  • With PuTTY opened or from the shell prompt on the desktop, type: sudo nano /etc/sudoers
  • Add this line at the end of the file : www-data ALL = NOPASSWD: /sbin/reboot, /sbin/halt
  • Save and quit (CTRL + O ENTER CTRL+X)

Step 3: Access Website From Outside (optional Feature)

Create access for the web server from outside of your home

https://readwrite.com/2014/06/27/raspberry-pi-web-...

Sometimes your router’s external address (WAN) is private. Check if the Wan address found inside your router is the same as IP detected by https://www.speedtest.net. If it is not the case, contact your internet service provider to receive a public address.

Step 4: Global Software

All project modules are made to be connected wirelessly to the raspberry. So, each module has his own electronic board that must be programmed from the Arduino IDE. To install this software, follow this link.

Software : https://www.arduino.cc/en/Main/Software

Follow this tutorial to add ESP32 boards inside Arduino IDE. https://randomnerdtutorials.com/installing-the-es...

Sometimes you need to add the following drivers : https://www.silabs.com/products/development-tools...

Download and add MQTT libraries in your Arduino IDE. Use the “clone or download” button, select “download zip”.

PubSubClient.h : https://github.com/knolleary/pubsubclient

Inside Arduino IDE, go to sketch < add a library < add a library .zip

For each module that you want to use (Light, Heating, Outside Station, …), download the corresponding ESP32 code from the Mega link below (folder “Arduino_programming”)

Mega link : https://mega.nz/#F!m8gwDADB!w0uWdQlT7ixLPJfP6khps...

Then, open ESP32 code and connect your ESP32 by USB to the computer. Select the port (tools) and the card (DOIT ESP32 DEVKIT V1) like in the picture below. Finally, upload the code to the ESP32.

Step 5: Module Central Heating

The purpose of the "Heating" module is to replace the conventional thermostat of a heating system with a remotely controllable thermostat. The web interface makes it possible to modify the different setpoints, the operating hours and to trigger the system remotely.

An additional option also makes it possible to control a ventilation system in the case of a hot air heater. This ventilation can be used to better circulate the air in the house (summer and winter).

Note : this technical solution need to be adapted to the specifications of your heating system. Never try to replace or avoid an existing security of your heating system ! The device proposed here is an upgrade of the thermostat that has no impact on the security.

Refer to the wiring diagram for the wiring of the module.

Materials requirements (~15€, Raspberry excluded)


Explication

Open the Arduino sketch heating.ino with the Arduino IDE.
Add your Wifi information inside the Arduino Sketch. You can modify the default setpoint value (value used after a reboot of the ESP32). Upload the sketch inside the ESP32 board using the arduino IDE. Do not connect any external alimentation while you are connected to your computer.

Create your circuit on a breadboard ant test it. If tests are OK, you can solder your components.

On your Pi, open the console and type the command :

python /var/www/html/etc/heating_program.py

If it works, you will see printed on the screen the temperature and the moisture detected by the ESP32. Now you can use the website to send the parameters.

Web page

On the homepage, click on the flame icon. The page on which you arrive allows you to consult the temperature of the room and its humidity. This page also allows heating to be switched to automatic or stop mode. It also allows you to activate the boost. The boost temporarily increases the temperature beyond the usual parameters. This option is useful when you feel cold or when you take a shower. You can also force or disable ventilation. If you choose the ventilation option in automatic mode, it will start at the same time as the heating. In the bottom part of the page, you can see the current state of the relay. To send your changes, click on the button "apply changes".

The second page accessible by clicking on the gear icon makes it possible to modify the different parameters. The heating setpoint is the desired temperature during the day. The night setpoint is the desired temperature at night. Anti-freezing is the temperature to prevent freezing. This feature is not implemented yet. You are free to develop it. The boost is the temperature temporarily added to create a hot blow effect. The deadband sets the interval around the set temperature at which the temperature of your house will be between two periods of heating operation. A small gap allows a better comfort but causes more ignition and extinction of the heating system. To send your changes, click on the button "apply changes".

The third page (This feature is not fully implemented) accessible by clicking on the stopwatch icon allow you to define the heating periods (uses the heating setpoint) and the cooler periods (uses the night setpoint). For each day of the week you can set two heating periods. The rest of the day will be a cool period. You can, of course, decide at any time to activate or deactivate the heating between two programmed periods using the buttons on the first page. To send your changes, click on the button "apply changes".

Step 6: Module Pet Food

This module allows you to know how much food remain in your storage room for your pet. So, even when you’re not at home you can know if you have to buy some or not when being at the supermarket.

Note : It was rather simple to build but needed a 3D printer for some parts. If you don’t have a 3D printer, you can still create the parts by yourself.


Materials requirements

  • HX711 module with a strain gauge (choose a correct strain gauge following your needs) (~11€)
  • A wooden bin with the size that you wanted (~30€)
  • Some connexion parts for the strain gauge (here there were 3D printed plastic) (~5€)
  • An external battery to connect to the ESP32 (~10€)- https://amzn.to/2viJm4L


Building the wooden bin

First of all, you have to create your own wooden bin (1) following the dimensions you want. You may also design and print the different 3D parts needed or make them by yourself.

3D printed parts :

  1. Electrical box for the ESP32 and the HX711 module (2)
  2. ESP32 case (3)
  3. 4 bases for the bin (4)
  4. A connexion part for the strain gauge (5)


Installation of the strain gauge

Now that your bin is build you can install the strain gauge at the correct place (in the back of the bin where the hole is placed) and connect it with the connexion part. (6)


Weld the strain gauge to the hx711 module

You may now connect the strain gauge with the hx711 module following the wire diagram presented above and install the electrical box composed of the ESP32 and the hx711 module.


Modify an upload the program to the ESP32

Now that your building is done, you may begin the software part of the project. The codes for the ESP32 and the raspberry pi are explained in the dedicated part of this document. The codes used for this module are :” pet_ESP32.ino” and “PetFoodManager_programme.py” Link for the hx711 module configuration : http://www.mschoeffler.de/2017/12/04/arduino-tuto...


Test the module

You are now able to test the correct functioning of your module by putting on the ESP32 and running the python program on the raspberry pi. (7) You can test the connection between the raspberry pi and the ESP32 by using the following code in the terminal of the raspberry: [mosquitto_sub -t “Loadcell/DogManager”] Then if it works, you may run the python program on the raspberry pi by the command and see if your information on the web page change following the program: [python /var/www/html/etc/PetFoodManager_programme.py]


Use of the web server page

Finally, you may create and design your web page. If you go to the pet manager part of the website, you arrive on a first page (8) allowing you to choose which manager you have installed. You have the choice between a dog, cat, bird or rabbit manager. Be careful that you correctly install and code your manager with the ESP32 and the website following the instructions given in the codes. Then you can go on the pet food manager page (9) where you can see how much food is left in your connected bin. You can also convert this amount in days but you’ll have to adapt your calculation in the web server page for that.

Step 7: Module Electric Shutters

The purpose of the "Electric Shutters” module is to allow the user to maintain control over the installation of electrical shutters. In addition to traditional use, everyone will now be able to decide to control their shutters remotely. Other very interesting features have been added. It is possible to program the raising and lowering of the shutters according to a schedule that can be modified on the website, but especially according to the external brightness. It is interesting to control electrical shutters according to the light entering a room in order to limit the temperature increase. All these features will now be disconcertingly easy.

Refer to the wiring diagram for the wiring of the module.


Materials requirements


Explication

Open the Arduino sketch MQTT_Shutters.ino with the Arduino IDE. Add your Wifi information inside the Arduino Sketch. You can modify the default setpoint value (value used after a reboot of the ESP32). Upload the sketch inside the ESP32 board using the arduino IDE. Do not connect any external alimentation while you are connected to your computer.

Create your circuit on a breadboard ant test it. If tests are OK, you can solder your components.

On your Pi, open the console and type the command : python /var/www/html/etc/Shutters_programme.py If it works, you will see printed on the screen the brightness detected by the ESP32. Now you can use the website to send the parameters.

Web page

On the homepage, click on the shutters icon. First, you must choose between local and remote mode. If you choose this mode, you will have to choose between manual or automatic mode. The manual mode logically allows you to choose a remote controlled rise or fall of your electric shutters. Logically, you cannot select the up and down at the same time. If you set the automatic mode, the shutters will be controlled either with brightness or with a schedule. This schedule can, of course, be modified in real time.

Step 8: Module Outside Station

The purpose of the outside station is designed to measure the humidity of the air, the temperature and the level of your water tank. Each variable is sent to the website.


Materials requirements


Explication

First of all you need to connect the ESP32 to your computer and upload the program (file names “outside_station_ESP32.ino”)

After you uploaded the program, disconnect your ESP32 from your computer.

Weld the different components by following the schema. Then, connect your ESP32 to your computer again. You can test if you receive the process values by the serial monitor in the Arduino IDE (Tools > Serial monitor). If it’s good, you can go on the next step.

Now, you need to protect your system from the rain by placing it in a box. If you have a 3D printer, you can design a box and print it. Personally, I have already had a box.

Web page

With the MQTT server and the website installed on the raspberry, you can check if you receive the information of the module (temperature, humidity and the water tank level). If everything is OK, you finished this part.

You just need to go on the website and set the parameters of your water tank (form, size and the distance between the bottom of the tank and the sensor).

Step 9: Module Light

This module allows you to control as many lights as you want. There are two types of control : ON/OFF with a relay or a PWM to dim the brightness between 0 and 100%.


Materials requirements


Explication

First, you have to upload the program (Light_ESP32.ino) corresponding to this module to the ESP32. You can connect the external 5V battery to it after you disconnected the module from your computer.

After this first step, you can choose between a clean installation or something made faster. In fact, you can decide to build your installation thanks to a breadboard or if you have the time, you can put the module and the wires in an electrical box. Whatever your choice, look at the electronic diagrams of the assembly.

How to use the AC Dimer module => https://www.instructables.com/id/Arduino-controll...

You have to download this library and use the example “SerialMonitorDimESP32 => https://github.com/RobotDynOfficial/Lib-RBD-Dimme...


Web page

On the Light Manager web page, you can choose to switch ON and OFF the registered light and change the brightness of the dimmable light. To set this page, click on the setting image to access to the table. You can add, modify and remove each line in the table in order to manage all your light. You can also choose the number of ESP32. Each one can manage four relays output and four PWM outputs.

Step 10: Module Camera

This module allows you to access all your IP cameras in the same place. You can add as many cameras as you want thanks to their IP address. You can also select the width, height and even give him a name.

Materials requirement

Explication

Buy a USB camera or recycle one on an old laptop.


Install Motion for the camera server : https://www.instructables.com/id/How-to-Make-Rasp...

At the end of this installation, you should be able to access your video stream into your browser. Keep the stream link because you will need it for the web page.

To use esp32-cam as an ip-camera, follow this tutorial

To upload the code without a FTDI board, using an arduino, use this tutorial :

Take care of the position of the jumper of the esp32-cam board. This card can use an internal or external antenna. Place the jumper on the right position according to the picture linked above.


Web page
On the camera web page, you can watch all your camera streaming. To add, modify or remove any camera in the setting section. There is a table and each line matches a camera. You can set your camera name, weight, height and camera URL.

Step 11: Download Code Files + Useful Tips

To realize yourself this project, you need to download all the files available in this instructable page. You can also access to these files with this Mega link:

Mega file : https://mega.nz/#F!m8gwDADB!w0uWdQlT7ixLPJfP6khps...

In the folder “Arduino_Programming”, you can find all codes for ESP32. For each of them, you have to change some settings so that they can work.

For each code, it will be necessary to change the name of your wireless network and the password. It is also needed to modify the IP address of the MQTT server. This is obviously the IP address of your raspberry pi which hosts the website.

For the light module code, there are more settings because it is possible to bind several ESP32 at the same time (one for each light for example). You must change the number of each ESP32 and the names of the topic MQTT according to your MQTT server settings on the raspberry. For example, the light module for living room is the number 1, the one in the kitchen is number 2, number 3 for the office, and so on.

In the folder “Python_Programming”, you can find all codes that must work on the raspberry. They you to bind all ESP32 to the web server. As for the ESP32 codes, it is necessary to change some settings by choosing the IP address of the server (raspberry) and the names of MQTT topics. Once edited, each codes as to be placed in the same folder as the website (/var/www/html)

In the folder “web_Programming”, you can find all file for the website. Look at the STEP 2 to understand how to install it.

Useful tips

Here are some additional details if you are creating your own program

  • If you create your own program, sometimes you can have the following message : “A fatal error occurred: Timed out waiting for packet content” (look at the picture above). This message occurs when you are using a pin that is used for another purpose. For example, the D2 pin of ESP32 is used for the blue led of the board. Avoid the use of RX & TX pins. How to use MQQT

Share

    Recommendations

    • Backyard Contest

      Backyard Contest
    • Frozen Treats Challenge

      Frozen Treats Challenge
    • Beauty Tips Contest

      Beauty Tips Contest

    4 Discussions

    1
    None
    TeamFiveHelha

    27 days ago

    Really interesting project ! I like the idea of different modules that can be added or not depending on what we want.

    1 reply
    0
    None
    TuturpadTeamFiveHelha

    Reply 27 days ago

    Yeah thanks you for your comment. Il known it's not easy to build our own smart Home. That's why we tried to make it modular and as simple as possible to install for everyone.

    1
    None
    audreyobscura

    27 days ago

    These are clever IoT tips for a smart home! Thanks for sharing!

    1 reply
    0
    None
    Tuturpadaudreyobscura

    Reply 27 days ago

    Thanks for your comment, I hope it will help people for their own smart home project :D