Smart home

From Biemme Italia Wiki
Jump to: navigation, search



In the last years, companies and experts proposed many smart home and home automation projects. Even though they seems to be perfect, some lack on standardized protocols, some other are too much expensive and are currently accessible only to an elite group of people.

We think that, as of time of writing, 2013, the technology and the innovation behind home automation is mature in order to be broadly used every day.

We think that a great smart home project has to use well established and open standards for communication between devices. In particular, we decided to use the modbus protocol on rs485 for light weight data transfer and Ethernet for the heavy data stream communications like video and audio. The second key point in our vision of home automation project is to use Android on one hand and Arduino on the other.

Core parts

We use Android as the platform that provide User Interface (UI) experience whereas Arduino for the connection to the hardware parts and for the low level logic. The connection is made by using a rs485 bus. The protocol is the modbus. This is an industrial protocol that is mature, reliable and many devices on the market support it. Since Arduino itself is not sufficient for controlling all types of motors, we need an Arduino expansion that has relay etc

Summarizing, the device that runs Android (in our specific case a Single Board PC with frame) is the master and all the Arduino devices (or Arduino + bMini Shield expansion) connected to the bus are the slaves. The logic of the system is distributed across the Arduino nodes. This schema is particular fault tolerant because the failure of one or more nodes does not stop the entire system.


Arduino is a low cost programmable MCU, widely used for prototyping. However, the heart of the board, i.e. the AtMega chip, is normally used in other contexts like industrial applications.

The range of applications an Arduino board can manage are infinites, testified for instance by the huge amount of blog posts that

However, when we want to deal with motors and in general with high current devices, we need a specific expansion. We identified as [[bMini shield] as a necessary element in our project. It allows to expand the Arduino characterizing simplicity when managing high current devices


Even though this article is far from being a tutorial on how to create an Android applications, we would like to list which blocks a typical home automation project with Android must have:

  1. UI, usually identified by some xml layout file(s)
  2. An android native modbus library
  3. One or more Activities (i.e., java classes that extend Android Activity)

This structure will be maintained throughout all our smart home projects. The simplicity of our approach is that simple actions like activating bulbs, turn on/off switches, etc are managed by a set of calls to the native modbus library to a specific Arduino node.

The source code of the project is available in our github repository.

User Interface


How to

In this section we want to describe what are the key parts on the Android source code that deals with turning on/off bulbs, switches, reading temperatures, modifying brightness levels.

Bulbs states

Bulbs in a smart home automation project are managed as digital inputs. When the state of a bulb is on the corresponding digital input will be HIGH, LOW otherwise. In Arduino, we get the status of digital inputs by calling the digitalRead function. Since the master node should be aware of the bulbs' states, every Arduino slaves must store their value to modbus registers (the value that are stored are the constants 1/0), namely:

holdingRegs[0] = digitalRead(1);
holdingRegs[1] = digitalRead(2);
holdingRegs[2] = digitalRead(3);
holdingRegs[4] = digitalRead(4);

In this example, the digital values of the pins 1 to 4 are stored in the first four modbus registers. In this way the master (Android), by calling the ReadHoldingRegister function can request for those registers that memorize the bulbs' state.


Switches in home automation projects are reserved for doing many things, most notably turning on/off bulbs or opening/closing shutters, etc. In Arduino are considered as digital outputs. The process of modifying the state of digital outputs in remote slaves starts by calling the WriteHoldingRegisters (from Android). This function overwrites the value of one (or more) register(s) in a connected device. In particular, the registers that must be modified are those in which the digital outputs are stored. Once the writing request is executed by the slave device, the digital outputs must be changed reflecting the new states of the modbus registers:


where the pinDigOut is the pin of the digital output and holdingRegs[5] is the register that contains one digital output state.

Temperature Sensors

Temperature sensors are extremely important in every home automation projects. Its impostance is twofold: first it represent a feedback to the user that is able to know the temperature of the rooms. Secondly, it is mandatory in order to correctly control boiler and heaters. TMP36 are one of the cheapest temperature sensors on the market, suitable for systems where the extreme accuracy is not necessary.

As one might guess, the master in order to show the room's temperature, has to read from the modbus register in which temperatures are stored. In Arduino, it is necessary to read the analog value of the sensor using analogRead function.

holdingRegs[0] = AnalogRead(1);

Since the value read from arduino analog pins are integer values that ranges from 0 to 1024 (representing 0 to 5v range), in order to calculates Celsius or Fahrenheit degrees, we have to convert it as described on Adafruit TMP36 learning page.

Brightness variation

LED lamps are becoming widely used in every home, offices and industries. The nice feature of these bulbs is that the brightness can be modified according to the user's need. This is accomplished by using the PWM pins in the Arduino board. A led lamp can be modified by calling the analogWrite function on a pin declared as digital output in the setup section. For instance:

analogWrite(ledPin, holdingRegs[6]);

The first parameter is the digital pin whereas the second must be a value that ranges between 0 and 255. In this particular example, this latter value is retrieved from a modbus register. In this way, every time this register overwritten with a new value, the brightness will be consequently altered.

Personal tools