DHT11 sensor stop reading when water pump starts

Hello all,

I’ve got an issue with my DHT11 sensor. The DHT11 sensor read perfectly the value at the beginning of the loop, but as soon as my water pump starts (depending on the readings of the moisture sensor) then the DHT11 sensor stops to read any value.

These are the readings:

Too wet. Moisture level: 96%
Humidity: 52.00% Temperature: 27.00°C
Add some water. Moisture level: 1% (the water pump starts and stop after 3 seconds)
Add some water. Moisture level: 0% (the water pump starts and stop after 3 seconds)
Too wet. Moisture level: 105%
Humidity: nan% Temperature: nan°C

I tried to to get the DHT readings after the moisture reading but same issue.

Here is my code:

//Moisutre Sensor
int sensorPin = A0;
int waterPump = 5;
int thresholdUp = 45;
int thresholdDown = 25;

//Temperature and Humidity Sensor
#include "DHT.h"
#define DHTPIN 2
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);


void setup() {
  Serial.begin(9600);
  Serial.println(F("GreenHouse Sensor"));
  pinMode(waterPump, OUTPUT);
  dht.begin(); 
  

}

void loop() {

  delay(2000);
  int sensorValue;
  String DisplayWords;
  
  sensorValue = analogRead(sensorPin);
  sensorValue = map(sensorValue,370,1023,100,0);
  
  if (sensorValue >= thresholdUp){
      
      DisplayWords = "Too wet. Moisture level: ";
      digitalWrite(waterPump, LOW);    // turn the water pump off by making the voltage LOW
      Serial.print(DisplayWords);
      Serial.print(sensorValue);
      Serial.println("%");
      
       
  // Wait a few seconds between measurements.
  delay(2000);

  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  float h = dht.readHumidity();
  // Read temperature as Celsius (the default)
  float t = dht.readTemperature();
  // Read temperature as Fahrenheit (isFahrenheit = true)
  float f = dht.readTemperature(true);

//  // Check if any reads failed and exit early (to try again).
//  if (isnan(h) || isnan(t) || isnan(f)) {
//    Serial.println(F("Failed to read from DHT sensor!"));
//    return;
//  }

  // Compute heat index in Fahrenheit (the default)
  float hif = dht.computeHeatIndex(f, h);
  // Compute heat index in Celsius (isFahreheit = false)
  float hic = dht.computeHeatIndex(t, h, false);

  Serial.print(F("Humidity: "));
  Serial.print(h);
  Serial.print(F("%  Temperature: "));
  Serial.print(t);
  Serial.println(F("°C "));
  
  } else if (sensorValue <= thresholdDown){ 
      
      DisplayWords = "Add some water. Moisture level: ";
      digitalWrite(waterPump, HIGH);
      delay(3000);
      digitalWrite(waterPump, LOW);
      Serial.print(DisplayWords);
      Serial.print(sensorValue);
      Serial.println("%");
  
  } else {
      
      Serial.print(DisplayWords);
  
  }
}

Does the problem come from my code? Thanks in advance for your help.

hi edmaker,

  1. How do you power the pump? Does it have its own power supply ? If you try to power the pump from poor pin 5 of your Arduino then it might suck up enough power while running to have no juice left for the DHT11

  2. What I always do when I encounter bugs (they always pop up, it's incredible) is to have a led at hand. For your script I suggest to let a led light up simultaneously when the pump pin is set high - kind of indicator light !

  3. Another possibility is that the script might hang up your microprocessor. One way to debug is to send a message to Serial Monitor
    after each instruction that might cause problems -> Serial.print ("still running!");

  4. It is always helpful to post a picture and/or a wiring diagram of your setup.

Success, photoncatcher

Hi photoncatcher,

Thanks a lot for your answer.

  1. I powered the water pump following this example.

And then the DHT11 + moisture sensor are connected to the 5v, GND and there respective digital output for the DHT11 and analog output for the moisture sensor.

Like these pictures:

Breadboard

Arduino

Big Picture

  1. I will follow your advice and add a led, thanks.

  2. I added your command but I don't see any problem there.

still running!Too wet. Moisture level: 114%
still running!Humidity: 82.00% Temperature: 28.20°C
still running!Add some water. Moisture level: 1%
still running!Too wet. Moisture level: 113%
still running!Humidity: nan% Temperature: nan°C
still running!Too wet. Moisture level: 112%
still running!Humidity: nan% Temperature: nan°C

  1. I hope the pictures will help you to understand my wiring :slight_smile:

Thanks again

Short Update

I separated the source of power of the water pump but I still have the same problem. As soon as the motor is turned on and turned off, then the DHT11 stops to give any readings.

Is there anything I can do in the code to avoid this issue?

Hi edmaker,

I have the same problem, could you find a solution to your problem?

thanks.