This circuit is designed to control a water pump based on soil moisture levels and display sensor data on an LCD. The main components include an Arduino Nano, a relay module, a DHT11 sensor, an LCD I2C display, a Humidity YL-69 sensor, a mini diaphragm water pump, and a 18650 Li-Ion battery. The Arduino Nano reads data from the DHT11 and Humidity YL-69 sensors, displays the data on the LCD, and controls the water pump via the relay module.
Arduino Nano
Relay module 1 channel
DHT11
LCD I2C Display
Humidity YL-69
Mini Diaphragm Water Pump
18650 Li-Ion
rp2040 zero
ESP32C3 Supermini
Arduino Nano ESP32
/*
* 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 initializes the DHT11 sensor and LCD, reads humidity and temperature data from the DHT11, reads soil moisture levels from the Humidity YL-69 sensor, displays the data on the LCD, and controls the water pump via the relay module based on the soil moisture levels. The data is also printed to the serial monitor for debugging purposes.