Evan Rust
Published © GPL3+

ESP8266 Plant Grower

Use an EPS8266 and ThingSpeak to monitor your plant and use a grow light to boost your plant's height!

IntermediateFull instructions provided3 hours3,964
ESP8266 Plant Grower

Things used in this project

Hardware components

Jumper wires (generic)
Jumper wires (generic)
×1
LED (generic)
LED (generic)
9 blue, 3 red
×1
SparkFun ESP8266 Thing - Dev Board
SparkFun ESP8266 Thing - Dev Board
×1
Relay (generic)
×1
DHT11 Temperature & Humidity Sensor (4 pins)
DHT11 Temperature & Humidity Sensor (4 pins)
×1
Resistor 100 ohm
Resistor 100 ohm
12
×1

Software apps and online services

Arduino IDE
Arduino IDE
ThingSpeak API
ThingSpeak API

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Schematics

Schematic

Connect as-is

Code

Code

C/C++
Just copy and paste, fill in your API key for ThingSpeak.
/*
 *  This sketch sends a message to a TCP server
 *
 */
//put your wifi network name here
#define SSID "ssid"
//put your wifi password here
#define PASS "pass"
#define API_KEY "API key here"
#define DHTPIN 13
#define DHTTYPE DHT11
#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>
#include "DHT.h"

ESP8266WiFiMulti WiFiMulti;
DHT dht(DHTPIN,DHTTYPE);

void setup() {
  pinMode(12,OUTPUT);
  digitalWrite(12,true);
    Serial.begin(115200);
    delay(10);
    dht.begin();

    // We start by connecting to a WiFi network
    WiFiMulti.addAP(SSID, PASS);

    Serial.println();
    Serial.println();
    Serial.print("Wait for WiFi... ");

    while(WiFiMulti.run() != WL_CONNECTED) {
        Serial.print(".");
        delay(500);
    }

    Serial.println("");
    Serial.println("WiFi connected");
    Serial.println("IP address: ");
    Serial.println(WiFi.localIP());

    delay(500);
}


void loop() {
    const uint16_t port = 80;
    const char * host = "api.thingspeak.com"; // ip or dns

    float h = dht.readHumidity();
    delay(200);
  // Read temperature as Celsius (the default)
  float f = dht.readTemperature(true);
  Serial.println(h);
  Serial.println(f);
    
    Serial.print("connecting to ");
    Serial.println(host);

    // Use WiFiClient class to create TCP connections
    WiFiClient client;

    if (!client.connect(host, port)) {
        Serial.println("connection failed");
        Serial.println("wait 5 sec...");
        delay(5000);
        return;
    }

    // This will send the request to the server
    String cmd1 = "GET /update?key=";
    cmd1 += API_KEY;
    cmd1+= "&field1=";
    cmd1 += String((int)f);
    cmd1 += "&field2=";
    cmd1 += String((int)h);
    cmd1 += "\r\n";
    client.print(cmd1);
    //debugging
    Serial.println(cmd1);

    //read back one line from server
    String line = client.readStringUntil('\r');
    client.println(line);

    Serial.println("closing connection");
    client.stop();
    digitalWrite(12,false);
    Serial.println("wait 10 hrs...");
    delay(1000*60*60*10);
    digitalWrite(12,true);
    //wait 14 hours off
    delay(1000*60*60*14);
}

Credits

Evan Rust

Evan Rust

120 projects • 1054 followers
IoT, web, and embedded systems enthusiast. Contact me for product reviews or custom project requests.

Comments