GROWMAT Home Automation
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
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
Create Django database superuser, run
python manage.py createsuperuser
and log in to system.
Part List
Control Unit
- Raspberry Pi 2 https://www.raspberrypi.org
- SD card
- 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
- WiFi USB dongle http://www.ebay.com/itm/111239881192 (optional)
- 7" LCD Touch Screen http://www.ebay.com/itm/191586231267?_trksid=p2057872.m2749.l2649&ssPageName=STRK%3AMEBIDX%3AIT (optional)
- power output sockets
- RJ45 wall socket
- power supply, output 12V/2A
- 12V to 5V/3A converter http://www.ebay.com/itm/281783236684?_trksid=p2057872.m2749.l2649&ssPageName=STRK%3AMEBIDX%3AIT
- Relay board http://www.ebay.com/itm/310574415181
- Mounting box
Sensors (general base)
- Arduino Nano
- 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
- RJ45 patch cabel
- RJ45 slitterhttp://www.ebay.com/itm/5Pcs-3-Sockets-RJ45-6-LAN-Ethernet-Splitter-Adapter-Internet-Connector-Cable-/400958412817?hash=item5d5afbd811
- Mounting box
Sensor - Motion
- General sensor base
- 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)
- General sensor base
- AM2302 or DHT22 http://www.ebay.com/itm/201442918588
- Photo transistor
Sensor - Temperature (liquid)
- General sensor base
- DS18B20 http://www.ebay.com/itm/181171267370
Sensor - Distance
- General sensor base
- HC-SR06 http://www.ebay.com/itm/400985326881
Sensor - PH
- General sensor base
- PH probe http://www.ebay.com/itm/271985715879
Sensor - CO2
Control Unit Software Installation
- Start from Raspbian Linux image (provided by display supplier)
- Run
sudo raspi-config
Expand file system and enable SSI, I2C - Connect via ssh, set up network and WiFi
- Run
sudo nano /etc/modules
and add lines
i2c-bcm2708
i2c-dev - Create directory tree for ram disk:
mkdir growmat
cd growmat
mkdir growmat
cd growmat
mkdir ramdisk - Create ram disk, run
sudo nano /etc/fstab
and add line
tmpfs /home/pi/growmat/growmat/ramdisk tmpfs nodev,nosuid,size=8M 0 0 - Mount ram disk, run
sudo mount -a - 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 - 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 - Make scripts executable
sudo chmod +x g
sudo chmod +x gstop
sudo chmod +x gshow
sudo chmod +x gm
sudo chmod +x gr - Set start Growmat automatically, run
sudo crontab -e
and add line
@reboot /home/pi/growmat/g - 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 - 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 - 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 - Create Django database superuser
cd ~/growmat/growmat/
python manage.py createsuperuser - 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.
- g - starts all following processes, but doesn't provide any output, not for debugging
Or
- 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
- gr - starts webserver on port 80, good for debugging
- ga - create archives
- gshow - shows running processes
- 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
- Use plastic mounting box
- Fix RJ45 wall socket on side of box
- Fix power sockets
- Fix instruments into box
- Connect power sockets to relays
- 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 - Communication bus and power supply are now inside RJ45 connector, for connection to sensor you need only standard RJ45 cable
- If you use display, make hole in box cover and fix display into cover
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.
Hardware
- Base is small electric installation box
- Cut RJ45 patch cable in half and, end without connector put to box via hole in side of box
- 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 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
- Index 1 = state of PIR sensor (movement detected = 1)
- Index 2 = off state counter
- Index 3 = on state counter
Hardware
Connect Arduino to PIR sensor
- Arduino 5V - PIR VCC
- Arduino GND - PIR GND
- Arduino D3 - PIR output
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
- Index 1 = Light measurement
- Index 2 = Temperature
- Index 3 = Humidity
- 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
- Arduino 5V - AM2302 VCC
- Arduino GND - AM2302 GND
- Arduino D9 - AM2302 output
Make easy light sensor from resistor and photo transistor and connect to Arduino
- Arduino 5V - resistor
- Arduino GND - photo transistor emittor
- Arduino A0 - photo transitor collector and resistor
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
- 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
- Arduino 5V - HC-SR04 VCC
- Arduino GND - HC-SR04 GND
- Arduino D4 - HC-SR04 trig
- Arduino D3 - HC-SR04 echo
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.
Module CO2
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
- Index 1 = PWM output
- Index 2 = ON/OFF output
Software
Use Arduino Code slaves\output_sl10\output_sl10.ino.