b_anz
Published © GPL3+

Instant Green Thumb

Automated irrigation for a small vertical herb garden.

BeginnerFull instructions provided2 hours7,305
Instant Green Thumb

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
DHT11 Temperature & Humidity Sensor (4 pins)
DHT11 Temperature & Humidity Sensor (4 pins)
×1
SparkFun Soil Moisture Sensor (with Screw Terminals)
SparkFun Soil Moisture Sensor (with Screw Terminals)
×1
434MHz RF-transmitter
×1
small indoor fountain pump (submersible) + hose
×1
remote control power socket
×1
timer (optional)
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Custom parts and enclosures

Planter (sketchup file)

Schematics

Fritzing diagram

Code

Instant green thumb

Arduino
#include <RCSwitch.h>
#include "DHT.h"

RCSwitch mySwitch = RCSwitch();

//#define
#define MOISTURE A0
#define DHTPIN 2
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE, 15);

//initial states
int moisturecurrent = 0;
int distancecurrent = 0;
int duration = 0;

//pins
int TRIGGER = 5;
int ECHO = 4;
int POWER = 7;

/************************SETUP****************************/
void setup() {

  dht.begin();

  // set pin as an input/output
  pinMode(MOISTURE, INPUT_PULLUP);
  pinMode(POWER, OUTPUT);
  pinMode(TRIGGER, OUTPUT);
  pinMode(ECHO, INPUT);

  Serial.begin(115200);

  // Transmitter Arduino Pin
  mySwitch.enableTransmit(12);
  mySwitch.setPulseLength(306);

}

/*******************************LOOP**************************/
void loop() {

  //switch off radio-controlled power socket
  mySwitch.send(4212052, 24);
  delay(1000);
  mySwitch.send(4212052, 24);
  delay(1000);

  /*IF1:Temperature>5°C********************************/

  int humidity_data = (int)dht.readHumidity();
  int temperature_data = (int)dht.readTemperature();

  Serial.print(F("Temperature: "));
  Serial.println(temperature_data);

  Serial.print(F("Humidity: "));
  Serial.println(humidity_data);

  if (temperature_data > 5)
  {
    Serial.println(F("Temperature ok"));

    /*IF2:Distance<25cm***************************/

    //Read sensor data: distance
    digitalWrite(TRIGGER, LOW);
    delay(5);
    digitalWrite(TRIGGER, HIGH);
    delay(10);
    digitalWrite(TRIGGER, LOW);
    duration = pulseIn(ECHO , HIGH);
    distancecurrent = (duration / 2) / 29.1;
    delay(1000);

    int distance_data = (int)distancecurrent;

    //publish
    Serial.print(F("Distance: "));
    Serial.print(distance_data);
    Serial.println(" cm");

    //dry-run safeguard for water pump:
    //distance to bottom of water bucket: 30cm; min. water level: 5cm
    //this will probably need adjusting to your specific setup
    if (distance_data < 25)
    {

      /*IF3:moisture<300****************************/

      //Read sensor data: moisture
      digitalWrite(POWER, HIGH);
      moisturecurrent = analogRead(MOISTURE);
      delay(1000);
      digitalWrite(POWER, LOW);

      int moisture_data = (int)moisturecurrent;

      //publish
      Serial.print(F("Soil moisture: "));
      Serial.println(moisture_data);

      if (moisture_data < 400)
      {
        //switch on radio-controlled power socket
        mySwitch.send(4212049, 24);
        delay(1000);
        mySwitch.send(4212049, 24);
        delay(1000);

        //water for 10 seconds
        Serial.println(F("...Watering..."));
        delay(10 * 1000);

        //switch off power socket
        mySwitch.send(4212052, 24);
        delay(1000);
        mySwitch.send(4212052, 24);
        delay(1000);

        Serial.println(F("Waiting 1 min."));
        for (int i = 1; i <= 1; i = i + 1) {
          delay(20 * 1000);
          Serial.print(F("."));
          delay(20 * 1000);
          Serial.print(F("."));
          delay(20 * 1000);
          Serial.println(F("."));
        }

      } //ENDIF3

      else
      {



        Serial.println(F("Watering not necessary at the moment."));
        Serial.println(F("Waiting 10 min."));
        for (int i = 1; i <= 10; i = i + 1) {
          delay(20 * 1000);
          Serial.print(F("."));
          delay(20 * 1000);
          Serial.print(F("."));
          delay(20 * 1000);
          Serial.println(F("."));
        }
      }

    }  //ENDIF2
    else
    {
      if (distance_data > 30)
      {
        Serial.println(F("Error. Unplausible water level."));
      }
      else
      {
        Serial.println(F("Water bucket empty. Refill necessary!"));
      }
      Serial.println(F("Waiting 5 min."));
        for (int i = 1; i <= 5; i = i + 1) {
          delay(20 * 1000);
          Serial.print(F("."));
          delay(20 * 1000);
          Serial.print(F("."));
          delay(20 * 1000);
          Serial.println(F("."));
        }
    }

  }  //ENDIF1
  else {
    Serial.println(F("Too cold for watering"));
  }

} //End loop

Credits

b_anz

b_anz

1 project • 4 followers

Comments