Arduino Home Automation

Posted on Sunday, February 22, 2015 at 12:00 AM, 25825 views

Arduino home automation

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.

Base task: remote alarm and light management using smartphone or/and Internet:

  • 32 lamps
  • 6 motion sensors
  • 4 reed switches
  • 1 alarm siren

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.


As a light switchers I used Schneider Electric light switches from Unica series, because they have push-buttons for impulse relay control. Also Unica is modular system, so you can combine any kind of switchers and other modules together.
MGU3.106.18 Half size pushbutton - 1-way - 10 A 250 VAC - 1 m - white
MGU3.206.18 Full size pushbutton - 1-way - 10 A 250 VAC - 2 m - white


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>.


Schematic can be easily guessed from sketch (Controller1.h file).
  • GSM Shield: Serial1(18, 19), POWER - 10, RESET - 11
  • ALARM Relay - 12
  • I2C inter-controller communication - 20, 21
  • Motion sensors - 3,4,5,6
  • Light Relays - [22-52] even pins
  • Light Switches - [23-53] odd pins


Arduino Home Automation PCB1
PCB1 Sprint Layout
Arduino Home Automation PCB2
PCB2 Sprint Layout


Arduino Mega 2560 and Ethernet Shield W5100
IComSat GSM / GPRS SIM900 Module
Arduino Mega 2560 and Ethernet Shield W5100


Source code on Git Hub

Back to List