Irrigation cycle by pressing a button

who knows how to automate by pressing a button the irrigation system?
example: pressing X relay button 1 step 10sec - realy 2- etc …

Arduino is going to be your best bet. Code for when digital/virtual (digital write high) pin high, then do action on digital pin for so many milli seconds then “digital write low”

@Massimotruglio83

Connect your irrigation system to a relay and connect relay to GPIO4 of esp8266 board.
fill all the details in the code below and upload it into the esp8266.
on cayenne dashboard add a custom button widget with channel 1 selected.

// This example shows how to connect to Cayenne using an ESP8266 and send/receive sample data.
// Make sure you install the ESP8266 Board Package via the Arduino IDE Board Manager and select the correct ESP8266 board before compiling.

//#define CAYENNE_DEBUG
#define CAYENNE_PRINT Serial
#include <CayenneMQTTESP8266.h>
int x;
// WiFi network info.
char ssid[] = "";
char wifiPassword[] = "";

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = ";
char password[] = "";
char clientID[] ="";

unsigned long lastMillis = 0;

void setup() {
  Serial.begin(9600);
  pinMode(4, OUTPUT);
  Cayenne.begin(username, password, clientID, ssid, wifiPassword);
}

void loop() {
  Cayenne.loop();
}
CAYENNE_IN(1)
{
  int currentValue = getValue.asInt();
  if (currentValue == 1)
  {
    digitalWrite(4, HIGH);
  }
  else
  {
    digitalWrite(4, LOW);
  }
}

i dint get what you are trying to do. can you give more detail about this.

I believe he wants to get a button he can press that will activate for a time then reset automatically.

Here is a post that has some code to do just that.

here it is. pressing a button I would like to be able to choose the irrigation time and then automatically switch off. so x 8 irrigation zones. would it be feasible?

@Massimotruglio83 for this you can add a slider and depending on the value of slider position you can set the time on for irrigation.
example. when slider is at 2, turn on the irrigation for 2 minutes.

please code :stuck_out_tongue:

the entire code :thinking:
first you give it a try

1 Like

I guess at least hno excuse to leave … try it with yun but it hangs … while with arduin one seems to go

can you post the code and error. then i can help you.

//#define CAYENNE_DEBUG         // Uncomment to show debug messages
#include <avr/io.h>
#include <avr/wdt.h>

#define Reset_AVR() wdt_enable(WDTO_30MS); while(1) {} 
#include "DHT.h"
#define DHTPIN 2 
#define DHTTYPE DHT22
#define CAYENNE_PRINT Serial  // Comment this out to disable prints and save space
#include <CayenneYun.h>
DHT dht(2,DHT22);
// Cayenne authentication token. This should be obtained from the Cayenne Dashboard.
char token[] = "+++++++++";
int cicloirri=0;
float tempoirri=0;
float h =0;
float t=0;
unsigned long STARTINGTIME; //GESTIONE TIMER
void setup()
{
  Serial.begin(9600);
  
  dht.begin();
  Cayenne.begin(token);
}

void loop()
{ 
  //delay(1000);
  Cayenne.run();
  delay(1000);
  // Cayenne.virtualWrite(V2,cicloirri);
                      
        
  
  


  h = dht.readHumidity(); // Leggo il valore di umidità
  t = dht.readTemperature(); // Leggo il valore di temperatura delay (1000);
 
    Serial.print("Umidità: ");
    Serial.print(h);
    Serial.print(" %\t");
    Serial.print("Temperatura: ");
    Serial.print(t);
    Serial.println(" *C");
    Cayenne.virtualWrite(V2,cicloirri);
    if (cicloirri==1)
       {Cicloirri();
       }

  
    }
CAYENNE_OUT(V0)
 {
    Cayenne.virtualWrite(0, h);
    
    Serial.println("inviato dati!");
    }
CAYENNE_OUT(V1)
 {
    
    Cayenne.virtualWrite(1, t);
    Serial.println("inviato dati!!");
    }
void Cicloirri()

  { 
  
    Serial.println("inizio ciclo irri");
    digitalWrite(3,LOW);
    delay(tempoirri);
    Serial.println("chiudo 1 apro 2");
    digitalWrite(3,HIGH);
    digitalWrite(4,LOW);
    delay(tempoirri);
    Serial.println("chiudo 2 apro 3");
    digitalWrite(4,HIGH);
    digitalWrite(5,LOW);
    delay(tempoirri);
    digitalWrite(5,HIGH);
    Serial.println("fine ciclo");
    
    
    
  
   
  
  cicloirri=0;
   Cayenne.run();
   delay(1000);
  Cayenne.virtualWrite(V2,cicloirri);
  Cayenne.syncAll();
}
  CAYENNE_IN(V2)
{ Cayenne.syncAll(); 
  CAYENNE_LOG("Got a value: %s", getValue.asStr());
  // You can also use:
  cicloirri = getValue.asInt() ;
 
  
  // double d = getValue.asDouble()
}
 CAYENNE_IN(V3)
{
  CAYENNE_LOG("Got a value: %s", getValue.asStr());
  // You can also use:
  tempoirri = getValue.asInt() ;
  Serial.println(tempoirri);
 
  
  // double d = getValue.asDouble()
}
CAYENNE_DISCONNECTED() {
Reset_AVR();
}

can you post the error and give a bit detail about your code.

not by mistake, but but crashes arduino and does not do the correct cycle

I looked over the code quick and didn’t notice anything that stood out. As @shramik_salgaonkar said, what error are you getting?

it does not do its job, it crashes it disconnects and starts again …

There must be some error though, right? Is it a WDT reset?

Why do you need this, esp keeps connection up and reset its self if no conection.

Regarding your question, if you want your relays to activate at certain time, use schedule.
If you want to have it on demand using button press then better solution is to use hardware solution and timers/milis other than cloud system, then after that you can add Cayenne actuator for remote controle of that hardware button.
Its more reliable solution

2 Likes