Ammar Shahid
Published © GPL3+

Automated Plant Watering System

A device that waters plants and monitors temprature using an ESP8266 and Android app.

EasyWork in progress3,698
Automated Plant Watering System

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
DHT11 Temperature & Humidity Sensor
DHT11 Temperature & Humidity Sensor
×1
Grove - OLED Display 1.12'' V2
Seeed Grove - OLED Display 1.12'' V2
×1
ESP8266 ESP-01
Everything ESP ESP8266 ESP-01
×1
Relay (generic)
×1

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Hot glue gun (generic)
Hot glue gun (generic)

Story

Read more

Schematics

Automated Garden Watering

Circuit Design I made. I lack a lot of skills so be creative
Auto garden bb qmpfzplrwm

Code

Automated Garden Watering Nano

Arduino
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <DHT.h>


#define DHTPIN 2     // what pin we're connected to
#define DHTTYPE DHT11   // DHT 11
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);


// Initialize DHT sensor for normal 16mhz Arduino
DHT dht(DHTPIN, DHTTYPE);
String info;
boolean watering= false, status=false;
void setup()
{
  Wire.begin();
  dht.begin(); // initialize dht
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);// initialize with the I2C addr 0x3C (for the 128x32)(initializing the display)
  Serial.begin(9600);
}
void displayTempHumid(){
  delay(2000);
  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  float h = dht.readHumidity();
  // Read temperature as Celsius
  float t = dht.readTemperature();
  // Read temperature as Fahrenheit
  float f = dht.readTemperature(true);
  // Check if any reads failed and exit early (to try again).
  if (isnan(h) || isnan(t) || isnan(f)) {
    display.clearDisplay(); // clearing the display
    display.setTextColor(WHITE); //setting the color
    display.setTextSize(1); //set the font size
    display.setCursor(5,0); //set the cursor coordinates
    display.print("Failed to read from DHT sensor!");
    return;
  }
  display.clearDisplay();
  display.setTextColor(WHITE);
  display.setTextSize(1);
  display.setCursor(0,0);
  display.print("Humidity: "); 
  display.print(h);
  display.print(" %\t");
  display.setCursor(0,10);
  display.print("Temperature: "); 
  display.print(t);
  display.print(" C"); 
  display.setCursor(0,20);
  display.print("Temperature: "); 
  display.print(f);
  display.print(" F"); 
}

void loop()
{ 
  displayTempHumid();
  display.display();  
}

Automated Garden Watering Esp8266

Arduino
The code for Esp8266 used in this project
/*
 *  This sketch demonstrates how to set up a simple HTTP-like server.
 *  The server will set a GPIO pin depending on the request
 *    http://server_ip/gpio/0 will set the GPIO2 low,
 *    http://server_ip/gpio/1 will set the GPIO2 high
 *  server_ip is the IP address of the ESP8266 module, will be 
 *  printed to Serial when the module is connected.
 */

#include <ESP8266WiFi.h>

const char* ssid = "ASH";
const char* password = "12345678";

// Create an instance of the server
// specify the port to listen on as an argument
WiFiServer server(80);

boolean waternow=false;

void setup() {
  Serial.begin(9600);
  delay(10);
  pinMode(2, OUTPUT);

 
  
  // Connect to WiFi network
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
  
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");
  
  // Start the server
  server.begin();
  Serial.println("Server started");

  // Print the IP address
  Serial.write(WiFi.localIP());
}

void loop() {
  // Check if a client has connected
  WiFiClient client = server.available();
  if (!client) {
    return;
  }
  
  // Wait until the client sends some data
  Serial.println("new client");
  while(!client.available()){
    delay(1);
  }
  
  // Read the first line of the request
  String req = client.readStringUntil('\r');
  client.flush();
  
  
  int val;
  
  if (req.indexOf("manu/ON") != -1){
  waternow=true;}
  else if (req.indexOf("manu/OFF") != -1){
   waternow=false;}
    
  else {
    Serial.println("invalid request");
    client.stop();
    return;
  }

  
  
  client.flush();

 
  delay(1);
  Serial.println("Client disonnected");
  if (waternow==true){ digitalWrite(2, HIGH);
  delay (30000);
  waternow=false;}
  else{digitalWrite(2, LOW);}

  // The client will actually be disconnected 
  // when the function returns and 'client' object is detroyed
}

Credits

Ammar Shahid

Ammar Shahid

1 project • 0 followers

Comments

Add projectSign up / Login