The circuit in question is designed to monitor environmental conditions and control a water pump and fans based on temperature and water level readings. It utilizes an Arduino Mega 2560 as the main microcontroller to interface with a DHT22 temperature and humidity sensor, a water level sensor, and a 2-channel relay module. The relay module controls the power to a water pump and two 120mm 12V fans. An ESP32 microcontroller is also included for potential WiFi capabilities. The system is powered by a 12V battery.
5V
pin connected to the VCC
pins of the DHT22, Water Level Sensor, and 2ch relayGND
pin connected to the GND
pins of the DHT22, Water Level Sensor, and 2ch relayD2 PWM
pin connected to the DAT
pin of the DHT22A0
pin connected to the SIG
pin of the Water Level SensorD3 PWM
pin connected to the IN1
pin of the 2ch relay (controls the water pump)D4 PWM
pin connected to the IN2
pin of the 2ch relay (controls the fans)3V3
pin connected to the 3V3
pin of the ESP32GND
pin connected to the GND
pin of the ESP32D19/RX1
pin connected to the TX0
pin of the ESP32 (for serial communication)D18/TX1
pin connected to the RX0
pin of the ESP32 (for serial communication)VCC
pin connected to the 5V
of the Arduino Mega 2560GND
pin connected to the GND
of the Arduino Mega 2560DAT
pin connected to the D2 PWM
of the Arduino Mega 2560VCC
pin connected to the 5V
of the Arduino Mega 2560GND
pin connected to the GND
of the Arduino Mega 2560SIG
pin connected to the A0
of the Arduino Mega 2560VCC
pin connected to the 5V
of the Arduino Mega 2560GND
pin connected to the GND
of the Arduino Mega 2560IN1
pin connected to the D3 PWM
of the Arduino Mega 2560IN2
pin connected to the D4 PWM
of the Arduino Mega 2560COM
pins connected to the VCC
of the 12V BatteryNO
pins connected to the VCC
of the Water Pump and one of the 120mm fansVCC
pin connected to the COM
pins of the 2ch relayGND
pin connected to the GND
pins of the Water Pump and the 120mm fansVCC
pin connected to the NO
pin of the 2ch relayGND
pin connected to the GND
of the 12V Battery12V+
pin connected to the NO
pin of the 2ch relay, and the other fan's 12V+
pin connected to the 12V+
of the first fanGND
pins connected to the GND
of the 12V Battery3V3
pin connected to the 3V3
of the Arduino Mega 2560GND
pin connected to the GND
of the Arduino Mega 2560TX0
pin connected to the D19/RX1
of the Arduino Mega 2560RX0
pin connected to the D18/TX1
of the Arduino Mega 2560#include <DHT.h>
#include <Wire.h>
#define DHTPIN 2
#define DHTTYPE DHT22
#define WATER_LEVEL_PIN A0
#define RELAY_PUMP_PIN 3
#define RELAY_FAN_PIN 4
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600);
Serial1.begin(115200); // Communication with ESP32
dht.begin();
pinMode(WATER_LEVEL_PIN, INPUT);
pinMode(RELAY_PUMP_PIN, OUTPUT);
pinMode(RELAY_FAN_PIN, OUTPUT);
digitalWrite(RELAY_PUMP_PIN, LOW);
digitalWrite(RELAY_FAN_PIN, LOW);
}
void loop() {
float temperature = dht.readTemperature();
float humidity = dht.readHumidity();
int waterLevel = analogRead(WATER_LEVEL_PIN);
// Send data to ESP32
Serial1.print("Temperature: ");
Serial1.print(temperature);
Serial1.print(" C, Humidity: ");
Serial1.print(humidity);
Serial1.print(" %, Water Level: ");
Serial1.print(waterLevel);
Serial1.println(" mm");
// Check if the temperature is below 15 degrees Celsius
if (temperature < 15.0 && waterLevel > 3) {
digitalWrite(RELAY_PUMP_PIN, HIGH); // Activate water pump
digitalWrite(RELAY_FAN_PIN, HIGH); // Activate fans
} else {
digitalWrite(RELAY_PUMP_PIN, LOW); // Deactivate water pump
digitalWrite(RELAY_FAN_PIN, LOW); // Deactivate fans
}
delay(2000); // Wait for 2 seconds before the next reading
}
#include <WiFi.h>
#include <WebServer.h>
const char* ssid = "your_SSID";
const char* password = "your_PASSWORD";
WebServer server(80);
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
Serial.println("Connected to WiFi");
server.on("/", handleRoot);
server.begin();
}
void loop() {
server.handleClient();
}
void handleRoot() {
if (Serial.available()) {
String data = Serial.readStringUntil('\n');
server.send(200, "text/plain", data);
} else {
server.send(200, "text/plain", "No data available");
}
}
(Note: The second code snippet provided for the Arduino Mega 2560 appears to be intended for the ESP32, as it includes WiFi library calls and is written in C++ which is typical for ESP32 sketches. The code snippet is similar to the ESP32 code provided, suggesting a possible duplication or mislabeling in the input data.)