Step 2 of our project RemoteLight:
We want to build up our home automation with these requirement.
What kind of controller can we use?
We have 2 possible choices to have a low cost controller:
– Raspberry PI/Banana PI/Orange PI board: from 15$ to 50$
A full operative system, with all programming languages available, lots of tools to debug all problems, may be too much powerful and complex for our small scope, but with all its debug tools, it can be very useful to make experiments.
– ESP8266 Nodemcu board: 3$
Simple, able to do only few task, only Lua and C programming languages, small memory so only small code can run. But it is has anything we need.
Pay attention it is not so powerful, so for example the WIFI must have a good signal otherwise this micro board can suffer trying to connect to your wifi.
As we will see later, the work to do around these boards is quite the same, so you can use our suggestions for both boards. With a RasberryPI or similar board you can probably control more switches and lights with one board but, due to cabling constraint, it is not simple to manage all lights from a centralized location (this means having all cables starting from the same point and make them arriving to the finel position all around the house, that is usually not very simple) . This is one of the reason why at the end, as you will see, our choice was multiple Nodemcu boards spread around the house near the switches and lights it needs to control.
Let’s see how these boards work for our purpose.
All these boards are provided with a GPIO (General Purpose Input/Outoput) connection, made of multiple pins. Some of these pins can be read by a simple code inside the board, to ask if the pin is connected or not to the “ground” (specific pin marked as GRD). This way of using pin is called input mode.
So you can take a switch, even a big wall switch normally used with 125v or 220v, connect one wire to the pin, one to the the ground, and with a simple code you can understand if the switch is opened (circuit interrupted, no current passing through the switch) or closed (circuit closed, the current pass through the switch).
Great!!! we achieved the first functionality of our controller. This is the way we can read if a switch is off or on.
Then you can use another pin in output mode, so you can send out a signal and this signal can, for example, turn on a led as it can turn on a relay, make the high voltage electricity to reach your light.
And this is the second part of our controller. We can pilot a switch to turn on/off a real 125/220v lamp.
Here you can see a simple experiment, where a normal wall switch, in this case a Bticino switch, is connected to the GPIO of a OrangePI, then a led was connected to a different pin and with a very simple python script every second a check is done to the switch, if the status of the switch is changed, the led status is inverted.
Everything clear? Ready to implement this theory in your home automation?
Unluckily things are not so simple. The pin of the GPIO of your board generates a very low tension, 3.3v or 5v depending by the model of the board you choose. Perfect if the distance between your board and the switch is few centimeters (as in previous video), but in real life the cable between the controller and the switch can be 5-8 meters long, even longer, so the current gets lost in the cable and never return to the board, so for the board if the switch is open or closed is the same, the signal get lost so it will never return to the board as the switch was open. We need a higher voltage, at least 12v or 24v, to be sure the current from the pin returns to the board. For the same reason to move electrical power from production plants to towns, 125v or 220v are not enough, the voltage is transformed to 30.000v (small lines) or 1.000.000v and then back to 220v at the end of the journey.
But such high voltages (12v or 24v) can not arrive in contact with our board, they would burn your board designed to work with 5v maximum.
How to solve the problem?!!? The magic optoisolator