Cirkit Designer Logo
Cirkit Designer
Your all-in-one circuit design IDE
Home / 
Project Documentation

ESP32-Based Soil Moisture Monitoring and Watering System with Temperature Display

Image of ESP32-Based Soil Moisture Monitoring and Watering System with Temperature Display

Circuit Documentation

Summary

This circuit is designed to monitor soil moisture levels and temperature, control a water pump and a fan, and display the temperature on an LCD screen. The core of the circuit is an ESP32 microcontroller, which interfaces with a soil moisture sensor, a temperature sensor, a 2-channel relay module, a 5V mini water pump, a 40mm 12V fan, and an I2C LCD 16x2 screen. The ESP32 reads the sensors' data and controls the water pump and fan via the relay module based on the sensor inputs. The temperature is displayed on the LCD screen. The circuit is powered by a 12V battery, which also directly powers the fan.

Component List

  • Battery 12V: Provides the power source for the circuit.
  • SparkFun Soil Moisture Sensor: Measures the moisture level in the soil.
  • ESP32 (30 pin): Acts as the central microcontroller for processing sensor data and controlling other components.
  • USB Cable: Used to program the ESP32 and can also power the microcontroller.
  • 5V Mini Water Pump: Pumps water when activated by the ESP32 through the relay.
  • 40mm Fan 12V: Provides cooling and air circulation, controlled by the ESP32 through the relay.
  • 2-Channel Relay: Allows the ESP32 to control high-power devices such as the water pump and fan.
  • Temperature Sensor (TEMP): Measures the ambient temperature.
  • I2C LCD 16x2 Screen: Displays the temperature readings.

Wiring Details

Battery 12V

  • +: Connected to the Vin pin of the ESP32 and the +12V pin of the 40mm Fan 12V.
  • -: Connected to the GND pin of the ESP32, the -12V pin of the 40mm Fan 12V, and the common ground net.

SparkFun Soil Moisture Sensor

  • VCC: Connected to the 3V3 pin of the ESP32.
  • GND: Connected to the common ground net.
  • SIG: Connected to the D34 pin of the ESP32.

ESP32 (30 pin)

  • GND: Connected to the common ground net.
  • Vin: Connected to the + pin of the Battery 12V.
  • D34: Connected to the SIG pin of the SparkFun Soil Moisture Sensor.
  • D23: Connected to the IN1 pin of the 2-Channel Relay.
  • D22: Connected to the IN2 pin of the 2-Channel Relay and the SCL pin of the I2C LCD 16x2 Screen.
  • D21: Connected to the D3 pin of the Temperature Sensor and the SDA pin of the I2C LCD 16x2 Screen.
  • 3V3: Connected to the 5V pin of the Temperature Sensor, the VCC pin of the 2-Channel Relay, the VCC (5V) pin of the I2C LCD 16x2 Screen, and the VCC pin of the SparkFun Soil Moisture Sensor.

5V Mini Water Pump

  • Positive Pin: Connected to the NO pin of the 2-Channel Relay.
  • Negative Pin: Connected to the common ground net.

40mm Fan 12V

  • +12V: Connected to the + pin of the Battery 12V.
  • -12V: Connected to the common ground net.

2-Channel Relay

  • NC: Not connected in this circuit.
  • COM: Not connected in this circuit.
  • NO: Connected to the positive pin of the 5V Mini Water Pump.
  • VCC: Connected to the 3V3 pin of the ESP32.
  • IN1: Connected to the D23 pin of the ESP32.
  • IN2: Connected to the D22 pin of the ESP32.
  • GND: Connected to the common ground net.

Temperature Sensor (TEMP)

  • 5V: Connected to the 3V3 pin of the ESP32.
  • D3: Connected to the D21 pin of the ESP32.
  • GND: Connected to the common ground net.

I2C LCD 16x2 Screen

  • SCL: Connected to the D22 pin of the ESP32.
  • SDA: Connected to the D21 pin of the ESP32.
  • VCC (5V): Connected to the 3V3 pin of the ESP32.
  • GND: Connected to the common ground net.
  • Other Pins: Not connected in this circuit.

Documented Code

ESP32 Microcontroller Code

// The ESP32 code is not provided in the input. Please ensure that the code for the ESP32 is included here.

Temperature Sensor Code (Running on ESP32)

/*
 * This Arduino Sketch measures the temperature using a connected
 * temperature sensor and displays the value on an I2C LCD screen.
 */

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

// Define the I2C address for the LCD
#define I2C_ADDR 0x27

// Initialize the LCD
LiquidCrystal_I2C lcd(I2C_ADDR, 16, 2);

// Define the pin for the temperature sensor
const int tempSensorPin = 21; // D21 on ESP32

void setup() {
  // Initialize the LCD
  lcd.begin();
  lcd.backlight();
  lcd.setCursor(0, 0);
  lcd.print("Temp: ");

  // Initialize serial communication
  Serial.begin(115200);
}

void loop() {
  // Read the temperature sensor value
  int tempValue = analogRead(tempSensorPin);

  // Convert the analog value to temperature (assuming a specific sensor)
  float voltage = tempValue * (3.3 / 4095.0);
  float temperatureC = (voltage - 0.5) * 100.0;

  // Print the temperature to the LCD
  lcd.setCursor(6, 0);
  lcd.print(temperatureC);
  lcd.print(" C");

  // Print the temperature to the Serial Monitor
  Serial.print("Temperature: ");
  Serial.print(temperatureC);
  Serial.println(" C");

  // Wait for a second before the next reading
  delay(1000);
}

Note: The code for the other microcontrollers (USB Cable and 2-Channel Relay) is either not provided or is a default template without specific functionality. Additional code should be written and documented for these components based on the desired behavior of the circuit.