GROWMAT Home Automation

by bcsedlon in Circuits > Raspberry Pi

9101 Views, 92 Favorites, 0 Comments

GROWMAT Home Automation

IMG_20160107_133811.jpg
IMG_20160107_133127.jpg
IMG_20160107_132853.jpg
index.png
detail.png
instruments.png
periods.png
rules.png
IMG_20160107_132938.jpg
CONTROL EXAMPLE 2.jpg
CONTROL INSIDE 1.jpg
TEMP HUMI LUX METER 1.jpg
MOTION SENSOR 1.jpg
PH METER 2.jpg
DISTANCE METER 2.jpg
CO2 METER 1.jpg

GROWMAT

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 https://en.wikipedia.org/wiki/Modbus protocol and RS485 https://en.wikipedia.org/wiki/RS-485 standard.

Instruments

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

Periods

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

Rules

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.

Scripts

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

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.

User Interface

index.png
detail.png

Overview

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.

System Set Up Interface

instruments.png
periods.png
rules.png

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

Part List

CONTROL INSIDE 1.jpg

Control Unit

  1. Raspberry Pi 2 https://www.raspberrypi.org
  2. SD card
  3. RS485 USB converetr http://www.ebay.com/itm/CH340-USB-to-RS485-485-Converter-Adapter-Module-For-Win7-Linux-XP-Vista-/201258967189?hash=item2edbf82095:g:SDAAAOSw2s1UrPYd
  4. WiFi USB dongle http://www.ebay.com/itm/111239881192 (optional)
  5. 7" LCD Touch Screen http://www.ebay.com/itm/191586231267?_trksid=p2057872.m2749.l2649&ssPageName=STRK%3AMEBIDX%3AIT (optional)
  6. power output sockets
  7. RJ45 wall socket
  8. power supply, output 12V/2A
  9. 12V to 5V/3A converter http://www.ebay.com/itm/281783236684?_trksid=p2057872.m2749.l2649&ssPageName=STRK%3AMEBIDX%3AIT
  10. Relay board http://www.ebay.com/itm/310574415181
  11. Mounting box

Sensors (general base)

  1. Arduino Nano
  2. TTl - RS485 converter http://www.ebay.com/itm/10pcs-RS-485-MAX485-Module-TTL-to-module-RS-485-for-Arduino-Raspberry-pi-/131308930256?hash=item1e929f44d0
  3. RJ45 patch cabel
  4. RJ45 slitterhttp://www.ebay.com/itm/5Pcs-3-Sockets-RJ45-6-LAN-Ethernet-Splitter-Adapter-Internet-Connector-Cable-/400958412817?hash=item5d5afbd811
  5. Mounting box

Sensor - Motion

  1. General sensor base
  2. HC SR501 PIR sensor http://www.ebay.com/itm/HC-SR501-Infrared-PIR-Motion-Sensor-Module-for-Arduino-Raspberry-pi-HCSR501-/151857503916?hash=item235b699eac:g:ETIAAOSw14xWKOes

Sensor - Temperature, humidity, light (air)

  1. General sensor base
  2. AM2302 or DHT22 http://www.ebay.com/itm/201442918588
  3. Photo transistor

Sensor - Temperature (liquid)

  1. General sensor base
  2. DS18B20 http://www.ebay.com/itm/181171267370

Sensor - Distance

  1. General sensor base
  2. HC-SR06 http://www.ebay.com/itm/400985326881

Sensor - PH

  1. General sensor base
  2. PH probe http://www.ebay.com/itm/271985715879

Sensor - CO2

  1. General sensor base
  2. CO2 sensor MG-811 http://www.ebay.com/itm/SainSmart-MG-811-MG811-CO2-Carbon-Dioxide-Sensor-For-Arduino-UNO-R3-Raspberry-Pi-/301191399526?hash=item4620680866:g:F0IAAOSwDk5UG96J

Control Unit Software Installation

IMG_20160107_132637.jpg
IMG_20160107_133127.jpg
IMG_20160107_132938.jpg
IMG_20160107_132853.jpg
  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
    i2c-bcm2708
    i2c-dev
  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
    sudo
    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 https://github.com/bcsedlon/growmat.git
    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
    wget https://github.com/normanr/xmpppy/archive/master....
    unzip master.zip
    cd xmpppy-master
    sudo python setup.py 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 manage.py createsuperuser
  16. fswebcam???

Control Unit Software Description

Whole project is in GitHub repository, clone it by
git clone https://github.com/bcsedlon/growmat.git
or downlad zip file
https://github.com/bcsedlon/growmat/archive/master.zip

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

Or

  1. gm - starts growmat/w/management/commands/modbus.py, 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

Windows

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.


Unit Control Hardware

CONTROL INSIDE 2.jpg
growmat_control.png
  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

Module General Base

CONTROL EXAMPLE 2.jpg
sensor_bb.png
splitter.jpg

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.

Hardware

  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.

Software

Arduino Software ins necessary, download it from https://www.arduino.cc Next what you need is https://github.com/angeloc/simplemodbusng/tree/master/SimpleModbusSlave library, import it to Arduino Software. All Arduino cone you can find on GitHub repository https://github.com/bcsedlon/growmat in drirectory slaves.

Module Motion

MOTION SENSOR 2.jpg

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 https://github.com/bcsedlon/growmat/blob/master/slaves/pir/sm10_pir_sl4/sm10_pir_sl4.ino

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

Hardware

Connect Arduino to PIR sensor

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

Module Temperature Humidity Light

TEMP HUMI LUX METER 1.jpg

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

Software

AM2302 has one wire communication interface, download and install https://github.com/adafruit/DHT-sensor-library library to Arduino software. For Arduino code use code from repository in directory slaves/dht/sm10_dht_sl2

Hardware

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

Module Distance

DISTANCE METER 2.jpg

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

Software

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

Hardware

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

Module PH Probe

PH METER 2.jpg

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.

Module CO2

CO2 METER 1.jpg

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

Software

Use Arduino Code slaves\output_sl10\output_sl10.ino.