Aquaponics fish tank monitor
Build it step by step
0 of 8 doneTest the temperature probe
Read it in the tank water.
Calibrate the pH probe
Note the raw reading in two buffer solutions.
Fill in the numbers
Put the raw values in RAW_A and RAW_B.
Fit the float switch
Place it at the minimum safe level.
Set up the broker
Use a broker on your network and fill in the placeholders.
Upload
Check the messages arrive on tank/readings.
Add a dashboard
Use any MQTT dashboard app on your phone.
Test the alert
Lift the float and see tank/alert.
How do you build an aquaponics fish tank monitor?
Water temperature, pH and water level in an aquaponics tank go to a phone dashboard so fish problems show up early. You need ESP32 DevKit V1, DS18B20 waterproof probe, Resistor 4.7 kΩ, pH sensor kit (analog), Float switch (vertical), Resistor 10 kΩ × 2 and SSD1306 OLED Display. It takes 8 steps and about 180 minutes.
- Level
- Intermediate
- Time
- About 180 min
- Parts
- 7
Parts list
- Development BoardsBuyESP32 DevKit V1 × 1
- SensorsBuy
- PassivesBuyResistor 4.7 kΩ × 1
- SensorsBuy
- SensorsBuy
- PassivesBuyResistor 10 kΩ × 2
- DisplaysBuy
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| DS18B20 red and black | ESP32 3V3 and GND | Power |
| DS18B20 yellow data | ESP32 GPIO4 and 4.7 kΩ resistor to 3V3 | Water temperature |
| pH board VCC and GND | ESP32 VIN (5 V) and GND | Power |
| pH board Po output | 10 kΩ resistor to ESP32 GPIO34, and a second 10 kΩ from GPIO34 to GND | Divider halves the 5 V signal for the ESP32 |
| Float switch | ESP32 GPIO13 and GND | Closed when the water level is high enough |
| OLED VCC and GND | ESP32 3V3 and GND | Power |
| OLED SDA and SCL | ESP32 GPIO21 and GPIO22 | I2C |
Code
The pH board's output can reach 5 V, which would harm the ESP32, so the two 10 kΩ resistors halve it; the two-point calibration absorbs this, so you need not change the maths. Calibrate with two buffer solutions (for example pH 4.00 and 6.86): rinse the probe, place it in each, wait for a steady reading, note the raw value that the sketch prints, and put the two numbers in the code. The values in the sketch are placeholders. Probes need regular recalibration and must be kept wet in storage solution. The sketch sends plain MQTT to a broker on your own network at the placeholder address; do not expose that broker to the internet without a password and encryption, and keep the Wi-Fi details out of shared code. The float switch shows when the tank level drops. Never place the electronics where they can fall into the water. Arduino IDE with the ESP32 boards package, board "ESP32 Dev Module".
Runs on a virtual ESP32 Dev Module in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).
// Libraries: OneWire, DallasTemperature, PubSubClient, Adafruit SSD1306 and GFX.
#include <WiFi.h>
#include <PubSubClient.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
const char* WIFI_SSID = "YOUR_WIFI_NAME";
const char* WIFI_PASS = "YOUR_WIFI_PASSWORD";
const char* MQTT_HOST = "YOUR_BROKER_ADDRESS"; // for example a Mosquitto broker on your own network
const int MQTT_PORT = 1883;
// pH calibration: raw ADC readings (0 to 4095) in two buffer solutions, entered after calibrating
const float PH_A = 4.00, RAW_A = 2200; // placeholder values, replace with your own readings
const float PH_B = 6.86, RAW_B = 1750;
OneWire ow(4);
DallasTemperature ds(&ow);
Adafruit_SSD1306 oled(128, 64, &Wire, -1);
WiFiClient net;
PubSubClient mqtt(net);
const byte PH_PIN = 34, FLOAT_PIN = 13;
float readPH() {
long s = 0;
for (int i = 0; i < 64; i++) { s += analogRead(PH_PIN); delay(5); }
float raw = s / 64.0;
return PH_A + (raw - RAW_A) * (PH_B - PH_A) / (RAW_B - RAW_A); // straight line through the two points
}
void connectAll() {
if (WiFi.status() != WL_CONNECTED) { WiFi.begin(WIFI_SSID, WIFI_PASS); while (WiFi.status() != WL_CONNECTED) delay(300); }
while (!mqtt.connected()) { if (!mqtt.connect("tank-monitor")) delay(2000); }
}
void setup() {
Serial.begin(115200);
pinMode(FLOAT_PIN, INPUT_PULLUP);
ds.begin();
Wire.begin(21, 22);
oled.begin(SSD1306_SWITCHCAPVCC, 0x3C);
oled.setTextColor(WHITE);
mqtt.setServer(MQTT_HOST, MQTT_PORT);
}
void loop() {
connectAll();
ds.requestTemperatures();
float t = ds.getTempCByIndex(0), ph = readPH();
bool levelOk = (digitalRead(FLOAT_PIN) == LOW);
bool bad = t < 24 || t > 30 || ph < 6.8 || ph > 7.5 || !levelOk;
char msg[96];
snprintf(msg, sizeof(msg), "{\"temp\":%.1f,\"ph\":%.2f,\"level_ok\":%d}", t, ph, levelOk);
mqtt.publish("tank/readings", msg);
if (bad) mqtt.publish("tank/alert", msg);
oled.clearDisplay(); oled.setTextSize(1);
oled.setCursor(0, 0); oled.print("Temp "); oled.print(t, 1); oled.print(" C");
oled.setCursor(0, 14); oled.print("pH "); oled.print(ph, 2);
oled.setCursor(0, 28); oled.print("Level "); oled.print(levelOk ? "ok" : "LOW");
oled.setCursor(0, 48); oled.print(bad ? "CHECK THE TANK" : "All ok");
oled.display();
mqtt.loop();
delay(300000); // every 5 minutes
}Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| Buffer pH 6.86 | Reads near 6.86 |
| Tank temperature | Within about 1 degree of a reference thermometer |
| Float lifted | Level LOW and an alert |
| Every 5 minutes | New message on the dashboard |
If it does not work
pH reads nonsense
Recalibrate and check the divider resistors.
No MQTT messages
Check the broker address, Wi-Fi and port.
Temperature reads -127
Check the probe wiring and pull-up.
OLED blank
Check the I2C pins and address 0x3C.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the aquaponics fish tank monitor?
ESP32 DevKit V1, DS18B20 waterproof probe, Resistor 4.7 kΩ, pH sensor kit (analog), Float switch (vertical), Resistor 10 kΩ × 2 and SSD1306 OLED Display.
How long does the aquaponics fish tank monitor take to build?
About 180 minutes for a intermediate maker, in 8 steps.
How do I know the aquaponics fish tank monitor works?
Buffer pH 6.86: Reads near 6.86. Tank temperature: Within about 1 degree of a reference thermometer. Float lifted: Level LOW and an alert.
pH reads nonsense: what should I check?
Recalibrate and check the divider resistors.
No MQTT messages: what should I check?
Check the broker address, Wi-Fi and port.
Temperature reads -127: what should I check?
Check the probe wiring and pull-up.
OLED blank: what should I check?
Check the I2C pins and address 0x3C.
