Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino Mega 2560 and ESP8266 Nodemcu Based Climate Monitoring and Water Level Control System

View and Edit Project In Cirkit DesignerImage of Arduino Mega 2560 and ESP8266 Nodemcu Based Climate Monitoring and Water Level Control System

Circuit Documentation

Summary

This circuit is designed to monitor environmental conditions and control a water pump and fans based on temperature and water level readings. It uses an Arduino Mega 2560 as the main microcontroller to read data from a DHT22 temperature and humidity sensor and a water level sensor. The Arduino controls a 2-channel relay module, which in turn controls the power to a water pump and two 12V fans. The system also includes an ESP8266 NodeMCU for potential wireless communication capabilities. Power management is handled by a combination of 3.7V batteries, a lithium-ion charger, and a Battery Management System (BMS).

Component List

Wiring Details

Arduino Mega 2560

DHT22

Water Level Sensor

2-Channel Relay Module

Water Pump

120mm 12V Fans

3.7V Batteries

18650 Lithium-Ion Charger

Battery Management System (BMS)

ESP8266 NodeMCU

Documented Code

#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
}

The code is written for the Arduino Mega 2560 and is responsible for initializing the DHT22 sensor, setting up the communication with the ESP8266 NodeMCU, reading sensor data, and controlling the relay module based on the temperature and water level conditions. It sends sensor data to the ESP8266 NodeMCU for potential wireless transmission.