In this blog post, we will build an Internet Of Thing (IoT) device based on the super cheap ESP8266 chip. The device is used to automate home shutters at a predefined time of the day or according to the house temperature in order to limit the temperature increase caused by sunlight. The ESP8266 chip is a microcontroller with WiFi capabilities and a full TCP/IP stack. We can, therefore, have a complete web server and REST API running in it so as an MQTT client that can be used to send commands to the chip from anywhere and also to receive data from the chip. The project was split into phases:
The requirements for this device are:
The minimal pieces that we need to put together in order to meet these requirements are:
In order to minimize the size of the entire device, we have no other choice than smartly designing the Printed Circuit Board (PCB) of the device to combine all these elements on a minimal space. Note: our final design uses a double sided PCB which have the switching power supply located behind the ESP8266 wifi antena. This is far from idea has the switching power supply could cause interferences that negatively affect the wifi antena. We will therefore need to make an initial prototype to make sure that this location is acceptable. We have also added a small temperature sensor on the board to monitor the Triacs temperature in the testing phase of the board. Note that the proximity of the temperature sensor to the power supply makes it totally unusable to measure the house temperature (there is an obvious bias of 4-5°C).
See below the schema for this device:
See below the board design for this device:
We can now compute what would be the cost of the device based on the component list and price for small quantities:
Component | Unit Price ($) | Quantity | Total Price ($) |
---|---|---|---|
ESP8266_ESP12E | 2.40 | 1 | 2.40 |
Power-Supply 110V/220V to 3.3V 700mA AC-DC | 1.47 | 1 | 1.47 |
OptoCoupler MOC3081 | 0.88 | 2 | 1.76 |
Triac L4008D6 or T405-600B | 0.90 | 2 | 1.80 |
Resistance RC1206JR-07330RL | 0.01 | 4 | 0.04 |
Resistance OM16G5E-R58 | 0.06 | 2 | 0.12 |
Temperature Sensor: | 0.51 | 1 | 0.51 |
Connector ATB612-508-2P | 0.08 | 1 | 0.08 |
Connector ATB612-508-3P | 0.08 | 1 | 0.08 |
pin header 1x8 | 0.02 | 1 | 0.02 |
double sided PCB (from firstPCB) | 1.84 | 1 | 1.84 |
TOTAL | 10.12 |
So basically, we are at the level of 10$ per device. The cheapest commercial device I found on the web was around 50$, and they were not as complete as these. Note that there is still some soldering to be done to put all these together... so we are not completely comparing apple to apple. Note however that manual shutter switches already cost more than 10$.
Before ordering all the components and making a PCB order in china (which usualy take a month), let's make a prototyping board on a home-made PCB. The manual shutter switch (first figure) was removed and replaced by the prototype that was inserted into the wall (seecond figure). Note that I am not able to make double sided PCB at home which explains why they are some wires here and there on the prototype. The prototype stayied in place for an entire week which also allowed me to make progress on the software (see next chapter). As I haven't observed any issue regarding WiFi connectivity during the testing period I move forward with the production of 10 devices (last figure).
One of the major advantage of the ESP8266 chip is that it is compatible with the Arduino software stack that is widely adopted by the hacker community world wide. There are therefore already many librariries available to do practically anything. See the ESP8266 Arduino github for a complete documentation. So here the software part is mostly reduced to just combinning all the libraries together. I won't go in to the details of my code, but instead, I will list the functionnality that I have implemented in the software.
Finally, we need one more piece to orchestrate all the devices at once from a nice user interface. This last piece is a small server that can host the MQTT broker and server as a bridge between the user and the devices. For this, we have used an old raspberry pi on which we have installed the mosquitto MQTT broker and on which we have also deployed a small django website from which we can roll the shutters up and down individuall or all at once. In addition, the django server also run a cron scheduler which automatically roll the shutters up in the morning and down in the evening. More complex logic can also be implemented in there to take actions according to special conditions liek temperature, vacation, etc. This sever is also used as an insulation layer between the wide internet and the secured local network. See the figure bellow to see how this small user interface looks like:
We have conducted an entire IoT project from A to Z satisfying a specific list of constrains. We've designed the electronic shema for the device, built a prototype, made a small production of final devices, develop their software, setup a server to communicate with these devices using either REST API or MQTT and finally, we have built a simple but handy user interface to orchestrate all these devices.
Have you already faced similar type of issues ?
Feel free to contact us, we'd love talking to you…Don't forget to like and share if you found this helpful!