About This Project
I have lawn water irrigation system, with
- 24V water valve 2 pcs. Gardena Gardena Water Controls 24 V Irrigation Valve
- Soil Moisture Sensor Gardena Gardena Water Controls Soil Moisture Sensor
- Irrigation Control System Gardena 4040 Gardena Water Controls Irrigation Control System 4040 modular
I want replace control unit 4040 with IoT Cayenne unit and add some measurements and statistics. Temp sensors will be at -5 cm and -10 cm in the soil.
What’s Connected
(Hardware, sensors, actuators, device model, WiFi, etc.)
NodeMCU, dual relay, 2 DS18D20
(Did you use the Triggers & Alerts feature?)
- Alert when soil temperature reaches set min or max temperature for fertilization and application of herbicides in spring and autumn. Alert at freezing temp to drain water from system.
(Did you use the Scheduling feature?)
Dashboard Screenshots
Current dashboard: - Cayenne
Photos of the Project
What else to consider
- When irrigation starts and possible network failure occurs (WiFi, internet), water can flow for hours. Must add max time interrupt in code.
- If capable, add OpenWeathermap api and code if forecast is more then 25 mm (1 inch) rain in next 24 hours disable irrigation that day. Ad hourly air temperature.
- Cumulative time for each valve per year (water consumption statistics)
- Cayenne of/off button is one way communication. At start Cayenne dashboard one switch is always on one is always off. Ad code to see actual status on dashboard.
Current code
#define CAYENNE_DEBUG
#define CAYENNE_PRINT Serial
#include "CayenneMQTTESP8266.h"
#include "ESP8266WiFi.h"
#include <OneWire.h>
#include <DallasTemperature.h>
char ssid[] = "************";
char wifiPassword[] = "*********";
#define VIRTUAL_PIN V1
#define VIRTUAL_PIN V3
const int tmpPin = 13; //temp
const int tmpPinB = 15; // drugu temp senzor bodoci
OneWire oneWire(tmpPin); //temp
DallasTemperature sensors(&oneWire); //temp
OneWire oneWireB(tmpPinB); //temp
DallasTemperature sensorsB(&oneWireB); //temp
char username[] = "********************************";
char password[] = "*****************************************";
char clientID[] = "*******************************************";
int cona1rele = 0; //prej 5
int cona2rele = 2; //prej 4
int gardenasenz = 16; // vhod Gardena senzorja bil 13
int cona1web = 5; // prej 0
int cona2web = 4; // prej 2
unsigned long lastMillis = 0;
void setup() {
Serial.begin(115200);
delay(2000); //added to give the onewire stuff time to initialize.
Cayenne.begin(username, password, clientID, ssid, wifiPassword);
sensors.begin();
pinMode(gardenasenz, INPUT); //
pinMode(cona1rele, OUTPUT); //rele 1 D1
pinMode(cona2rele, OUTPUT); //rele 2 D2
pinMode(cona1web, OUTPUT); //LED 1
pinMode(cona2web, OUTPUT); //LED 2
digitalWrite(cona1rele, LOW);
digitalWrite(cona2rele, LOW);
digitalWrite(cona1web, LOW);
digitalWrite(cona2web, LOW);
}
void loop() {
Cayenne.loop();
sensors.requestTemperatures();
delay(100);
if(digitalRead(cona1web) == HIGH && digitalRead(gardenasenz) == HIGH){
digitalWrite(cona1rele, LOW);
}else{
digitalWrite(cona1rele, HIGH);
}
if(digitalRead(cona2web) == HIGH && digitalRead(gardenasenz) == HIGH){
digitalWrite(cona2rele, LOW);
}else{
digitalWrite(cona2rele, HIGH);
}
Serial.print("cona1web: ");
Serial.println(digitalRead(cona1web));
//Serial.println("cona2web: " + digitalRead(cona2web));
Serial.print("cona1rele: ");
Serial.println(digitalRead(cona1rele));
//Serial.println("cona2rele: " + digitalRead(cona2rele));
}
CAYENNE_OUT_DEFAULT()
{
Cayenne.celsiusWrite(1, sensors.getTempCByIndex(0));
delay(100);
if (digitalRead(gardenasenz) == HIGH) // prenos stanja Gardena vlagomera 1/0
{
Cayenne.virtualWrite(2, HIGH);
}
else if (digitalRead(gardenasenz) == LOW)
{
Cayenne.virtualWrite(2, LOW);
}
}
CAYENNE_OUT(V3)
{
sensorsB.requestTemperatures(); // Send the command to get temperatures.
delay(100);
Cayenne.celsiusWrite(VIRTUAL_PIN, sensorsB.getTempCByIndex(0)); // This command writes the temperature in Celsius to the Virtual Pin.
}
CAYENNE_IN_DEFAULT()
{
CAYENNE_LOG("Channel %u, value %s", request.channel, getValue.asString());
}
CAYENNE_IN(3)
{
CAYENNE_LOG("Got a value: %s", getValue.asStr());
int i = getValue.asInt();
if (i == 0)
{
digitalWrite(cona1web, LOW);
}
else
{
digitalWrite(cona1web, HIGH);
}
}
CAYENNE_IN(4)
{
CAYENNE_LOG("Got a value: %s", getValue.asStr());
int i = getValue.asInt();
if (i == 0)
{
digitalWrite(cona2web, LOW);
}
else
{
digitalWrite(cona2web, HIGH);
}
}