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

Arduino Nano ESP32-Based Aquaponics Monitoring System with Battery Power

Image of Arduino Nano ESP32-Based Aquaponics Monitoring System with Battery Power

Circuit Documentation

Summary

This document provides a detailed overview of an aquaponics monitoring and control system. The system utilizes various sensors to monitor water quality parameters such as temperature, pH, Total Dissolved Solids (TDS), and Dissolved Oxygen (DO). An Arduino Nano ESP32 microcontroller processes the sensor data and controls a water pump via a relay based on the readings.

Component List

  1. AHT10

    • Description: Temperature and Humidity Sensor
    • Pins: Vcc, Gnd, SCL, SDA
  2. Buck Converter

    • Description: DC-DC Step-Down Converter
    • Pins: IN+, IN-, OUT+, OUT-
  3. Lipo Battery 2200mAH 30c

    • Description: Rechargeable Lithium Polymer Battery
    • Pins: VCC, GND
  4. 1-Channel Relay (5V 10A)

    • Description: Relay Module for Switching High Power Devices
    • Pins: NC, signal, C, power, NO, ground
  5. PH Meter

    • Description: pH Sensor for Measuring Acidity/Alkalinity
    • Pins: Signal, VCC, GND
  6. Water Pump

    • Description: Pump for Water Circulation
    • Pins: positive, negative
  7. Arduino Nano ESP32

    • Description: Microcontroller for Processing Sensor Data and Controlling Actuators
    • Pins: D12, D11, D10, D9, D8, D7, D6, D5, D4, D3, D2, GND, RST, RX0, TX1, D13, 3.3V, B0, A0, A1, A2, A3, A4, A5, A6, A7, VBUS, B1, VIN
  8. TDS Sensor

    • Description: Total Dissolved Solids Sensor for Measuring Water Quality
    • Pins: AI, GND, 5V
  9. Temperature Sensor

    • Description: Temperature Sensor for Measuring Water Temperature
    • Pins: Temp GND Black, Temp VDD Red, Temp DQ Data Yellow
  10. DO Sensor

    • Description: Dissolved Oxygen Sensor for Measuring Oxygen Levels in Water
    • Pins: Vcc, Gnd, Out

Wiring Details

AHT10

  • Vcc: Connected to Buck Converter OUT+
  • Gnd: Connected to Buck Converter OUT-
  • SCL: Connected to Arduino Nano ESP32 A5
  • SDA: Connected to Arduino Nano ESP32 A4

Buck Converter

  • IN+: Connected to Lipo Battery VCC and 1-Channel Relay C
  • IN-: Connected to Lipo Battery GND and 1-Channel Relay ground
  • OUT+: Connected to AHT10 Vcc, TDS Sensor 5V, 1-Channel Relay power, Temperature Sensor Temp VDD Red, PH Meter VCC, DO Sensor Vcc
  • OUT-: Connected to AHT10 Gnd, TDS Sensor GND, Temperature Sensor Temp GND Black, PH Meter GND, DO Sensor Gnd

Lipo Battery 2200mAH 30c

  • VCC: Connected to Buck Converter IN+ and 1-Channel Relay C
  • GND: Connected to Buck Converter IN- and 1-Channel Relay ground

1-Channel Relay (5V 10A)

  • NC: Not connected
  • signal: Connected to Arduino Nano ESP32 D8
  • C: Connected to Lipo Battery VCC and Buck Converter IN+
  • power: Connected to Buck Converter OUT+
  • NO: Connected to Water Pump positive
  • ground: Connected to Lipo Battery GND, Water Pump negative, and Buck Converter IN-

PH Meter

  • Signal: Connected to Arduino Nano ESP32 A3
  • VCC: Connected to Buck Converter OUT+
  • GND: Connected to Buck Converter OUT-

Water Pump

  • positive: Connected to 1-Channel Relay NO
  • negative: Connected to 1-Channel Relay ground

Arduino Nano ESP32

  • D8: Connected to 1-Channel Relay signal
  • D5: Connected to Temperature Sensor Temp DQ Data Yellow
  • A0: Connected to TDS Sensor AI
  • A1: Connected to DO Sensor Out
  • A3: Connected to PH Meter Signal
  • A4: Connected to AHT10 SDA
  • A5: Connected to AHT10 SCL

TDS Sensor

  • AI: Connected to Arduino Nano ESP32 A0
  • GND: Connected to Buck Converter OUT-
  • 5V: Connected to Buck Converter OUT+

Temperature Sensor

  • Temp GND Black: Connected to Buck Converter OUT-
  • Temp VDD Red: Connected to Buck Converter OUT+
  • Temp DQ Data Yellow: Connected to Arduino Nano ESP32 D5

DO Sensor

  • Vcc: Connected to Buck Converter OUT+
  • Gnd: Connected to Buck Converter OUT-
  • Out: Connected to Arduino Nano ESP32 A1

Code Documentation

#include <Wire.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <AHT10.h>
#include <DFRobot_ESP_PH.h>
#include <DFRobot_DO.h> // Added dissolved oxygen sensor library

// Pin Definitions
#define TDS_SENSOR_PIN A0
#define PH_SENSOR_PIN A3
#define DS18B20_PIN 5
#define RELAY_PIN 8
#define ONE_WIRE_BUS DS18B20_PIN
#define DO_SENSOR_PIN A1 // Added pin for dissolved oxygen sensor
#define SCL_PIN A5 // Typical SCL pin for I2C
#define SDA_PIN A4 // Typical SDA pin for I2C

// Sensor Objects
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature tempSensor(&oneWire);
AHT10 aht10;
DFRobot_ESP_PH ph;
DFRobot_DO do_sensor; // Dissolved oxygen sensor object
float tdsSensorValue = 0;
float phValue = 0;
float doValue = 0; // Dissolved oxygen value

void setup()
{
    Serial.begin(115200);

    // Initialize I2C with specific SCL and SDA pins
    Wire.begin(SDA_PIN, SCL_PIN);

    // Initialize Sensors
    tempSensor.begin();

    // AHT10 Initialization
    if (!aht10.begin())
    {
        Serial.println("AHT10 not found. Check wiring!");
    }

    // PH Sensor Initialization
    ph.begin();

    // Dissolved Oxygen Sensor Initialization
    do_sensor.begin();

    // Relay Setup
    pinMode(RELAY_PIN, OUTPUT);
    digitalWrite(RELAY_PIN, LOW);
}

void loop()
{
    // Read Temperature Sensors
    tempSensor.requestTemperatures();
    float waterTemp = tempSensor.getTempCByIndex(0);

    // Read AHT10 (Humidity and Air Temperature)
    float humidity = aht10.readHumidity();
    float airTemp = aht10.readTemperature();

    // Read TDS Sensor
    tdsSensorValue = readTDSSensor();

    // Read PH Sensor
    phValue = readPHSensor();

    // Read Dissolved Oxygen Sensor
    doValue = readDOSensor(waterTemp);

    // Print Sensor Readings
    Serial.println("--- Aquaponics Sensor Readings ---");
    Serial.print("Water Temperature: ");
    Serial.print(waterTemp);
    Serial.println(" °C");

    Serial.print("Air Temperature: ");
    Serial.print(airTemp);
    Serial.println(" °C");

    Serial.print("Humidity: ");
    Serial.print(humidity);
    Serial.println(" %");

    Serial.print("TDS Value: ");
    Serial.print(tdsSensorValue);
    Serial.println(" ppm");

    Serial.print("PH Value: ");
    Serial.print(phValue);
    Serial.println("");

    Serial.print("Dissolved Oxygen: ");
    Serial.print(doValue);
    Serial.println(" mg/L");

    // Control Relay (example: turn on if water temp is below 20°C)
    if (waterTemp < 20.0)
    {
        digitalWrite(RELAY_PIN, HIGH);
    }
    else
    {
        digitalWrite(RELAY_PIN, LOW);
    }

    delay(5000); // Read sensors every 5 seconds
}

float readTDSSensor()
{
    int sensorValue = analogRead(TDS_SENSOR_PIN);
    float voltage = sensorValue * (3.3 / 4095.0);
    float tdsValue = (133.42 * voltage * voltage * voltage - 255.86 * voltage * voltage + 857.39 * voltage) * 0.5;
    return tdsValue;
}

float readPHSensor()
{
    static unsigned long samplingTime = millis();
    static unsigned long printTime = millis();
    static float pHValue, voltage;

    if (millis