---
title: "Arduino Home Automation"
url: "https://maker.wiznet.io/Alan/projects/arduino-home-automation/"
markdown_url: "https://maker.wiznet.io/Alan/projects/arduino-home-automation/md"
type: "UCC: User Created Content"
author: "Ihor Melnyk"
author_url: "https://ihormelnyk.com/arduino_home_automation"
editor: "WIZnet"
editor_url: "https://maker.wiznet.io/"
original_author: "Ihor Melnyk"
original_url: "https://ihormelnyk.com/arduino_home_automation"
published: "2023-06-05"
language: "en"
likes: 0
views: 256
comments: 0
source: "WIZnet Makers (https://maker.wiznet.io/)"
---

# Arduino Home Automation

> Arduino Home Automation

Original author: Ihor Melnyk (source: https://ihormelnyk.com/arduino_home_automation)

## Article

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.

### Hardware:

- Arduino Mega 2560 R3 Arduino Compatible **7$**

- Ethernet Shield W5100 Network Expansion Board For Arduino UNO R3 Mega 2560 **5$**

- [IComSat GSM / GPRS SIM900 Module Expansion Board Shield With Antenna For Arduino Mega](https://www.itead.cc/icomsat.html) **42$**

- 12V 16 Channel Relay Module Interface Board For Arduino **12$**

- [GAINTA D9MG Plastic enclosure on DIN-rail](http://www.gainta.com/en/d9mg.html) **6$**

- [GAINTA D4MG Plastic enclosure on DIN-rail](http://www.gainta.com/en/d4mg.html) **4$**

- [GAINTA D4MG-PCB-A PCB for D4MG](http://www.gainta.com/en/d4mg-pcb-a.html) **2$**

- [NINIGI TBW-5-9P/GN Pluggable terminal block x 6](http://www.tme.eu/gb/details/tbw-5-9p_gn/terminal-blocks-pcb-mount/ninigi/) **5$**

- [NINIGI TBG-5-KB-9P/GN Pluggable terminal block x 6](http://www.tme.eu/en/details/tbg-5-kb-9p_gn/terminal-blocks-pcb-mount/ninigi/) **2.5$**

- [2.54mm Arduino MEGA Stackable Copper-Plating Header Kit](https://www.itead.cc/arduino-mega-stackable-header-kit.html) **1.5$**

As a light switchers I used Schneider Electric light switches from [Unica](http://www.schneider-electric.com/en/product-range/1268-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](http://www.schneider-electric.com/en/product-range-selector/1268-unica/?p_url=http%3A%2F%2Fwww.ops-ecat.schneider-electric.com%2Fecatalogue%2Fbrowse.do%3Fel_typ%3Dproduct%26cat_id%3DBU_ISC_1268_L3%26prd_id%3DMGU3_106_18%26scp_id%3DZ000)

[MGU3.206.18 Full size pushbutton - 1-way - 10 A 250 VAC - 2 m - white](http://www.schneider-electric.com/en/product-range-selector/1268-unica/?p_url=http%3A%2F%2Fwww.ops-ecat.schneider-electric.com%2Fecatalogue%2Fbrowse.do%3Fel_typ%3Dproduct%26cat_id%3DBU_ISC_1268_L3%26prd_id%3DMGU3_206_18%26scp_id%3DZ000)

### Software:

- [Arduino Software (IDE)](https://www.arduino.cc/en/Main/Software)

- [Sketch](https://github.com/ihormelnyk/arduino_home_automation)

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: &lt;component_name>&lt;command>&lt;args>.

### Schematic:

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

### PCB:

![Arduino Home Automation PCB1](https://ihormelnyk.com/Content/Pages/arduino_home_automation/arduino_home_automation_pcb1.png)
[PCB1 Sprint Layout](https://ihormelnyk.com/Content/Pages/arduino_home_automation/pcb/D9MG_PCB_Arduino_megaNb.lay)

![Arduino Home Automation PCB2](https://ihormelnyk.com/Content/Pages/arduino_home_automation/arduino_home_automation_pcb2.png)
[PCB2 Sprint Layout](https://ihormelnyk.com/Content/Pages/arduino_home_automation/pcb/D9MG_PCB_Arduino_mega?b.lay)

### Implementation:

![PCB1](https://ihormelnyk.com/Content/Pages/arduino_home_automation/arduino_home_automation_pcb1_i.jpg)

![PCB2](https://ihormelnyk.com/Content/Pages/arduino_home_automation/arduino_home_automation_pcb2_i.jpg)
![Arduino Mega 2560 and Ethernet Shield W5100](https://ihormelnyk.com/Content/Pages/arduino_home_automation/arduino_mega_2560_W5100.jpg)
![IComSat GSM / GPRS SIM900 Module](https://ihormelnyk.com/Content/Pages/arduino_home_automation/IComSat_GSM_GPRS_SIM900_Module.jpg)
![Arduino Mega 2560 and Ethernet Shield W5100](https://ihormelnyk.com/Content/Pages/arduino_home_automation/arduino_home_automation_i.jpg)

### Code:

[Source code on Git Hub](https://github.com/ihormelnyk/arduino_home_automation/)

---

Source: https://maker.wiznet.io/Alan/projects/arduino-home-automation/
