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.
- The negative pin (-) on the module lines up with the blue line (-) on the breadboard
- The positive pin (+) lines up with the red line (+)
- Use two M-M wires to connect Arduino Uno to the breadboard.
- GND to the blue line (-)
- 5V to the red line (+).
- Connect the DHT11 sensor to the Arduino Uno.
- GND to the blue line (-)
- VCC to the red line (+)
- Data to your defined digital pin on Arduino (in my case it is digital pin 2)
- Wire up the relay module to the Arduino Uno
- Relay module + to the red line (+)
- Relay module – to the blue line (-)
- Relay module S to your defined digital pin on Arduino for the relay circuit (in my case it is digital pin 10)
- Relay module NO (Normally Open) to the positive terminal of the water pump
- Relay module COM (Common) to the positive terminal of the power supply (use the opposite side from the Arduino)
- The negative terminal of the water pump to the negative terminal of the power supply (use the opposite side from the Arduino)
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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
/* 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
2 replies 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?
Great web site. Lots of useful information here. I’m sending it to a few friends and also sharing in delicious. And naturally, thanks for your effort!