code returns wrong value

This code somehow leads to my Relais (PUMP_PIN in this case) being constantly HIGH even if soilmoist isn't smaller then DRY_SOIL. I've tried swapping HIGH for LOW wich has helped me with relais in the past but it stayed HIGH annyways. I've checked the hardware and the wiring (I'm using a WEMOS D1 R1) including the relais. I know this is a personel topic but I just don't have annybody else to ask and I couldn't fix this by myself.
Thanks

#define BLYNK_PRINT Serial    
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
WidgetLED PUMP(V0); 
#include "DHT.h"
#include <SimpleTimer.h>
#define DHTPIN D4     // pin  DATA with D4
#define SOIL_MOIST_1_PIN A0 // pin A0 with A0
#define PUMP_PIN D13   // PUMP RELAY
#define DHTTYPE DHT11   
#define DRY_SOIL      15
#define WET_SOIL      50
#define TIME_PUMP_ON  15
#define READ_SOIL_HUM_TM  10L 
#define READ_AIR_DATA_TM  2L  
#define SEND_UP_DATA_TM   10L 
#define AUTO_CTRL_TM      60L 
char auth[] = "ksdjhkjshdgiq3";
char ssid[] = "ssid";
char pass[] = "87235120";
float humDHT = 0;
float tempDHT = 0;
int soilMoist = 0;
boolean pumpStatus = 0;
int timePumpOn = 1; 
long sampleTimingSeconds = 20; 
long startTiming = 0;
long elapsedTime = 0;
SimpleTimer timer;
DHT dht(DHTPIN, DHTTYPE);

void setup() {
  pinMode(PUMP_PIN, OUTPUT);
 aplyCmd();
  Serial.begin(115200);
  dht.begin();    
  Blynk.begin( auth, ssid , pass );
  PUMP.off();
 startTimers();
 digitalWrite(PUMP_PIN, LOW);

}
void loop() {
  timer.run(); 
  Blynk.run();
  
}
BLYNK_WRITE(3) 
{
  int i = param.asInt();
  if (i == 1)
  {
    pumpStatus = !pumpStatus;
    aplyCmd();
  }
}
void getSoilMoist(void)
{
  int i = 0;
  soilMoist = 0;
  for (i = 0; i < 10; i++)  //
  {
    soilMoist += analogRead(SOIL_MOIST_1_PIN); 
    delay(20);   
  }
  soilMoist = soilMoist / (i);
  soilMoist = map(soilMoist, 1023, 0, 0, 100); 

}
void getDhtData(void)
{
tempDHT = dht.readTemperature();
  humDHT = dht.readHumidity();
  if (isnan(humDHT) || isnan(tempDHT))   
  {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }
}
void aplyCmd()
{
  if (pumpStatus == 1)
  {
    Blynk.notify("pump ON");
    digitalWrite(PUMP_PIN, HIGH);
    PUMP.on();
  }

  else {
    digitalWrite(PUMP_PIN, LOW);
    PUMP.off();
  }
}
void autoControlPlantation(void)
{
  if (soilMoist < DRY_SOIL)
  {
    turnPumpOn();
  }
  else {
    digitalWrite(PUMP_PIN, LOW);
  }
}
void turnPumpOn()
{
  pumpStatus = 1;
  aplyCmd();
  delay (TIME_PUMP_ON * 1000);
  pumpStatus = 0;
  aplyCmd();
}
void startTimers(void)
{
  timer.setInterval(READ_AIR_DATA_TM * 1000, getDhtData);
  timer.setInterval(READ_SOIL_HUM_TM * 1000, getSoilMoist);
  timer.setInterval(SEND_UP_DATA_TM * 1000, sendUptime);
  timer.setInterval(AUTO_CTRL_TM * 1000, autoControlPlantation);
}
void sendUptime()
{
  Blynk.virtualWrite(1, tempDHT);
  Serial.println(tempDHT); 
  Blynk.virtualWrite(2, humDHT); 
  Blynk.virtualWrite(3, soilMoist);
  Serial.println(soilMoist);
}

How are things wired up? Attache the wiring diagram.

I would start with assumption that the code returns with the value you ask it to.

That of course might not be the value you want to see.

Here's a shitty drawing I made but you can also see what is attached where by reading the code

Use Serial Monitor and temporary use Serial.print inside the code to see what's going on. Printout nanalog values, digital state of important variables.

Hi,
You need a 4k7 resistor between the DHT11 signal wire and 5V.

Thanks.. Tom... :slight_smile: