Overview
In this tutorial, we will be using an Arduino Uno microcontroller to control the activation and deactivation of a water pump via a relay module based on temperature and humidity readings from a DHT11 sensor. When the temperature and/or humidity exceed a certain threshold, the Arduino will activate the water pump to regulate the environment and deactivate automatically when conditions are met. This project is useful for use cases such as automating the watering of plants or regulating the humidity levels in a room or greenhouse.
Components Required
- Arduino Uno (or equivalent)
- Arduino-to-USB cable
- Power supply module
- Breadboard
- 5V relay module
- DHT11 temperature and humidity module
- Gikfun DC 3V 5V micro submersible mini water pump
- Jumper wires (8 Male-Female, 3 Male-Male)
Components Introduction
How does the water pump work?

The Gikfun DC 3V 5V Micro Submersible Mini Water Pump is a small device that uses a motor to drive an impeller or rotor, which moves water through the pump’s inlet and outlet ports. When the pump is turned on, the impeller creates a low-pressure area at the inlet, which sucks water into the pump and then pushes it out through the outlet at a higher pressure. The pump is submersible, meaning it can be fully submerged in water without damage, and is powered by a 3V or 5V DC power supply
Why use the power supply module?

The load rated current of the water pump is 0.18A while the Arduino pin could supply a maximum of 40mA. So, connecting the water pump directly to a UNO R3 board digital output is not recommended as the pump may require more power than the board can handle. Attempting to do so could potentially cause damage to the board. To prevent this, it is advisable to use a power supply module to provide the necessary power to the pump. In addition, the left and right voltage output can be configured independently.
Why use the relay?

The relay was used in this project to control the activation and deactivation of the water pump based on the temperature and humidity readings from the DHT11 sensor. Using a relay to control the water pump provides a safer and more efficient way to operate the system compared to directly connecting the water pump to the Arduino Uno. The relay module acts as a switch that isolates the low-voltage microcontroller circuit from the high-voltage water pump circuit, ensuring safe and reliable operation.
Circuit Diagram

- Place the power supply module on the breadboard.
- Use two M-M wires to connect Arduino Uno to the breadboard.
- GND to the blue line (-)
- Connect the DHT11 sensor to the Arduino Uno.
- Wire up the relay module to the Arduino Uno
Code
Before uploading the code: Make sure you install the dht_nonblocking library to use the sensor. The temperature and humidity in my testing environment are around 23°C and 50%. So, we will set the temperature threshold as 25°C and the humidity threshold as 65% for demonstration purposes in this tutorial. The exact thresholds for applications depend on the use case where the thresholds could be more extreme values.
/*
TITLE: Tutorial Code Demo
WRITER: Chenxi Zhu
DATE: 2023-03-28
DESCRIPTION:
Activating and Deactivating Water Pump with Environmental Readings
SOURCE:
Code adapted from
Elegoo Super Starter Kit for UNO Lesson 11 &
Controlling submersible pump with Arduino
https://www.sensingthecity.com/tutorial-controlling-submersible-pump-with-arduino/
*/
#include <dht_nonblocking.h>
#define DHT_SENSOR_TYPE DHT_TYPE_11
static const int DHT_SENSOR_PIN = 2;
static const int PUMP_PIN = 10;
DHT_nonblocking dht_sensor(DHT_SENSOR_PIN, DHT_SENSOR_TYPE);
// specify the temperature threshold to pump water
long temperature_threshold = 25; // in deg C
// specify the humidity threshold to pump water
long humidity_threshold = 65; // in %
// specify measurement cycle delay as 60 milliseconds
long measurement_delay = 60; //3000ul
/*
* Initialize the serial port.
*/
void setup( )
{
// set pin mode for pump as output
pinMode(PUMP_PIN, OUTPUT);
Serial.begin(9600);
}
/*
* Poll for a measurement, keeping the state machine alive. Returns
* true if a measurement is available.
*/
static bool measure_environment(float *temperature, float *humidity)
{
static unsigned long measurement_timestamp = millis();
if(millis() - measurement_timestamp > measurement_delay)
{
if(dht_sensor.measure(temperature, humidity) == true)
{
measurement_timestamp = millis();
return(true);
}
}
return(false);
}
/*
* Main program loop.
*/
void loop()
{
// define sensor variables
float temperature;
float humidity;
/* Measure temperature and humidity. If the functions returns
true, then a measurement is available. */
if(measure_environment(&temperature, &humidity) == true)
{
// print temperature and humidity
Serial.print("T = ");
Serial.print(temperature, 1);
Serial.print(" deg.C, H = ");
Serial.print(humidity, 1);
Serial.println("%");
if(temperature > temperature_threshold || humidity < humidity_threshold) {
digitalWrite(PUMP_PIN, HIGH);
Serial.print("pump on - ");
if(temperature > temperature_threshold) {
Serial.print("too hot");
}
if(humidity < humidity_threshold) {
Serial.print("too dry");
}
Serial.println();
} else {
digitalWrite(PUMP_PIN, LOW);
Serial.println("pump off");
}
delay(2000);
}
}
Demo
Sources
Elegoo Super Starter Kit for Uno, Lesson 11 DHT11 Temperature and Humidity Sensor
One reply on “Controlling water pump based on air temperature and humidity”
I want to use five 5V water pumps in one arduino board. How many external volt should be required?