I've been busy with a project to water all my plants in the greenhouse.
The system is stand alone with a water tank instead of a connection on the water mains. So first the program has to check if the water level is not low, this to protect the waterpump.
If the water level is ok, the irrigation sequence can start with a delay for the pump to build up pressure. Then 8 valves are sequentialy opened and closed after another. The delays can be changed to determain the amount of water every valve is providing.
And I also want to monitor the temperature and humidity.
Evereything is working now, except the temperature and humidity, i can monitor them by serial print, but it is not visible in Domoticz. Please help me with this last detail.
Code: Select all
/* Z-kas
* Z-wave controlled irrigation system for greenhouse.
* Input: watertank level
* temperature (DHT22)
* humidity (DHT22)
* Outputs: waterpump switch (z-wave)
* 8 valves for 8 water circuits
* 8 valves for different irrigation
*
* When irrigation is started by user or timer in Domoticz:
* Measure waterlevel
* When waterlevel is not low start pump
* After ... seconds start valve sequence
*/
#include "ZUNO_DHT.h"
// pin number, where relay valves are connected
#define DHTPIN 9
#define IRRIGATION 11 // irrigation system active LED
#define VALVE_1 12 // valve circuit 1
#define VALVE_2 13 // valve circuit 2
#define VALVE_3 14 // valve circuit 3
#define VALVE_4 15 // valve circuit 4
#define VALVE_5 16 // valve circuit 5
#define VALVE_6 17 // valve circuit 6
#define VALVE_7 18 // valve circuit 7
#define VALVE_8 19 // valve circuit 8
DHT dht(DHTPIN, DHT22);
int humidity; // here we will store the humidity
int temperature; // here we will store the temperature
byte pin10SensorBinaryState; // waterlvl sensor
int WtrLVL; // integer to store low water level warning
byte lastSetValue; // variable to store current switch state
int IrrigationOn; // integer to store the switch value
int T_PumpDelay; // integer to store pump delay before start irrigation
int T_Valve1; // integer to store the opening time of valve 1
int T_Valve2; // integer to store the opening time of valve 2
int T_Valve3; // integer to store the opening time of valve 3
int T_Valve4; // integer to store the opening time of valve 4
int T_Valve5; // integer to store the opening time of valve 5
int T_Valve6; // integer to store the opening time of valve 6
int T_Valve7; // integer to store the opening time of valve 7
int T_Valve8; // integer to store the opening time of valve 8
// macro sets up the Z-Uno channels
ZUNO_SETUP_CHANNELS(
ZUNO_SENSOR_BINARY(ZUNO_SENSOR_BINARY_TYPE_GENERAL_PURPOSE, pin10SensorBinaryGetter),
ZUNO_SWITCH_BINARY(getter, setter),
ZUNO_SENSOR_MULTILEVEL_TEMPERATURE(getterTemperature),
ZUNO_SENSOR_MULTILEVEL_HUMIDITY(getterHumidity)
);
void setup() {
pinMode(10, INPUT);
pin10SensorBinaryState = !digitalRead(10);
pinMode(IRRIGATION, OUTPUT); // Irrigation active
pinMode(VALVE_1, OUTPUT); // set up relay pin as output
pinMode(VALVE_2, OUTPUT); // set up relay pin as output
pinMode(VALVE_3, OUTPUT); // set up relay pin as output
pinMode(VALVE_4, OUTPUT); // set up relay pin as output
pinMode(VALVE_5, OUTPUT); // set up relay pin as output
pinMode(VALVE_6, OUTPUT); // set up relay pin as output
pinMode(VALVE_7, OUTPUT); // set up relay pin as output
pinMode(VALVE_8, OUTPUT); // set up relay pin as output
dht.begin();
Serial.begin();
Serial.println("start");
// defining valve opening times (delays)
T_PumpDelay = 2000;
T_Valve1 = 2000;
T_Valve2 = 1000;
T_Valve3 = 2000;
T_Valve4 = 1000;
T_Valve5 = 1000;
T_Valve6 = 1000;
T_Valve7 = 1000;
T_Valve8 = 1000;
}
void loop() { // loop used for reading waterlevel
byte _pin10SensorBinaryState = digitalRead(10);
if (pin10SensorBinaryState != _pin10SensorBinaryState) {
pin10SensorBinaryState = _pin10SensorBinaryState;
WtrLVL = pin10SensorBinaryState;
zunoSendReport(1);
}
if (WtrLVL == HIGH) {
Serial.println("Waterlevel HIGH");
}else { // if equals zero
Serial.println("Waterlevel LOW");
}
// loop used for delayed port sequence
if (IrrigationOn == 1 && WtrLVL == HIGH) { // if irrigation activated & waterlevel is not low
Serial.println("Normal water level");
digitalWrite(IRRIGATION, HIGH); //turn irrigation system on
Serial.println("-= Start irrigation sequence =-");
Serial.print("Pump delay = ");
Serial.print(T_PumpDelay);
Serial.println(" ms");
delay (T_PumpDelay); //delay to allow pump to pressurise
digitalWrite(VALVE_1, HIGH); //turn relay valve on
Serial.print("Open irrigation valve 1 for ");
Serial.print(T_Valve1);
Serial.println(" ms");
delay (T_Valve1);
digitalWrite(VALVE_1, LOW);
Serial.println("Close irrigation valve 1");
digitalWrite(VALVE_2, HIGH); //turn relay valve on
Serial.print("Open irrigation valve 2 for ");
Serial.print(T_Valve2);
Serial.println(" ms");
delay (T_Valve2);
digitalWrite(VALVE_2, LOW);
Serial.println("Close irrigation valve 2");
digitalWrite(VALVE_3, HIGH); //turn relay valve on
Serial.print("Open irrigation valve 3 for ");
Serial.print(T_Valve3);
Serial.println(" ms");
delay (T_Valve3);
digitalWrite(VALVE_3, LOW);
Serial.println("Close irrigation valve 3");
digitalWrite(VALVE_4, HIGH); //turn relay valve on
Serial.print("Open irrigation valve 4 for ");
Serial.print(T_Valve4);
Serial.println(" ms");
delay (T_Valve4);
digitalWrite(VALVE_4, LOW);
Serial.println("Close irrigation valve 4");
digitalWrite(VALVE_5, HIGH); //turn relay valve on
Serial.print("Open irrigation valve 5 for ");
Serial.print(T_Valve5);
Serial.println(" ms");
delay (T_Valve5);
digitalWrite(VALVE_5, LOW);
Serial.println("Close irrigation valve 5");
digitalWrite(VALVE_6, HIGH); //turn relay valve on
Serial.print("Open irrigation valve 6 for");
Serial.print(T_Valve6);
Serial.println(" ms");
delay (T_Valve6);
digitalWrite(VALVE_6, LOW);
Serial.println("Close irrigation valve 6");
digitalWrite(VALVE_7, HIGH); //turn relay valve on
Serial.print("Open irrigation valve 7 for ");
Serial.print(T_Valve7);
Serial.println(" ms");
delay (T_Valve7);
digitalWrite(VALVE_7, LOW);
Serial.println("Close irrigation valve 7");
digitalWrite(VALVE_8, HIGH); //turn relay valve on
Serial.print("Open irrigation valve 8 for ");
Serial.print(T_Valve8);
Serial.println(" ms");
delay (T_Valve8);
digitalWrite(VALVE_8, LOW);
Serial.println("Close irrigation valve 8");
IrrigationOn = 0;
Serial.println("-= End irrigation sequence =-");
digitalWrite(IRRIGATION, LOW); //turn irrigation system off
} else if (IrrigationOn == 1 && WtrLVL == 0){ //if irrigation activated & waterlevel is low
Serial.println("Low water level!");
Serial.println("-= Irrigation sequence not started =-");
Serial.println("Close all irrigation valves");
digitalWrite(VALVE_1, LOW); //switch off all relay valves and irrigation system
digitalWrite(VALVE_2, LOW);
digitalWrite(VALVE_3, LOW);
digitalWrite(VALVE_4, LOW);
digitalWrite(VALVE_5, LOW);
digitalWrite(VALVE_6, LOW);
digitalWrite(VALVE_7, LOW);
digitalWrite(VALVE_8, LOW);
digitalWrite(IRRIGATION, LOW);
IrrigationOn = 0;
Serial.println("-= End irrigation sequence =-");
}
// obtaining readings from the sensor DHT
humidity = dht.readHumidity();
temperature = dht.readTemperature();
Serial.print("Humidity = ");
Serial.print(humidity);
Serial.print(" % ");
Serial.print("Temperature = ");
Serial.print(temperature);
Serial.println(" *C");
// send data to channels
zunoSendReport(1);
zunoSendReport(2);
// send every 30 second
delay(1000);
}
// function, which returns the previously saved relay value
// this function runs only once the controller asks
byte pin10SensorBinaryGetter() {
return pin10SensorBinaryState;
}
byte getter() {
return lastSetValue;
}
byte getterTemperature() {
return temperature;
}
byte getterHumidity() {
return humidity;
}
// function, which sets new relay state
// this function runs only once the controller sends new value
void setter(byte newValue) {
// newValue is a variable, holding a "value"
// which came from the controller or other Z-Wave device
if (newValue > 0) { // if greater then zero
IrrigationOn = 1;
} else { // if equals zero
IrrigationOn = 0;
}
// save the new value in a variable
lastSetValue = newValue;
}