Lawn irrigation controller

About This Project

I have lawn water irrigation system, with

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: https://cayenne.mydevices.com/shared/5d9502434ed44e3f57eeac03/project/781f5390-66df-4e75-8bd6-7afeb6056dbe

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);
  }  
}
2 Likes

Thanks for sharing this project. Can you share some pics of your project in the wild.

I liked this and it would be great if you can integrate this in your project.

At this point project can be functional. This lawn watering season is at the end. During winter project is in the testing phase for reliability and improvements.

Remark: R6 in scheme is not 10k, must be lower to reach LOW level voltage threshold, because soil moisture sensor is not NO/NC or LOW/HIGH state.
endless = no sensor present, 10kohms = sensor present and dry, short = sensor present and wet

2 Likes

I need to repair electronic scheme. There is an error in the current electronic circuit, described here:
https://espeasy.readthedocs.io/en/latest/Reference/GPIO.html#best-pins-to-use-on-esp8266

D8 (GPIO 15) has pullup resistor which causes boot problem. D8 is now D5.

2 Likes

The development phase is complete.

  1. row
  • icon 1.1 soil moisture sensor status dry or damp
  • icon 1.2 and 1.4 manual on/off and weekly schedule
  • icon 1.3 and 1.5 actual valve status
  • icon 1.6 rain forecast in next 24 hours from openweathermap
  • icon 1.7 rain threshold; if rain forecast is bigger than threshold schedule in not working
  1. row
  • icon 2.1 and 2.2. current soil temperature 5 and 10 cm deep
  • icon 2.3 current air temperature from openweathermap
  • icon 2.4 WiFi RSSI signal strenght
  • icon 2.5 reset both cumulative valve time
  • icon 2.6 and 2.7 cumulative open time in minutes for valve 1 and 2

alerts:

  • when rain forecast meet criteria send email, useful for fertilization or over seeeding
1 Like

Great work @Idnas.