How to Monitor Aquarium Water Quality Using Arduino: DS18B20 Temperature Sensors, Turbidity Monitoring, Automatic Heating and Feeding

Smart fish tank design---warm nest - iNEWS
Gikfun Water Quality Sensor Bundle: Waterproof DS18B20 Temperature Pro– AusPower Australia

Arduino Temperature Controller : 3 Steps - Instructables

9

SEO title: Arduino Aquarium Water Quality Monitoring System: Temperature, Turbidity and Automatic Feeding

URL slug: arduino-aquarium-water-quality-monitoring-system

Meta description: Learn how to build an Arduino aquarium water quality monitoring system using waterproof DS18B20 sensors, turbidity monitoring, automatic heater control and fish feeding.

Focus keyphrase: Arduino aquarium water quality monitoring system

SEO keywords: Arduino aquarium monitor, DS18B20 aquarium temperature sensor, aquarium turbidity sensor, automatic aquarium heater controller, Arduino automatic fish feeder, aquarium water quality monitoring system, DIY smart aquarium, Arduino fish tank automation, aquarium IoT project, STEM science project.

1. Introduction

Maintaining good aquarium water quality is essential for healthy fish, aquatic plants and other organisms. Sudden temperature changes, suspended particles, excessive feeding and poor maintenance can affect fish health and aquarium stability.

An Arduino aquarium water quality monitoring system combines temperature sensors, a turbidity sensor and automated control mechanisms to monitor selected water conditions and assist with routine aquarium maintenance.

In this project, a waterproof DS18B20 temperature sensor measures the aquarium’s water temperature, while a turbidity sensor estimates the amount of light scattering caused by suspended particles. An Arduino processes the readings and can control a heater through a suitable relay or temperature controller. A servo motor can operate an automatic feeder at scheduled intervals.

The system can also use an LCD to display measurements and warning messages.

What this project does

Temperature monitoring

Measures water temperature and identifies readings outside the selected range.

Turbidity monitoring

Estimates water cloudiness and signals when inspection or maintenance may be necessary.

Automatic heater control

Regulates a suitable heater according to the aquarium’s temperature requirements.

Scheduled fish feeding

Operates a small servo-driven feeder at programmed times, dispensing a measured portion.

Important: Temperature and turbidity alone do not establish complete aquarium water quality. Ammonia, nitrite, nitrate, pH and dissolved oxygen may also need to be monitored, depending on the aquarium and species.

2. How the system works

Sensors in the aquarium

Waterproof DS18B20 + turbidity sensor

Arduino Uno

Reads sensor values and applies programmed rules.

Temperature control

Controls the heater with a suitable deadband and safety checks.

Feeder control

Operates a servo mechanism at scheduled feeding times.

LCD and alarms

Display temperature, turbidity readings and system warnings.

The Arduino acts as the controller. The sensors supply measurements, the program evaluates the readings, and the outputs activate the relevant control mechanisms.

3. Materials and components required

ARDUINO® Uno Rev3

        – Robot Pi Shop

DFRobot Gravity - Flüssigkeitstrübungssensor Botland - Robotikgeschäft

5

ComponentQuantityPurpose
Arduino Uno1Main controller
Waterproof DS18B20 sensor1–2Measures aquarium water temperature
4.7 kΩ resistor1 per data busPull-up resistor for DS18B20 data
Turbidity sensor and module1Measures an optical signal related to water cloudiness
16×2 LCD with I2C1Displays measurements and warnings
Small servo motor1Operates the feeder mechanism
Food container and dispensing wheel1 setStores and releases fish food
Suitable relay module or certified temperature controller1Controls the heater in an appropriately designed system
Low-voltage demonstration lamp1Safely simulates heater operation during initial tests
Buzzer and LEDsOptionalProvide visual and audible alerts
Breadboard and jumper wires1 setPrototyping
Regulated 5 V power supply1Powers the Arduino and suitable peripherals
Separate servo power supplyAs requiredPrevents motor current spikes from resetting the controller

Estimated budget in Kenya

These are indicative planning estimates, not live supplier quotations.

ItemEstimated cost (KES)
Arduino Uno-compatible board800–1,500
Waterproof DS18B20 probe150–400
Turbidity sensor module500–1,200
Servo motor150–350
LCD I2C display350–700
Resistors, wires and breadboard250–600
Relay module and low-voltage test load200–500
Feeder container and mounting materials100–300
Power supply300–700
Estimated total2,800–6,250

A suitable aquarium heater, certified temperature controller, waterproof enclosure or additional water-quality sensors may increase the final cost.

4. Circuit diagram and Arduino pin connections

An Integrated Smart Pond Water Quality Monitoring and Fish Farming Recommendation Aquabot System | MDPI

mdpi.com

Use the following connections as the basis for the prototype.

ComponentPinArduino connection
DS18B20VCC5 V
DS18B20GNDGND
DS18B20DATAD2
4.7 kΩ resistorOne endDATA/D2
4.7 kΩ resistorOther end5 V
Turbidity moduleAOA0
Turbidity moduleVCC/GNDAccording to module specifications
Servo motorSignalD9
Servo motorPower/GNDSuitable supply and common ground
I2C LCDSDAA4
I2C LCDSCLA5
Relay moduleIND8
Relay moduleVCC/GNDAs specified by its manufacturer

Important wiring considerations

  • The DS18B20 uses a digital one-wire communication bus. The 4.7 kΩ pull-up resistor is normally connected between the data line and its supply.
  • Check the turbidity module’s output voltage before connecting its analogue output to A0. Never allow an input to exceed the Arduino board’s permitted voltage.
  • Power the servo from an adequately rated external supply when necessary. Connect the supply ground to Arduino ground for a shared signal reference.
  • Verify the relay’s active-high or active-low behaviour before using it.
  • Keep the Arduino, breadboard, connectors and mains electricity completely separated from aquarium water.

Heater safety: For the school prototype, use a low-voltage lamp to simulate heater operation. In a real aquarium, use a properly rated aquarium heater and a suitable independent temperature controller or certified control arrangement. Do not rely on a hobby Arduino and relay as the sole protection against overheating. Any mains-powered installation must use suitable enclosures, electrical protection and qualified installation.

5. Step-by-step construction procedure

Water Temperature Monitoring - Shelly Europe

Step 1: Install the temperature sensor

Position the waterproof probe in an area with representative water circulation, away from direct contact with the heater. Connect its data line to D2 and install the pull-up resistor.

16x2 LCD | Circuit Digest

Step 2: Install the turbidity sensor

Mount the probe according to its manufacturer’s instructions. Some common modules are not designed for continuous immersion, so keep the electronics and non-waterproof connections dry. Provide a consistent measurement position.

Circuit design LCD I2C - Tinkercad

Step 3: Connect the display

Wire the LCD’s I2C interface to A4 and A5. The display can show the measured temperature, raw turbidity reading and any sensor-fault warnings.

Small Fish Feeder (Rotary, Single Servo, Arduino) by robotgeek - Thingiverse

Step 4: Build the automatic feeder

Attach a servo to a small dispensing gate or rotating wheel. Test it with dry fish-food pellets before installing it above the aquarium. Adjust the opening to deliver a measured portion without jamming.

Control a Bulb using Relay Module and Touch Sensor
 – REES52

Step 5: Test the heater-control output

Initially connect the relay to a low-voltage test lamp. Verify that the output switches at the programmed temperature thresholds and returns to the safe state when a sensor fault occurs.

6. Arduino code for aquarium monitoring and automation

This example integrates the DS18B20, turbidity module, relay output and servo feeder. It uses a demonstration temperature range of 24–26 °C, which must be adjusted to suit the actual aquarium species and setup.

The example feeds at fixed intervals measured from startup. For a dependable aquarium installation, replace this with a real-time clock (RTC) and defined feeding times, so a power interruption does not reset the daily schedule.

Required Arduino libraries

Install these libraries using the Arduino IDE Library Manager:

  • OneWire
  • DallasTemperature
  • Servo
  • LiquidCrystal_I2C

The code assumes a common I2C LCD address of 0x27, an active-low relay and a servo feeder that dispenses food when moved to its open position. Check the hardware before use.


#include <OneWire.h>
#include <DallasTemperature.h>
#include <Servo.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

// Pin assignments
const byte TEMP_PIN = 2;
const byte TURBIDITY_PIN = A0;
const byte RELAY_PIN = 8;
const byte SERVO_PIN = 9;

// Adjust for the relay module
const byte RELAY_ON = LOW;
const byte RELAY_OFF = HIGH;

// Example setpoints: adjust for fish species
const float HEAT_ON_TEMP = 24.0;
const float HEAT_OFF_TEMP = 26.0;

// Demonstration turbidity threshold.
// Calibrate with the actual sensor and water samples.
const int TURBIDITY_THRESHOLD = 500;

// Feeder positions: calibrate the mechanism
const int FEED_CLOSED = 10;
const int FEED_OPEN = 90;

// Example interval: 8 hours after startup
const unsigned long FEED_INTERVAL = 8UL * 60UL * 60UL * 1000UL;
const unsigned long FEED_OPEN_TIME = 800;

OneWire oneWire(TEMP_PIN);
DallasTemperature tempSensor(&oneWire);
LiquidCrystal_I2C lcd(0x27, 16, 2);
Servo feeder;

bool heaterOn = false;
unsigned long lastFeedTime = 0;
unsigned long lastDisplayTime = 0;

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

  pinMode(RELAY_PIN, OUTPUT);
  digitalWrite(RELAY_PIN, RELAY_OFF);

  tempSensor.begin();

  lcd.init();
  lcd.backlight();

  feeder.attach(SERVO_PIN);
  feeder.write(FEED_CLOSED);

  // Begin feeding interval after startup.
  lastFeedTime = millis();

  lcd.setCursor(0, 0);
  lcd.print("Aquarium Monitor");
  lcd.setCursor(0, 1);
  lcd.print("Initialising...");
  delay(1500);
}

void loop() {
  tempSensor.requestTemperatures();
  float tempC = tempSensor.getTempCByIndex(0);

  int turbidity = analogRead(TURBIDITY_PIN);

  // DS18B20 disconnect/error check
  bool tempValid =
      tempC != DEVICE_DISCONNECTED_C &&
      tempC >= -10.0 &&
      tempC <= 60.0;

  // Fail safe: turn off heater if temperature is invalid.
  if (!tempValid) {
    heaterOn = false;
    digitalWrite(RELAY_PIN, RELAY_OFF);
  } else {
    // Hysteresis avoids rapid relay switching.
    if (tempC <= HEAT_ON_TEMP) {
      heaterOn = true;
    } else if (tempC >= HEAT_OFF_TEMP) {
      heaterOn = false;
    }

    digitalWrite(
      RELAY_PIN,
      heaterOn ? RELAY_ON : RELAY_OFF
    );
  }

  // Print data for calibration and testing.
  Serial.print("Temperature: ");
  if (tempValid) {
    Serial.print(tempC);
    Serial.print(" C");
  } else {
    Serial.print("SENSOR ERROR");
  }

  Serial.print(" | Turbidity raw: ");
  Serial.println(turbidity);

  // Display sensor readings and faults.
  if (millis() - lastDisplayTime >= 1000) {
    lastDisplayTime = millis();

    lcd.setCursor(0, 0);
    if (tempValid) {
      lcd.print("Temp: ");
      lcd.print(tempC, 1);
      lcd.print((char)223);
      lcd.print("C   ");
    } else {
      lcd.print("TEMP SENSOR ERR ");
    }

    lcd.setCursor(0, 1);
    if (turbidity >= TURBIDITY_THRESHOLD) {
      lcd.print("Check water     ");
    } else {
      lcd.print("Turb:");
      lcd.print(turbidity);
      lcd.print("       ");
    }
  }

  // Scheduled feeder: interval from startup.
  if (millis() - lastFeedTime >= FEED_INTERVAL) {
    feeder.write(FEED_OPEN);
    delay(FEED_OPEN_TIME);
    feeder.write(FEED_CLOSED);

    lastFeedTime = millis();
  }

  delay(500);
}

Code limitations to address before deployment

This is a teaching prototype, not a complete unattended aquarium controller.

  • The temperature sensor fault check switches the heater off, but a real system also needs independent over-temperature protection and a suitable heater safety arrangement.
  • The turbidity threshold is an arbitrary raw analogue value. It must be calibrated for the particular sensor and is not a universal measure of water cleanliness.
  • The feeder interval starts when the Arduino starts. Use an RTC and persistent scheduling for reliable daily feeding.
  • The servo movement time and angles depend on the feeder design. Verify that it dispenses the correct portion without jamming.
  • The program does not yet provide a complete sensor-fault response for the turbidity module or a low-food alarm.

7. How to calibrate the sensors

A. Calibrating the DS18B20 temperature sensor

The DS18B20 reports temperature digitally, typically with a resolution configurable up to 12 bits. To verify its accuracy:

  1. Place the probe in a stable water bath alongside a reliable reference thermometer.
  2. Allow both readings to stabilise.
  3. Record the Arduino reading and reference temperature.
  4. Repeat at several temperatures within the intended operating range.
  5. Investigate any consistent difference and replace a faulty probe if necessary.

Do not assume that the programmed temperature limits suit every fish species. Tropical freshwater fish, cold-water species and marine aquariums can have different temperature requirements.

B. Calibrating the turbidity sensor

We've Got A New Toy! - Analog Turbidity Sensor (SEN0189) - Mar2016 | DigiKey

digikey.com

A turbidity sensor measures changes in light transmission or scattering. Its output depends on the sensor design, water composition, ambient light and the characteristics of suspended particles.

For a basic calibration experiment:

  1. Collect a sample of clear aquarium water.
  2. Record the raw analogue reading several times.
  3. Prepare controlled samples with increasing concentrations of a safe, non-toxic suspended material in separate test containers.
  4. Record the readings using the same probe position, lighting and sample volume.
  5. Compare the readings and establish an appropriate threshold for your particular module.

Do not introduce test particles into the aquarium itself. For accurate turbidity measurements, use a suitable calibrated reference instrument and a method appropriate to the sensor’s design.

Important: The direction of the analogue reading varies between sensor modules. A higher raw value does not universally mean cleaner or dirtier water. Establish the relationship experimentally before using the threshold in an automated alarm.

8. How to test the automatic fish feeder

The feeder should deliver a consistent, suitable quantity of food without releasing too much at once.

Small simple fish feeder by epatel - Thingiverse

thingiverse.com

Follow this testing procedure:

  1. Fill the feeder with dry pellets of the intended size.
  2. Run the servo through its closed and open positions.
  3. Collect and weigh the food released during each dispensing cycle.
  4. Repeat at least ten times and calculate the average portion.
  5. Adjust the dispensing gate or wheel until the portions are consistent.
  6. Test for jams and verify that food cannot continuously fall through the opening.

Use the fish species’ feeding requirements to determine portion size and frequency. Automation should not replace observation of the fish, and the feeder should not continue dispensing if its mechanism becomes stuck.

For improved reliability, add a real-time clock module, a manual feeding button, a low-food sensor and a way to verify that a feeding cycle has completed.

9. Data collection and experimental investigation

For a school science project, collect evidence showing how well the system monitors temperature and responds to changing water conditions.

Sample data-recording table

Record real measurements during testing; the table below is a blank template.

TimeReference temperature (°C)DS18B20 reading (°C)Turbidity raw readingHeater stateFeeder event
08:00—————
10:00—————
12:00—————
14:00—————
16:00—————

Suggested research questions

  • How accurately does the DS18B20 measure aquarium temperature compared with a reference thermometer?
  • How does turbidity sensor output change as the concentration of suspended particles increases?
  • How consistently does the automatic feeder dispense a fixed portion of fish food?
  • How effectively does temperature hysteresis reduce unnecessary heater switching?

Performance indicators

You can calculate the absolute temperature error:

\[ E=|T_{\text{Arduino}}-T_{\text{reference}}| \]

You can also calculate the mean absolute error across several readings:

\[ MAE=\frac{\sum_{i=1}^{n}|T_i-R_i|}{n} \]

Here, \(T_i\) represents the Arduino temperature reading, \(R_i\) the reference thermometer reading, and \(n\) the number of paired measurements.

For the feeder, measure the mass of food dispensed per cycle and calculate the mean and variation across repeated trials.

These measurements help establish whether the project works reliably rather than simply showing that its components can be connected.

10. How to Fix Common Arduino Upload Errors

ProblemLikely causeSolution
OneWire.h: No such fileOneWire library is missingInstall the OneWire library
DallasTemperature.h: No such fileTemperature library is missingInstall DallasTemperature
Servo.h: No such fileServo library is unavailable for the selected environmentInstall a compatible Servo library and select the correct board
DS18B20 reads -127°CProbe disconnected, wiring error or communication failureCheck VCC, GND, data pin and pull-up resistor
Temperature reads 85°C unexpectedlySensor startup/default reading or incomplete measurementCheck sensor initialisation and wait for a valid conversion
LCD displays no textIncorrect I2C address or contrastCheck the address and adjust contrast
Arduino resets when the servo movesInsufficient power or voltage dropUse an adequately rated separate servo supply
Heater relay switches repeatedlyIncorrect thresholds or no hysteresisUse separate switch-on and switch-off temperatures
Turbidity reading fluctuatesAmbient light, bubbles or inconsistent probe positioningShield the sensor from ambient light and standardise sample placement
Feeder releases too much foodIncorrect servo angle or dispenser geometryAdjust the gate and measure portions repeatedly

11. Safety and maintenance considerations

  • Keep all mains-powered equipment away from water and use appropriate electrical protection.
  • Use drip loops on cables entering electrical equipment.
  • Inspect waterproof probes and their cable seals regularly.
  • Keep non-waterproof turbidity electronics outside the aquarium.
  • Do not allow the feeder to drop food continuously if the Arduino resets.
  • Use an independent heater thermostat and thermal cut-out suitable for aquarium use.
  • Check ammonia, nitrite, nitrate and pH with appropriate tests; a turbidity sensor cannot detect all dangerous water conditions.
  • Verify water conditions and fish behaviour manually, particularly after maintenance or a power interruption.

12. Future improvements

Smart fish tank design---warm nest - iNEWS
Machine Learning on Low-Cost Edge Devices for Real-Time Water Quality Prediction in Tilapia Aquaculture | MDPI

Real-Time Water Quality Assessment via IoT: Monitoring pH, TDS, Temperature, and Turbidity | IIETA

11

The system can be expanded into a smart aquarium monitoring platform by adding:

  • pH monitoring to track acidity and alkalinity.
  • Ammonia and nitrite testing using suitable validated sensors or test methods.
  • Dissolved oxygen monitoring to assess oxygen availability.
  • ESP32 Wi-Fi connectivity for remote dashboards and notifications.
  • RTC-based scheduling for accurate feeding times.
  • Data logging to identify long-term temperature and water-quality trends.
  • Independent heater protection to reduce the risk of overheating if the controller fails.

For advanced projects, compare the performance of the automated system with manual measurements over several weeks and evaluate its accuracy, reliability, cost and maintenance requirements.

13. Conclusion

The Arduino Aquarium Water Quality Monitoring System demonstrates how sensors, microcontrollers and automated mechanisms can improve routine aquarium management. The DS18B20 measures water temperature, the turbidity module monitors changes in water cloudiness, the relay interface supports temperature-control experiments, and the servo motor operates a scheduled fish feeder.

The project’s scientific value comes from collecting reliable measurements, calibrating sensors, testing automated responses and identifying limitations. With additional pH, ammonia, nitrite and dissolved oxygen monitoring, the prototype can be developed into a more comprehensive aquarium management system

Total Views: 1
  • mbeva

    Dominic Mbeva is a science teacher, experienced researcher, innovator, and creative technologist with expertise in STEM education, digital media, and scientific research. As a Kenya Science and Engineering Fair (KSEF) advisor and projects manager, he mentors young scientists, guiding them in developing award-winning innovations. He is also an IC Technorat, leading advancements in science and technology. Beyond education, Dominic is a skilled photographer and video editor, using visual storytelling to make science more engaging. His philosophy, “If you take care of minutes, hours will take care of themselves,” reflects his belief in consistent effort, strategic thinking, and innovation to drive success in both research and creativity.

    Related Posts

    How to Build a Vehicle Driver Alcohol Detection and Engine Locking System Using Arduino

    Design and Evaluation of an Arduino-Based Driver Alcohol Detection and Ignition Interlock Prototype. 8 A Vehicle Driver Alcohol Detection and Engine Locking System is a road-safety engineering project designed to…

    Read more

    How to Build an Automated Green Environmental Monitoring System for Greenhouses

    Meta description: Learn how to build an automated greenhouse monitoring system using Arduino or ESP32 to measure temperature, humidity, soil moisture, light, and CO₂, with sensor wiring, code, costs, and…

    Read more

    Leave a Reply

    Your email address will not be published. Required fields are marked *