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

Arduino-Controlled Nutrient and Water Management System with ESP32-CAM and Relay

View and Edit Project In Cirkit DesignerImage of Arduino-Controlled Nutrient and Water Management System with ESP32-CAM and Relay

Circuit Documentation

Summary

This circuit is designed to monitor soil nutrient levels using an NPK Soil Sensor and control a water pump based on the sensor's readings. The system uses an Arduino UNO microcontroller to read the sensor data and activate a relay, which in turn controls the power to the water pump. The ESP32-CAM modules are included for potential camera functionality or wireless communication, although their specific roles are not defined in the provided code. The circuit is powered by a 5V supply that is distributed to the various components, and a 240V power source is used to power the water pump through the relay.

Component List

ESP32-CAM

Do Sensor (Dissolved Oxygen Sensor)

Water Pump

Arduino UNO

Relay Module 5V-30V

240V Power Source

NPK Soil Sensor

Wiring Details

ESP32-CAM

Do Sensor (Dissolved Oxygen Sensor)

Water Pump

Arduino UNO

Relay Module 5V-30V

240V Power Source

NPK Soil Sensor

Documented Code

// Pin definitions
const int npkSensorPin = A1; // NPK Soil Sensor output connected to A1
const int relayPin = 2; // Relay trigger connected to D2

// Threshold for low nutrient level
const int nutrientThreshold = 400; // Adjust this value based on your sensor's calibration

void setup() {
  // Initialize serial communication
  Serial.begin(9600);

  // Set relay pin as output
  pinMode(relayPin, OUTPUT);
  digitalWrite(relayPin, LOW); // Ensure the relay is off initially

  // Initialize sensor pin
  pinMode(npkSensorPin, INPUT);
}

void loop() {
  // Read sensor value
  int npkSensorValue = analogRead(npkSensorPin);

  // Print sensor value to the serial monitor
  Serial.print("NPK Sensor Value: ");
  Serial.println(npkSensorValue);

  // Check if the nutrient level is below the threshold
  if (npkSensorValue < nutrientThreshold) {
    // Activate the water pump
    digitalWrite(relayPin, HIGH);
    Serial.println("Low nutrient detected! Pump activated.");
  } else {
    // Deactivate the water pump
    digitalWrite(relayPin, LOW);
    Serial.println("Nutrient level is normal. Pump deactivated.");
  }

  // Wait for 2 minutes before the next loop
  delay(120000); // 120,000 milliseconds = 2 minutes
}

This code is designed to run on the Arduino UNO microcontroller. It reads the value from the NPK Soil Sensor connected to analog pin A1 and compares it to a predefined threshold. If the nutrient level is below the threshold, it activates a relay which powers the water pump. The relay is controlled via digital pin D2. The system pauses for two minutes between readings.