NodeMCU Watering System

##General introduction, About This Project

Had an old watering controller that failed ages ago, but the water solenoids were still installed.
Got a NodeMCU 12E and a four relay board and taught bmyself how to programme it and use Cayenne
as the IoT interface. Added a DHT-11 temp/humidity sensor and there you go yet another watering system
controlled by Cayenne. Took me two days to code it and one day to build the box and install it. Nothing
fancy but Hey it works!

Who says new tricks can’t be learnt when you are 62 yrs old!!

What’s Connected

NodeMCU 12E
4 realy board
WIFI connected

Scheduling

Scheduling works fine

Dashboard Screenshots

##Project Photos
Temperature sensor housingtemp sensor 1|690x460


In the box ready to run

Code of Project

#include <CayenneMQTTESP8266.h>
#include <SimpleDHT.h>

int pinDHT11 = D5;
SimpleDHT11 dht11;
int temperature;
int humidity;

#define RELAY1_PIN D1 // RELAY1 PIN
#define RELAY2_PIN D2// RELAY2 PIN
#define RELAY3_PIN D3 // RELAY3 PIN
#define RELAY4_PIN D4 // RELAY4 PIN

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

void setup()
{
  
  Cayenne.begin(username, password, clientID, ssid, wifiPassword);
  pinMode(RELAY1_PIN, OUTPUT);
  pinMode(RELAY2_PIN, OUTPUT);
  pinMode(RELAY3_PIN, OUTPUT);
  pinMode(RELAY4_PIN, OUTPUT);
  digitalWrite(RELAY1_PIN, HIGH);
  digitalWrite(RELAY2_PIN, HIGH);
  digitalWrite(RELAY3_PIN, HIGH);
  digitalWrite(RELAY4_PIN, HIGH);
}

void loop()
{
  byte temperature = 0;
  byte humidity = 0;
  byte data[40] = {0};
  dht11.read(pinDHT11, &temperature, &humidity, data);
  Cayenne.virtualWrite(1, ((int)temperature));
  Cayenne.virtualWrite(3, ((int)humidity));
  // DHT11 sampling rate is 2HZ.
  delay(2000);
  Cayenne.loop();
}


CAYENNE_IN(2)
{
  // get value sent from dashboard
  int currentValue = getValue.asInt(); // 0 to 1

  // assuming you wire your relay as normally open
  if (currentValue == 0) {
    digitalWrite(RELAY1_PIN, HIGH);
  } else {
    digitalWrite(RELAY1_PIN, LOW);
  }
}


CAYENNE_IN(4)
{
  // get value sent from dashboard
  int currentValue = getValue.asInt(); // 0 to 1

  // assuming you wire your relay as normally open
  if (currentValue == 0) {
    digitalWrite(RELAY2_PIN, HIGH);
  } else {
    digitalWrite(RELAY2_PIN, LOW);
  }
}


CAYENNE_IN(6)
{
  // get value sent from dashboard
  int currentValue = getValue.asInt(); // 0 to 1

  // assuming you wire your relay as normally open
  if (currentValue == 0) {
    digitalWrite(RELAY3_PIN, HIGH);
  } else {
    digitalWrite(RELAY3_PIN, LOW);
  }
}


CAYENNE_IN(8)
{
  // get value sent from dashboard
  int currentValue = getValue.asInt(); // 0 to 1

  // assuming you wire your relay as normally open
  if (currentValue == 0) {
    digitalWrite(RELAY4_PIN, HIGH);
  } else {
    digitalWrite(RELAY4_PIN, LOW);
  }
}
5 Likes

Hi @vk3edw,

Wow thank you for sharing this! Any plans for a phase II ? Maybe add a soil moisture sensor in there?

It’d be really cool if you could show the watering system in action through a video too :slight_smile:

~B

nice project :slight_smile:

Very good project! :slight_smile:

nice project :slightly_smiling_face:

Very nice!

Awesome.

awesome project and thank you for the clarity in documenting it plus posting to code was a very nice touch, thank you

1 Like