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.
// The ESP32 code is not provided in the input. Please ensure that the code for the ESP32 is included here.
/*
* 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.