Prototype of Light Control Device for Smart Home

by

·

, ,

Where did the idea come from?

I’ve long wanted to make something in the spirit of Smart Home and IoT (Internet of Things). To begin with, I decided to make a device for controlling light. There are a lot of light bulbs in the apartment, there are chandeliers with several separately switched lamps, there is a hallway where it would be good to turn on the light only when necessary, and so on. And, of course, making a separate device for each situation is ineffective. Therefore, the idea arose to make something universal and programmatically configurable for a specific place. Naturally, everything should be connected to Wi-Fi for centralized control.

I decided to use the sink in the kitchen as a test site. The sink is in a dark corner, as a temporary measure we put a lamp on a clothespin with a switch on the wire there. But working with an unprotected switch with wet hands next to a grounded sink is not a very good solution. And your hands are often busy.

Concept

For versatility, the device has two inputs and three outputs. Motion sensors or just switches can be connected to the inputs. A relay for load control is connected to two outputs. An LED is connected to the third output to indicate the current state. By default, it displays the Wi-Fi connection status, but this can be changed in the settings.
Additionally, a temperature and humidity sensor can be connected, but this is for the future.
The device program has a customizable control matrix – how signals at the inputs affect the outputs. Additionally, there are customizable delays at the inputs and outputs.
For network control, I chose the MQTT protocol. This is a very popular system in which there is a server that supports a database with different values. And clients, connecting to the server, can, firstly, update the values, and secondly, receive notifications about changes in the values ​​​​that interest them.
In this way, you can link any device to any other. There is an obvious scheme with sensors reporting on / off the light, and a central device with a screen where all this is displayed. But one can also imagine more interesting options, when, for example, the sequential activation of sensors in the corridor leads to the light in the room turning on, since a person is moving in that direction.

Hardware

The ESP8266 module was chosen as the “brain”. It has enough digital inputs and, of course, the main difference from Arduino is built-in Wi-Fi. The module is inexpensive, it is easy to program thanks to the SDK. It is inserted into a connector on a small homemade breadboard. The board also contains resistors to ensure the operation of the module and a 5V -> 3.3V converter.
Later, I had to add a supply voltage stabilizer from a capacitor and a diode. Otherwise, the module rebooted when the relay was triggered. Although the control signals to the relay are connected via optocouplers, and the coils are powered from 5V, i.e. to the ESP8266 power converter.
The motion sensor is the most common one, with two trimming resistors.

Movement Sensor

To control the load, I initially used a two-channel module with mechanical relays, but after a couple of months of operation, I replaced the relay with a solid-state module.

Solid state switch

Реле управляются напряжением в 5 Вольт, а модулю ESP8266 требуется 3.3 Вольта. Так что понадобился источник питания 220 -> 5 Вольт и дополнительный слаботочный модуль для понижения до 3.3.
В качестве источника света я взял уже готовый светодиодный модуль, работающий от 220 Вольт.

Software

For software development I used not an IDE for Arduino, but the PlatformIO environment based on the universal Atom editor. This solution is 100% compatible with Linux, and you can develop simultaneously on different platforms, synchronizing via a git repository.

To debug the program, I used the board from the SDK, and only then soldered my own circuit on a small breadboard with minimal wiring for the ESP8266 to work.

SDK board with connected sensor

Body

I decided to design the case myself using FreeCAD and print it on a 3D printer. At the same time, I modeled the location of all the modules inside so that nothing intersected (since this does not happen in real life 🙂 Of course, my box will not win a beauty contest, but for the first time it turned out pretty good.

Main body
Cover
Internal components allocation planning

And now we print:

Prototype is ready

The LED module was fixed to a radiator from an old motherboard. The module heats up quite a bit and will easily melt PLA plastic when in direct contact. The branded white wire was left over from an old kettle.

Connection with MQTT server

I installed the MQTT server on a constantly running RaspberryPi connected to our home network. I made a separate Wi-Fi network for Smart Home devices. The connection between clients and the server is protected by SSL. A command line client comes with the server. With it, you can download settings for different modules and receive messages from other clients. Each module needs to download its own settings.

In order for the firmware of the modules to be universal, I made a two-stage identification system for each module. Each module has a unique MAC address. And on the server, all settings are tied to the text name of the device, in this case, “kitchen-sink”. And there is one line binding the MAC address of the device’s radio module to the name. Thus, when replacing a module, you only need to change one line in the configuration on the server.

In the figure below, the parameter values ​​​​go from “/config”, they are set by the script when starting the server. And the values ​​​​transmitted by the modules are contained inside the “/status” tree. First comes the name of the parameter and, after a space, the value. The line “effect/11 1” means that there is only one 1 in the input/output connection matrix – when input #1 is triggered, output #1 must be turned on.

Messages from the device are marked in green.

Comments

Leave a Reply