Posted on Sunday, February 22, 2015 at 12:00 AM, 12055 views
A few years ago my house was at the stage of laying electrical wiring, that was a good time to think about home automation and security system, which I really would like to have. The first reason, why did I need it, was that my house is located outside the city, therefore security system was a necessity. The second reason was that ready-made solutions always has some limitations and a small set of features. And the third reason was that electronics is my hobby and it was like a new challenge for me to design such system by myself.
All hardware I decided to place into electric switchboard in garage. Despite the huge number of wires, I would like to make easily replaceable blocks to have ability quickly replace broken shields. Solution was to use DIN-rail enclosures and pluggable terminal blocks, which you can found in hardware list below.
Arduino MEGA 2560 has 54 digital I/O pins, 16 analog inputs, 256 KB Flash Memory and 8 KB SRAM, which is quite enough to control all required staff directly without any device communications buses.
The main challenge was to make all this staff work simultaneously. Light switching should work without any delay when for example controller communicates with GSM or Ethernet shield. Most of open source GSM libraries communicates with GSM module via Serial port sending AT commands and waiting for responses. Some AT commands could run more than 2 seconds, which is inappropriate delay for real time system. Considering all these issues I decided to develop extensible and asynchronous mini framework. There are to queues: events and commands. Each sensor or device should be inherited from SHComponent class, which can produce events and execute commands. SHController manages these queues and encapsulates all logic for handling events and building command list. I used interrupt timer to poll all components. As interruption callback should be as short as possible, it checks component status changes and pushes events into events queue. Queues organized as ring buffers due a to small amount of SDRAM memory.
Text protocol was introduced to able to send any command via SMS, HTTP or I2C protocols. Command looks like: <component_name><command><args>.