BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Need help with code for greenhouse automation

I am new to Arduino and I am needing some help. I ordered WeMos D1 Mini and a DHT11 for temperature and humidity monitoring. I am also wanting to monitor soil moisture and activate a relay for a 12v pump when the soil moisture is low. Any help with this would be greatly appreciated.

Would you like to have a look at

Thanks for the quick reply ! Did you develop this code ?

Please don’t blame me if something goes wrong :wink:

LOL ! I am not going to… Thank you for the code though I appreciate it. Do you have any diagrams on what pins to connect the sensors to ?

All inside the code, but here it is the link

and the code snippet


#if USE_ESP32

  //#define PIN_RESET         PIN_D0    //16
  #define DHTPIN            PIN_D22            // pin DATA @ D22 / GPIO22
  #define PUMP_RELAY_PIN    PIN_D23            // PUMP RELAY @ D21
  #define SOIL_MOIST_PIN    PIN_D32            // pin GPIO32 for analog input

#else   //USE_ESP32

  //#define PIN_RESET         PIN_D0    //16
  #define DHTPIN            PIN_D2            // pin DATA @ D2
  #define PUMP_RELAY_PIN    PIN_D1            // PUMP RELAY @ D1
  #define SOIL_MOIST_PIN    A0                // pin A0 with A0

#endif    //USE_ESP32

Hope you’ll later send me some vegetables from your greenhouse if it’s working.

So I need to order a esp32 board. I have a esp12 on order right now. I am sorry if these are stupid questions. just learning. Thanks for all the info

No, you just use WeMos D1 Mini. The code is written for both ESP8266 (such as WeMos D1 Mini) and ESP32.

The default config is for ESP8266:

//Ported to ESP32
//#define USE_ESP32         true
#define USE_ESP32         false

So you just compile and use as is.

okay cool… I really appreciate all the help

Khoih I have a question. I am just using the basic sketch for the DHT11 for my greenhouse right now. I am wanting to put this in deep sleep with a 10 minute delay. It is on a ESP8266 D1 Mini board. The sketch I am using is from the blynk sketch browser. Could you please tell me how I could go about doing this ?

You can just use the SmartFarm-DeepSleep code as is, then select DHT11 as the sensor.

If you’d like and have time + energy, you can either

  1. copy the DeepSleep code portion to your basic sketch
  2. or delete the unnecessary code

Thats where I was getting confused. New to this and didnt know where the deep sleep code needed to be placed in the sketch. I will also have to place a jumper to the rst pin correct ?

I’m sorry I’m so busy right now and can’t help you with the code. You have to start trying the best you can, then someone will help guide you to finish.
I don’t know if @Madhukesh can help you now.

Its okay… I will search youtube and give it a go. I appreciate all the help you have given me to this point. Thanks !

I am afraid to help you on this, because i have not worked on deep sleep. But i will give it a try.

As @khoih said delete the lines which are not necessary. Each section has been commented with info on what it does, if you give enough time and study the code you can get it working.

Yes connect RST pin to GPIO16

void deep_sleep() {
Blynk.disconnect();
WiFi.mode(WIFI_OFF);
ESP.deepSleep(60000000); \\ 60 Seconds
}

Call this function once you have got the readings from the sensor.
This is all you need to put the ESP in deep sleep and wake up again at set interval.

I would say better start with a simple deep sleep sketch and once you get it working you can add it to Blynk. Once you have a basic code you can post it here and we can help you.

@khoih correct me if am wrong.

1 Like

This is the code that I am currently running. It goes into deep sleep but it never send the temp or humidity values to blynk.

[Unformatted code removed by moderator]

You’ve not done the triple backtick thing again, so I’ve removed your code.

Please keep the discussion about this subject to one topic, rather than the two that you have created. I’ll merge the other topic into this one to keep everything together.

Pete.

I am in need of some help. I am monitoring the temp and humidity in a greenhouse and I got the deep sleep to work on my ESp8266 D1 mini board but it does not send the sensor data using this code. Can anyone please help me with this ? Any help would be appreciated.

  Download latest Blynk library here:
    https://github.com/blynkkk/blynk-library/releases/latest

  Blynk is a platform with iOS and Android apps to control
  Arduino, Raspberry Pi and the likes over the Internet.
  You can easily build graphic interfaces for all your
  projects by simply dragging and dropping widgets.

    Downloads, docs, tutorials: http://www.blynk.cc
    Sketch generator:           http://examples.blynk.cc
    Blynk community:            http://community.blynk.cc
    Follow us:                  http://www.fb.com/blynkapp
                                http://twitter.com/blynk_app

  Blynk library is licensed under MIT license
  This example code is in public domain.

 *************************************************************

  This example shows how value can be pushed from Arduino to
  the Blynk App.

  WARNING :
  For this example you'll need Adafruit DHT sensor libraries:
    https://github.com/adafruit/Adafruit_Sensor
    https://github.com/adafruit/DHT-sensor-library

  App project setup:
    Value Display widget attached to V5
    Value Display widget attached to V6
 *************************************************************/

/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial


#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <DHT.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "";
char pass[] = "";

#define DHTPIN 2          // What digital pin we're connected to

// Uncomment whatever type you're using!
#define DHTTYPE DHT11     // DHT 11
//#define DHTTYPE DHT22   // DHT 22, AM2302, AM2321
//#define DHTTYPE DHT21   // DHT 21, AM2301

DHT dht(DHTPIN, DHTTYPE);
BlynkTimer timer;

// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
void sendSensor()
{
  float h = dht.readHumidity();
  float t = dht.readTemperature(true); // or dht.readTemperature(true) for Fahrenheit

  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V5, h);
  Blynk.virtualWrite(V6, t);
}

void setup()
{
  // Debug console
  Serial.begin(9600);

  Blynk.begin(auth, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,60), 9443);

  dht.begin();

  // Setup a function to be called every second
  timer.setInterval(60000L, sendSensor);

  ESP.deepSleep(600 * 1000000,WAKE_RF_DEFAULT);   //try the default mode
  delay(100);
}

void loop()
{
  Blynk.run();
  timer.run();
}

@swtrpeter please edit your post, using the pencil icon at the bottom, and add triple backticks at the beginning and end of your code so that it displays correctly.
Triple backticks look like this:
```

Pete.

Sorry about that