D3 and D4 are not working in my project

I made a project which controls a greenhouse. I used a nodemcu which is connected with blynk. I used blynk.adgent. I started the program using the scetch example of arduino Blynk.Edgent and I was adding code step by step according to my needs. I noticed that some pins didn’t work properly.
I’ m using 5 DHT11 sensors, 2 relays for controling light and watering and 4 relays for controling 2 motors for opening windows at the greenhouse. Unfortunatelly pins D3 and D4 doesn’t work. If I connect a sensor or a relay on D3 or D4 nodemcu stops communication with the blynk. So I didn’t connect a DHT11 sensor (which gives output) and an input of a relay. If I connect one or two relays or sensors on D3 or D4, without using any other pin, nodemcu can establish communication with nodemcu and the project works. I want to take advantage of all of the pins in order my project to work, but D3 and D4 don’t responding. I read about using a resistor but I don’t understand how to connect it and if this action is going to solve the problem.

Adding my code:

#define BLYNK_TEMPLATE_ID "TMPLtQmUC3jM"
#define BLYNK_TEMPLATE_NAME "Remote Greenhouse IOT"
#define BLYNK_FIRMWARE_VERSION        "0.2.6"
#include "DHT.h"
#define BLYNK_PRINT Serial
#define sensor A0
#define BLYNK_DEBUG
#define APP_DEBUG
#define USE_NODE_MCU_BOARD
#include "BlynkEdgent.h"

DHT dht1,dht2,dht3,dht4;
double Temperature1,Humidity1,Temperature2,Humidity2,Temperature3,Humidity3,Temperature4,Humidity4,avg_temperature,avg_humidity;

int soil_moisture_value,percentageSM;
const int dry = 595; // value for dry sensor 595
const int wet = 239; // value for wet sensor 239


BLYNK_WRITE(V0) { //Light uses D0 and V0
  bool value = param.asInt();
  // Check these values and turn the relay1 ON and OFF
  if (value == 1) {
    digitalWrite(D0, LOW);
    Serial.println("Turn on the light");
  } 
  else {
    digitalWrite(D0, HIGH);
    Serial.println("Turn off the light");
  }
}


BLYNK_WRITE(V1) { //Watering uses D1 and V1
  bool value = param.asInt();
  // Check these values and turn the relay1 ON and OFF
  if (value == 1) {
    digitalWrite(D1, LOW);
    Serial.println("Start watering");
  } 
  else {
    digitalWrite(D1, HIGH);
    Serial.println("Stop watering");
  }
}


BLYNK_WRITE(V2) { //Left motor (open) uses D5 and V2
  bool value = param.asInt();
  // Check these values and turn the relay1 ON and OFF
  if (value == 1) {
    delay(1000);
    digitalWrite(D5, LOW);
    digitalWrite(D6, HIGH);
    Blynk.virtualWrite(V3, LOW);
    Serial.println("Open left window");
  } 
  else {
    digitalWrite(D5, HIGH);
    Serial.println("Stop left window at this position");
  }
}

BLYNK_WRITE(V3) { //Left motor (close) uses D6 and V3
  bool value = param.asInt();
  // Check these values and turn the relay1 ON and OFF
  if (value == 1) {
    delay(1000);
    digitalWrite(D6, LOW);
    digitalWrite(D5, HIGH);
    Blynk.virtualWrite(V2, LOW);
    Serial.println("Close left window");
  } 
  else {
    digitalWrite(D6, HIGH);
    Serial.println("Stop left window at this position");
  }
}

BLYNK_WRITE(V10) { //Right motor (open) uses D4 and V10
  bool value = param.asInt();
  // Check these values and turn the relay1 ON and OFF
  if (value == 1) {
    delay(1000);
    digitalWrite(D3, LOW);
    digitalWrite(D8, HIGH);
    Blynk.virtualWrite(V11, LOW);
    Serial.println("Open right window");
  } 
  else {
    digitalWrite(D3, HIGH);
    Serial.println("Stop right window at this position");
  }
}

BLYNK_WRITE(V11) { //Right motor (close) uses D8 and V11
  bool value = param.asInt();
  // Check these values and turn the relay1 ON and OFF
  if (value == 1) {
    delay(1000);
    digitalWrite(D8, LOW);
    digitalWrite(D3, HIGH);
    Blynk.virtualWrite(V10, LOW);
    Serial.println("Close right window");
  } 
  else {
    digitalWrite(D8, HIGH);
    Serial.println("Stop right window at this position");
  }
}

void setup()
{
  Serial.begin(115200);

  pinMode(D0,OUTPUT); //Lamp
  digitalWrite(D0, HIGH);

  pinMode(D1,OUTPUT); //Watering
  digitalWrite(D1, HIGH);  

  pinMode(D5,OUTPUT); //Left motor open window
  digitalWrite(D5, HIGH);

  pinMode(D6,OUTPUT); //Left motor close window
  digitalWrite(D6, HIGH);

  pinMode(D3,OUTPUT); //Right motor open window
  digitalWrite(D3, HIGH);

  pinMode(D8,OUTPUT); //Right motor close window
  digitalWrite(D8, HIGH);

  dht1.setup(D2);
  dht2.setup(D7);
  dht3.setup(D9);  //RX
  dht4.setup(D10); //TX

  BlynkEdgent.begin();
}

void loop() {
  BlynkEdgent.run();

  Temperature1 = dht1.getTemperature();
  Humidity1 = dht1.getHumidity();
  
  Temperature2 = dht2.getTemperature();
  Humidity2 = dht2.getHumidity();

  Temperature3 = dht3.getTemperature();
  Humidity3 = dht3.getHumidity();
  
  Temperature4 = dht4.getTemperature();
  Humidity4 = dht4.getHumidity();

  avg_temperature=(Temperature1+Temperature2+Temperature3+Temperature4)/4.0;
  avg_humidity=(Humidity1+Humidity2+Humidity3+Humidity4)/4.0;  
  
  soil_moisture_value = analogRead(A0);
  percentageSM = map(soil_moisture_value, wet, dry, 100, 0); 


  Serial.print("Temperature1: " + String(Temperature1) + " *C");
  Serial.print("\t");  
  Serial.println("Humidity1: " + String(Humidity1) + " %");
  Serial.println("=================================================");
  Serial.print("Temperature2: " + String(Temperature2) + " *C");
  Serial.print("\t");  
  Serial.println("Humidity2: " + String(Humidity2) + " %");
  Serial.println("================================================="); 
  Serial.print("Temperature3: " + String(Temperature3) + " *C");
  Serial.print("\t");  
  Serial.println("Humidity3: " + String(Humidity3) + " %");
  Serial.println("=================================================");     
  Serial.print("Temperature4: " + String(Temperature4) + " *C");
  Serial.print("\t");  
  Serial.println("Humidity4: " + String(Humidity4) + " %");
  Serial.println("=================================================");
  Serial.print("Average temperature: " + String(avg_temperature) + " *C");
  Serial.print("\t");  
  Serial.println("Average humidity: " + String(avg_humidity) + " %");
  Serial.println("=================================================");
  Serial.println("Soil Moisture: " + String(percentageSM) + " %");

  Blynk.virtualWrite(V6, avg_temperature); //Average temprature uses V6
  Blynk.virtualWrite(V7, avg_humidity); //Average Humidity uses V7
  Blynk.virtualWrite(V4, percentageSM); //Soil moisture uses V4

  delay(2000);
}

You should read the article in the following link :point_down:t2:

There are very few usable pins available on ESP8288. If you have too many sensors to be connected, its better you switch over to ESP32. These have many pins that can support your project.

Https://docs.blynk.io/en/legacy-platform/legacy-articles/keep-your-void-loop-clean

You have too many stuff running on your loop. This will cause disconnects or random crashes.
So read the article in the link and clean your void loop();

You should also read this about the pins used by Edgent…

You really need to be using an ESP32 if you want that many pins.

Pete.

Thank you for your replies. I will probably use esp32. Can I use Blynk.Adgent with esp32? Do I have to change something to my code?

There is a Blynk Edgent example for ESP32.

Whichever board you use you need to remove the blocking delay() commands and remove all of the rubbish you’ve added to your void loop.
You should use BlynkTimer to call functions on a timed basis instead.

I’m unclear about what sort of widgets you have connected to datastreams V2, V3, V10 and V11, but the virtualWrites that you’re doing to these datastreams don’t make much sense to me.

If you’re changing hardware then you should probably also consider swapping to better temperature and humidity sensors than the DHT range.
The only thing that the DHT sensors have going for them is that they are cheap.

Pete.

Thank you for your help.