Home automation for only $21.13! Sounds too good to be true, and actually you will need something more: 433 MHz power switches (Dutch: klikaanklikuit modules) to use the wireless opportunities. But without, you still can use 8 relays with your cellphone or any device with internet.
A few months ago, a friend came to me for some help with his home-automation wish: control everything in his apartment with only one remote. So we started this project.
The list of needed parts:
|1 Arduino Mega clone||$ 7.10|
|1 ESP 8266 WIFI module||$ 1.24|
|1 set RX / TX 433 mhz.||$ 0.37|
|1 block with 8 relays||$ 3.88|
|1 power-unit||$ 4.41|
|1 OLED screen||$ 3.23|
|1 push button||$ 0.71|
|1 small piece of PCB||$ 0.18|
And, of course some scrap wood and other materials. I used plexiglass for my casing. I like to see the connected parts, but at the lower level it's no weak current: depending on your country, the relays will switch 110-230 volts. So the entire package I made will be stored in a wooden box once its operational.
What can it do?
After the unit is powered, it will connect to a WIFI network. The OLED screen looks pretty small, but can be read very easily. Once connected, it shows the IP address where you can find it's control center. It's a local address, so only available when you are connected to the same network. Of course it's possible to configure your access point to make it visible from outside your network, but the whole world gets the ability to switch off your coffee machine. So be warned...
Once your cellphone, tablet or laptop has loaded the website, it can control everything connected to the relays and the radio transmitter. The website uses AJAX for sending the commands, so there is no delay for reloading the website every time you turn a switch.
Choices and decisions
The Arduino Mega and the Wemos D1 mini
We started this project first with a Wemos D1 mini. It has some major advantaged above the Arduino Mega:
- It's very small
- It's very cheap (below $3.00)
- It has lots of memory to store vars.
- There is no need for an external WIFI-unit: it is embedded on the circuit board.
- Using WIFI is very easy, as this kind of board is a real IOT board.
We discovered also some disadvantages:
- It has only a few pins (9) for input/output, and some are still in use by the Serial line or the WIFI.
- Because we needed all pins, the Serial monitor could not be used for tracing purposes. Programming and debugging became a little slow due to the lack of this kind of monitoring.
Some problems can be solved by using an extension board. You offer one or two pins, to get four till eight in return. We decided to switch to an Arduino Mega clone because of the next advantages:
- More sets of RX / TX serial ports. That makes it easy to remain connected to your Arduino IDE (and serial monitor) while using another serial port for the WIFI simultaneously.
- Lots of input/output pins.
Beside the advantages, there are also some disadvantages. The main problem is the small amount of memory (8 kb for storing vars) and the combination with the ESP8266 WIFI unit. The connection between them needs to be read as text (char or strings), and you even have to store/collect messages to interpret them once they're completed. And last but not least: the website itself needs to be stored on the Arduino also. More text to store.
Text Code:AT+RST OK WIFI DISCONNECT ets Jan 8 2013,rst cause:2, boot mode:(3,7) load 0x40100000, len 1856, room 16 tail 0 chksum 0x63 load 0x3ffe8000, len 776, room 8 tail 0 chksum 0x02 load 0x3ffe8310, len 552, room 8 tail 0 chksum 0x79 csum 0x79 2nd boot version : 1.5 SPI Speed : 40MHz SPI Mode : DIO SPI Flash Size & Map: 8Mbit(512KB+512KB) jump to run user1 @ 1000 Ai-Thinker Technology Co. Ltd. ready
Above the response after a given AT+RST command (a reset)
The storage of text (Strings) is complicated on an Arduino. It's the only var with unknown memory usage when it's declared. Besides that, you clone (and double the usage of memory) very often when working with strings: pass it through a function, edit it, etc.
Once your memory is filled up, your Arduino will behave strange: resets without warning, program crashes, unexpected return-values from functions, and almost every time no signals from the serial ports anymore...
- Next >>