Introduction: GROWMAT Home Automation


is automation unit for homes, greenhouses, fields for growing fruits, vegetables or flowers. Can be used as standalone automation unit, remote control or supervision and security system and can save your time, because can works almost without supervising.

Using of industrial standards gives a possibility connect to system thousands instruments available on market.

Main Control Unit is based on Raspberry Pi with Linux OS.

User interface is web base application written in Python Django framework.

Communication with remote sensors and peripherals is using industrial MODBUS protocol and RS485 standard.


Every input measurement or output is called instrument. Instrument is defined by Address, means MODBUS address of Sensor (0 is reserved for Control Unit itself) and Index of measurement, meas index inside sensor (more in chapter Sensors).


By periods you can restrict rules in time. For example you can define another heating during day and night.


Rules makes GROWMAT active. By rules you can define actions depending on state of instruments. For example you can start heating when temperature is low, you can take photo, play sound and send a message when Sensor Motion detect movement, you can switch on lights on at 10 PM a switch off at 6 AM and much more.


As output you can start bash script. By script you can take picture from USB webcam, play sound on speaker, send Jabber or email message or whatever else you want. It's planned use scripts also as inputs, therefore you can use for example information from internet (e. g. weather forecast) in GROWMAT system similar like any other instrument.


Modules are based on Arduino Uno acts MODBUS slaves and measurement functions.
System is open and new sensors could be easily develop, connect and set up in GROWMAT control unit.

Step 1: User Interface


User interface is web application. You can control Unit from build in touchscreen, computer or mobile phone. Just connect with your browser to the Unit. Default page shows all instruments defined in system. Instruments has Value (measurement value) and Status. Status provides additional information about quality of Value. You can see yellow instruments, that means warning, e.g. humidity is high. Red instruments means alarm, e.g. temperature is too high. Limits for warnings and alarms you can easily set by rules. Gray instruments means some disturbance , e.g Sensor is not connected to the system or is broken, value is not valid.

Instrument detail

On instrument detail page you can force value to instrument. You can force any value to instrument by pressing SET button, OFF button force 0 (zero) and ON force 1 (one). User setting is prioritized over system itself, your value is forced till you press AUTO. It could be useful for output instruments, where you can switch output manually.

Step 2: System Set Up Interface

Create Django database superuser, run
python createsuperuser
and log in to system.

Step 3: Part List

Control Unit

  1. Raspberry Pi 2
  2. SD card
  3. RS485 USB converetr
  4. WiFi USB dongle (optional)
  5. 7" LCD Touch Screen (optional)
  6. power output sockets
  7. RJ45 wall socket
  8. power supply, output 12V/2A
  9. 12V to 5V/3A converter
  10. Relay board
  11. Mounting box

Sensors (general base)

  1. Arduino Nano
  2. TTl - RS485 converter
  3. RJ45 patch cabel
  4. RJ45 slitter
  5. Mounting box

Sensor - Motion

  1. General sensor base
  2. HC SR501 PIR sensor

Sensor - Temperature, humidity, light (air)

  1. General sensor base
  2. AM2302 or DHT22
  3. Photo transistor

Sensor - Temperature (liquid)

  1. General sensor base
  2. DS18B20

Sensor - Distance

  1. General sensor base
  2. HC-SR06

Sensor - PH

  1. General sensor base
  2. PH probe

Sensor - CO2

  1. General sensor base
  2. CO2 sensor MG-811

Step 4: Control Unit Software Installation

  1. Start from Raspbian Linux image (provided by display supplier)
  2. Run
    sudo raspi-config
    Expand file system and enable SSI, I2C
  3. Connect via ssh, set up network and WiFi
  4. Run
    sudo nano /etc/modules
    and add lines
  5. Create directory tree for ram disk:
    mkdir growmat
    cd growmat
    mkdir growmat
    cd growmat
    mkdir ramdisk
  6. Create ram disk, run
    sudo nano /etc/fstab
    and add line
    tmpfs /home/pi/growmat/growmat/ramdisk tmpfs nodev,nosuid,size=8M 0 0
  7. Mount ram disk, run
    sudo mount -a
  8. Install necessary software
    sudo apt-get install python-pip
    pip install utils
    sudo pip install Django
    sudo pip install minimalmodbus
    sudo apt-get install python-smbus
    sudo apt-get install i2c-tools
  9. Create download directory and download and install Growmat project
    cd ~
    mkdir downloads
    cd downloads
    git clone
    rsync -a control/ ~/growmat/
    cd ~/growmat

    mkdir archives
  10. Make scripts executable
    sudo chmod +x g
    sudo chmod +x gstop
    sudo chmod +x gshow
    sudo chmod +x gm
    sudo chmod +x gr
  11. Set start Growmat automatically, run
    sudo crontab -e
    and add line
    @reboot /home/pi/growmat/g
  12. For Jabber instant messaging install xmppy
    cd ~/downloads
    cd xmpppy-master
    sudo python install
  13. Customize dispaly, rotate if you need, run
    sudo nano /boot/config.txt
    add line for display rotate
    display_rotate=3 #270 degree
    If you rotate display you also need rotate touch device, run
    sudo apt-get install xinput -y
    sudo nano /etc/X11/xinit/xinitrc
    add lines to file
    DISPLAY=:0 xinput --set-prop 'RPI_TOUCH By ZH851' 'Evdev Axes Swap' 1
    DISPLAY=:0 xinput --set-prop 'RPI_TOUCH By ZH851' 'Evdev Axis Inversion' 1 1
  14. Make browser run automatically in kiosk fulscreen mode, run
    sudo nano /etc/xdg/lxsession/LXDE-pi/autostart
    add lines
    @xscreensaver -no-splash
    @xset s off
    @xset -dpms
    @xset s noblank
    @sed -i 's/"exited_cleanly": false/"exited_cleanly": true/' ~/.config/chromium/Default/Preferences
    @chromium --noerrdialogs --kiosk http://localhost/w --incognito
  15. Create Django database superuser
    cd ~/growmat/growmat/
    python createsuperuser
  16. fswebcam???

Step 5: Control Unit Software Description

Whole project is in GitHub repository, clone it by
git clone
or downlad zip file

Be sure you installed package described in previous chapter. Source code is in PYTHON.

Edit file growmat.ini and set port, where is your USB - RS485 converter connected. Typically /dev/ttyUSB0 for Raspi or COM1 for Windows.

Create Django database superuser, run
python createsuperuser

How to start on Linux

Start project by prepared scripts, needs sudo because GPIO and port 80.

  1. g - starts all following processes, but doesn't provide any output, not for debugging


  1. gm - starts growmat/w/management/commands/, which is core script responsible for MODBUS communication and rules execution, using standard output and is good for debogging
  2. gr - starts webserver on port 80, good for debugging
  3. ga - create archives
  4. gshow - shows running processes
  5. gstop - kill processes


You can use project also on Windows with some limitation, because on your PC are not GPIOs for outputs, but you can create Output module for outputs (see chapter Module Output). Scripts names are same like for Linux with .bat extension.

Step 6: Unit Control Hardware

  1. Use plastic mounting box
  2. Fix RJ45 wall socket on side of box
  3. Fix power sockets
  4. Fix instruments into box
  5. Connect power sockets to relays
  6. Connect wires from RJ45 socket
    RJ45 #1 - NC
    RJ45 #2 - NC
    RJ45 #3 - RS485 converter A+
    RJ45 #4
    - +12VDC
    RJ45 #5 - +12VDC
    RJ45 #6 - RS485 converter A-
    RJ45 #7 - GND
    RJ45 #8 - GND
  7. Communication bus and power supply are now inside RJ45 connector, for connection to sensor you need only standard RJ45 cable
  8. If you use display, make hole in box cover and fix display into cover

Step 7: Module General Base

All modules are based on Arduino Nano acts as MODBUS slave together with addition function. For RS485 electrical interface TTL - RS485 converter is used. Each Sensor has to have unique Slave ID (Modbus slave address), you can change it in Arduino code.

For connection of new sensor use RJ45 splitter, that gives you free slot for next sensor. If sensor is last in row, put to free RJ45 splitter slot Rj45 connector with 100 Ohm resistance between #2 #6 to termination bus.


  1. Base is small electric installation box
  2. Cut RJ45 patch cable in half and, end without connector put to box via hole in side of box
  3. Connect Arduino Uno together wit TTL - RS485 converter
    RJ45 #3 - RS485 converter A
    RJ45 #5 - Arduino VIN
    RJ45 #6 - RS485 converter B
    RJ45 #7 - Arduino GND
    Connect Arduino and TTL - RS485 converter
    Arduino 5V - RS485 VCC
    Arduino GND - RS485 GND
    Arduino TX - RS485 DI
    Arduino RX - RS485 RO
    Arduino D2 - RS485 _RE
    Arduino D2 - RS485 DE

All others Arduino inputs and outputs are free for digital and analog sensors.


Arduino Software ins necessary, download it from Next what you need is library, import it to Arduino Software. All Arduino cone you can find on GitHub repository in drirectory slaves.

Step 8: Module Motion

Motion sensor uses PIR sensor for motion detection. With Motion sensor you can for example trig lights on, make a photo, play a welcome melody for you guest. Source code for Arduino is in repository or

Slave ID is set to 4 in code, if you want more Sensor Motions, you have to change to any free number.

From Sensor Motion you can read following informations

  1. Index 1 = state of PIR sensor (movement detected = 1)
  2. Index 2 = off state counter
  3. Index 3 = on state counter


Connect Arduino to PIR sensor

  1. Arduino 5V - PIR VCC
  2. Arduino GND - PIR GND
  3. Arduino D3 - PIR output

Step 9: Module Temperature Humidity Light

This is basic sensor for your greenhouse. Sensor using AM2302 (DHT22, DHT11) for temperature and humidity measurement. Temperature and humidity are inputs for Control Unit to control heater or fan. With light sensor you can supervise lights in indoor gardening.

Slave ID is 2 with following informations

  1. Index 1 = Light measurement
  2. Index 2 = Temperature
  3. Index 3 = Humidity
  4. Index 4 = Head index


AM2302 has one wire communication interface, download and install library to Arduino software. For Arduino code use code from repository in directory slaves/dht/sm10_dht_sl2


Connect Arduino to AM2302

  1. Arduino 5V - AM2302 VCC
  2. Arduino GND - AM2302 GND
  3. Arduino D9 - AM2302 output

Make easy light sensor from resistor and photo transistor and connect to Arduino

  1. Arduino 5V - resistor
  2. Arduino GND - photo transistor emittor
  3. Arduino A0 - photo transitor collector and resistor

Step 10: Module Distance

Sensor Distance can measure distance to object in range from 2 cm to 200 cm. For measurement is used ultrasonic sensor HC-SR04. Sensor can be used foe example to monitoring water level in tank for watering plants.

Slave ID is 3 with following informations

  1. Index 1 = distance measurement


For Arduino code use code from repository in directory slaves/sr04/sm10_sr04_sl3


Connect Arduino to HC-SR04

  1. Arduino 5V - HC-SR04 VCC
  2. Arduino GND - HC-SR04 GND
  3. Arduino D4 - HC-SR04 trig
  4. Arduino D3 - HC-SR04 echo

Step 11: Module PH Probe

PH probe has analog output, reuse Arduino code from another Sensor, read analog value on Arduino pin and store to MODBUS register. Good example base be light sensor, just remove DHT relevant parts and don't forget change slave ID.

Step 12: Module CO2

Step 13: Module Output

If you run GROWMAT software on computer without GPIOs or you need remote output you can use Module Output. Output is defined as any other instrument, but in this case Control Unit is not reading information from Module, but writing to Module. Value is calculated in Control Unit by rules.

Slave ID is 10 with following informations

  1. Index 1 = PWM output
  2. Index 2 = ON/OFF output


Use Arduino Code slaves\output_sl10\output_sl10.ino.

Digital Life 101 Challenge

Participated in the
Digital Life 101 Challenge

Raspberry Pi Contest 2016

Participated in the
Raspberry Pi Contest 2016