

This circuit is designed to control a mini diaphragm water pump based on humidity levels detected by a DHT11 sensor and a YL-69 soil moisture sensor. The system uses an Arduino Nano as the central microcontroller to process sensor data, control a relay module that powers the water pump, and display readings on an LCD I2C display. The circuit is powered by a 18650 Li-Ion battery.
D2 connected to DHT11 signal pinD3 connected to Relay module signal pinA0 connected to Humidity YL-69 sensor analog outputA4 (SDA) connected to LCD I2C Display SDA pinA5 (SCL) connected to LCD I2C Display SCL pin5V connected to 5V pins of Relay module, DHT11, LCD I2C Display, and Humidity YL-69 sensorGND connected to ground pins of Relay module, DHT11, LCD I2C Display, and Humidity YL-69 sensorVIN connected to the positive terminal of the 18650 Li-Ion batteryS (Signal) connected to Arduino Nano D35V and GND connected to Arduino Nano 5V and GND respectivelyCOM (Common) connected to the negative terminal of the 18650 Li-Ion batteryNO (Normally Open) connected to the negative terminal of the Mini Diaphragm Water PumpS (Signal) connected to Arduino Nano D25V and GND connected to Arduino Nano 5V and GND respectivelySDA connected to Arduino Nano A4SCL connected to Arduino Nano A5VCC connected to Arduino Nano 5VGND connected to Arduino Nano GNDA0 (Analog Output) connected to Arduino Nano A0VCC connected to Arduino Nano 5VGND connected to Arduino Nano GNDPositive (+) connected to the positive terminal of the 18650 Li-Ion batteryNegative (-) connected to the NO pin of the Relay modulePositive connected to Arduino Nano VIN and Mini Diaphragm Water Pump Positive (+)Negative connected to the COM pin of the Relay module/*
* Arduino Sketch for controlling a water pump based on humidity levels
* and displaying sensor data on an LCD.
*
* Components:
* - Arduino Nano
* - Relay module 1 channel
* - DHT11 sensor
* - LCD I2C Display
* - Humidity YL-69 sensor
* - Mini Diaphragm Water Pump
* - 18650 Li-Ion battery
*/
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <DHT.h>
// Pin definitions
#define DHTPIN 2
#define RELAY_PIN 3
#define HUMIDITY_SENSOR_PIN A0
// DHT sensor type
#define DHTTYPE DHT11
// Initialize DHT sensor
DHT dht(DHTPIN, DHTTYPE);
// Initialize LCD
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup() {
// Start serial communication
Serial.begin(9600);
// Initialize DHT sensor
dht.begin();
// Initialize LCD
lcd.init();
lcd.backlight();
// Set relay pin as output
pinMode(RELAY_PIN, OUTPUT);
// Set initial state of relay
digitalWrite(RELAY_PIN, LOW);
}
void loop() {
// Read humidity and temperature from DHT11
float humidity = dht.readHumidity();
float temperature = dht.readTemperature();
// Read soil moisture level
int soilMoisture = analogRead(HUMIDITY_SENSOR_PIN);
// Display data on LCD
lcd.setCursor(0, 0);
lcd.print("Temp: ");
lcd.print(temperature);
lcd.print(" C");
lcd.setCursor(0, 1);
lcd.print("Humidity: ");
lcd.print(humidity);
lcd.print(" %");
// Control relay based on soil moisture level
if (soilMoisture < 500) { // Adjust threshold as needed
digitalWrite(RELAY_PIN, HIGH); // Turn on pump
} else {
digitalWrite(RELAY_PIN, LOW); // Turn off pump
}
// Print data to serial monitor
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.print(" C, Humidity: ");
Serial.print(humidity);
Serial.print(" %, Soil Moisture: ");
Serial.println(soilMoisture);
// Wait before next loop
delay(2000);
}
This code is responsible for reading temperature and humidity data from the DHT11 sensor, soil moisture from the YL-69 sensor, controlling the relay to power the water pump, and displaying the sensor data on the LCD. The relay is activated when the soil moisture level falls below a predefined threshold, indicating that the soil is dry and the plant requires watering.