WEMOS D1 Mini + shields + Blynk

I use Wemos D1 Mini + shields (DHT11, Relay + Funduino Soil Moisture sensor):

   #define BLYNK_PRINT Serial    
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <DHT.h>
#include <SimpleTimer.h>   //Good timer library

#define DHTPIN D4     // what pin we're connected to
#define Relay_1  D1  // Arduino Digital I/O pin number

#define DHTTYPE DHT11   // DHT 11
DHT dht(DHTPIN, DHTTYPE);
int temp;
int humidity;
// SoilMoisture Value
int moisture_val;
char auth[] = "1.....d"; //Auth Token for project

// Blynk Led Widget
WidgetLED led(V4); //register led to virtual pin 4

SimpleTimer timer;

void setup()
{
  Serial.begin(9600);
  dht.begin();
  Blynk.begin(auth, "ssid", "pasword");
  Serial.println("Blynk test!");

    
//-------( Initialize Pins so relays are inactive at reset)----
  digitalWrite(Relay_1, LOW);
//---( THEN set pins as outputs )----  
  pinMode(Relay_1, OUTPUT);   
  delay(4000); //Check that all relays are inactive at Reset


  // Setup function to be called every 2 seconds
timer.setInterval(2000, sendData);

}//--(end setup )---
  

void sendData()
{
 float t = dht.readTemperature();
 float h = dht.readHumidity();
  
  moisture_val = analogRead(A0); // read the value from the moisture sensor
  Blynk.virtualWrite(V2, t);
  Blynk.virtualWrite(V1, h);
  Blynk.virtualWrite(V3, moisture_val);
    if (moisture_val < 850)
           {
            led.on(); 
            digitalWrite (Relay_1, HIGH);
           }
           else
           { 
              led.off();
              digitalWrite (Relay_1, LOW);
           }
}

void loop()
{
  Blynk.run();
  timer.run(); // Initiates SimpleTimer
}

Now I prepare housing and “put on the field”.

2 Likes

Looks like a fun project, but you are bound to run into trouble with the delays you are using. I’d recommend using SimpleTimer to get your readings :slight_smile:

1 Like

Sorry, you read to fast, I published old version with delays, which really DO a lot of trouble :-). Thanks!

Lol, np, it just caught my eye in between work :wink:

2 Likes

you are awesome thank you! i will try it soon.

As a big fan of the WeMos D1 Mini and Blynk plus a critic of shields I was drawn to this thread by the title. In my mind the Mini and Blynk are excellent products but shields, in the main, are over priced extras you can do without. That’s coming from someone who can barely hold an iron.

The MCU’s are exceptional value for money (loss leaders?) but some shields are extortionate in comparison.

Enough of my drivel and the real reason for my post.

This is a great example of a bad sketch turned good. If you click the edit button in post 1 you will see the “history” of the sketch, starting with the delays over 14000ms in loop() ! This was the Arduino style sketch and may have been fine on an Arduino but certainly not an ESP with Blynk.

Looking at the revised sketch you can see that the essential SimpleTimer library has been added and it is now ESP and Blynk compliant.

I have saved both versions of the sketch to a single sketch in my sketchbook, called badtogoodsketch.ino.

2 Likes

sorry would you be able to help me?
what is the pin number soil moisture sensor connected to? i see D4 is for DHT 11, relay D1
i am a beginner

moisture_val = analogRead(A0); // read the value from the moisture sensor - it is A0 pin, as moisture is measured as analog value.

Complete working sketch:

#include "ESP8266WiFi.h"
#include "BlynkSimpleEsp8266.h"
#include "DHT.h"
#include "SimpleTimer.h"   //Good timer library

#define BLYNK_PRINT Serial  
#define DHTPIN D4     // what pin we're connected to
#define Relay_1  D1  // Arduino Digital I/O pin number
#define DHTTYPE DHT11   // DHT 11

DHT dht(DHTPIN, DHTTYPE);
int temp;
int humidity;
// SoilMoisture Value
int moisture_val;
char auth[] = "token "; //Auth Token for project 

// Blynk Led Widget
WidgetLED led(V4); //register led to virtual pin 4

SimpleTimer timer;

void setup()
{
  Serial.begin(9600);
  dht.begin();
 Blynk.begin(auth, "here your wifi name", "here your wifi password");
    
//-------( Initialize Pins so relays are inactive at reset)----
  digitalWrite(Relay_1, LOW);
//---( THEN set pins as outputs )----  
  pinMode(Relay_1, OUTPUT);   
  delay(4000); //Check that all relays are inactive at Reset


  // Setup function to be called every 2 seconds
timer.setInterval(2000, sendData);

} 
//--(end setup )---
  

void sendData()
{
 float t = dht.readTemperature();
 float h = dht.readHumidity();
  
  moisture_val = analogRead(A0); // read the value from the moisture sensor
  Blynk.virtualWrite(V2, t);
  Blynk.virtualWrite(V1, h);
  Blynk.virtualWrite(V3, moisture_val);
    if (moisture_val < 750)
           {
            led.on(); 
            digitalWrite (Relay_1, HIGH);
           }
           else
           { 
              led.off();
              digitalWrite (Relay_1, LOW);
           }
}

void loop()
{
  Blynk.run();
  timer.run(); // Initiates SimpleTimer
}