Arduino Hydroponics System: Pump, TDS/EC, pH and Grow Light
Arduino hydroponics system: pump timing, TDS/EC and pH monitoring, water temperature, grow light, an EC-pH table per plant and remote monitoring via ESP32.
An Arduino hydroponics system automates a setup that grows plants in a nutrient solution instead of soil. In hydroponics everything the plant needs is in the water, so the secret to success is circulating the water at the right time and keeping the solution's EC (nutrient strength), pH and temperature in the right range. The Arduino measures these values constantly, switches the pump and grow light on and off on time and warns you when something goes wrong.
In this article you'll learn the hydroponic methods and which pump timing each one needs, how to track the nutrient solution with TDS/EC and pH sensors, and how to control water temperature and the grow light. You'll find EC and pH ranges per plant in a table, build the logic for a nutrient warning, write a complete controller sketch for the Arduino Uno and monitor the system from your phone with an ESP32.

What is a hydroponic system? Which method should you choose?
Hydroponics is a way of growing in which the roots are fed with water containing dissolved mineral nutrients instead of soil. With no soil there are few weeds and soil-borne diseases, water use is far lower than with conventional irrigation, and leafy greens such as lettuce are ready to harvest in 4–6 weeks. Four methods are most common at home. In DWC (deep water culture), the roots hang into a constantly aerated nutrient tank; here you need an air pump running 24 hours instead of a water pump. In NFT (nutrient film technique), a thin film of nutrient flows through sloped channels; the roots can dry out, so the pump runs continuously or at short intervals. In ebb and flow, a tray is flooded and drained at set intervals, and this is where the Arduino's timing helps most. Drip irrigation gives timed drops to a growing medium such as perlite or coco coir.
| Method | How it works | Pump timing | Suitable plants |
|---|---|---|---|
| DWC (deep water culture) | Roots sit in an aerated tank | Air pump on 24 hours | Lettuce, basil, spinach |
| NFT (nutrient film) | Thin nutrient flow in a sloped channel | Continuous or 15 min on / 15 min off | Lettuce, strawberries, herbs |
| Ebb and flow | Tray floods, then drains back to the tank | Flood 15 min, 4–6 times a day | Peppers, tomatoes, flowers |
| Drip irrigation | Timed drops onto the medium | 1–5 min, 4–10 times a day | Tomatoes, cucumbers, large plants |
| Kratky | Passive tank, no pump | No pump needed | Lettuce, herbs (beginners) |
System parts and wiring
The example system in this article is designed for a small NFT or ebb and flow setup, with an Arduino Uno as the brain. A Gravity-type TDS sensor measures nutrient strength, a pH sensor with a PH-4502C module measures acidity, and a waterproof DS18B20 measures water temperature. A float level switch at the bottom of the tank stops the pump from running dry when the water drops. A two-channel relay module drives the pump and grow light, and a DS3231 clock module makes the light come on at the right time of day. An LED or a buzzer is enough for warnings.
| Component | Arduino Uno | ESP32 | Note |
|---|---|---|---|
| pH module Po | A0 | GPIO 34 (through a 10 kΩ + 20 kΩ divider) | Module powered from 5 V |
| TDS module A | A1 | GPIO 35 | Works on 3.3–5 V |
| TDS module VCC | D8 (powered from a pin) | GPIO 27 | Switched off while reading pH |
| DS18B20 data | D2 + 4.7 kΩ pull-up | GPIO 4 + 4.7 kΩ pull-up | Waterproof probe |
| Float switch | D4 (INPUT_PULLUP) | GPIO 13 (INPUT_PULLUP) | Contact closed when water is present |
| Warning LED / buzzer | D5 | Web page | On during an alarm |
| Light relay | D6 | GPIO 25 | Relay modules usually switch on with LOW |
| Pump relay | D7 | GPIO 26 | Prefer a 12 V pump |
| DS3231 SDA / SCL | A4 / A5 | Not needed (NTP time) | For the light schedule |
Water pump timing

Time the pump with millis(), not delay(); delay() locks the Arduino for minutes, and during that time you can't read the sensors or raise an alarm. The cycle in the code runs the pump for 15 minutes and stops it for 45, a good starting point for ebb and flow. If you built an NFT system, lower PUMP_OFF_MS to 15 minutes or keep the pump on continuously, because roots in an NFT channel start to wilt if they stay dry for more than 30–60 minutes. The float switch sits at the tank's minimum water level; when the water falls below it, the code stops the pump no matter what the timer says. Submersible pumps are cooled by water and overheat and fail within minutes if they run dry. A small mini water pump draws 100–300 mA; you can drive it with a relay module or a logic-level MOSFET, but never power it straight from an Arduino pin.
Monitoring TDS/EC and pH
EC (electrical conductivity) shows the amount of nutrient salts dissolved in the water and is measured in mS/cm or µS/cm. TDS is an estimate of the same measurement in ppm; most meters use the 500 scale: ppm = EC (µS/cm) × 0.5. Some European and Australian meters use the 700 scale, so converting to EC is the safest way to compare ppm values you find online. Conductivity rises by about 2% per degree, so the reading is corrected to 25 °C; the code uses the DS18B20 temperature for this. The cheap Gravity TDS sensor tops out at about 1000 ppm, or 2.0 mS/cm. That's enough for leafy greens, but for plants such as tomatoes that want 3–5 mS/cm the reading saturates and you need an industrial EC probe with K=1. Calibrate the sensor with a 1413 µS/cm calibration solution. On the pH side, the PH-4502C module gives about 2.5 V around pH 7 and the voltage rises as acidity increases. Calibrate the probe at two points with pH 4.00 and 6.86 buffers and write the measured voltages into V_ACID and V_NEUTRAL in the code. A pH probe is ruined if it dries out; when it's not in use, keep it in its cap with KCl storage solution and replace it every 1–2 years.
EC and pH ranges by plant
| Plant | EC (mS/cm) | TDS (ppm, 500 scale) | pH | Note |
|---|---|---|---|---|
| Lettuce | 0.8–1.2 | 400–600 | 5.5–6.5 | The easiest for beginners |
| Basil | 1.0–1.6 | 500–800 | 5.5–6.5 | Pinch the tips for bushy growth |
| Spinach | 1.8–2.3 | 900–1150 | 6.0–7.0 | Likes cool water |
| Mint | 2.0–2.4 | 1000–1200 | 5.5–6.0 | Spreads fast, give it its own channel |
| Strawberry | 1.8–2.2 | 900–1100 | 5.5–6.2 | Needs potassium while fruiting |
| Pepper | 0.8–1.8 | 400–900 | 6.0–6.5 | Raise EC when flowering |
| Cucumber | 1.7–2.5 | 850–1250 | 5.5–6.0 | Drinks a lot, watch the level |
| Tomato | 2.0–5.0 | 1000–2500 | 5.5–6.5 | Gravity TDS is not enough, use an EC probe |
Controlling water temperature and the grow light
Place the DS18B20 probe in the middle of the tank, away from the pump outlet; the pump's own heat and the flow can skew the reading. If the water gets too warm the code raises a warning, and you can shade the tank, add an air stone to boost oxygen or fit an aquarium chiller. In winter you can build the same thermostat logic with an aquarium heater and a relay. Two things matter with a grow light: the daily light period (photoperiod) and the total amount of light the plant gets in a day, the DLI (daily light integral). DLI = PPFD × hours × 3600 / 1,000,000, expressed in mol/m²/day. For example, an LED panel at 250 µmol/m²/s running for 16 hours gives 250 × 16 × 3600 / 1,000,000 ≈ 14.4 mol/m²/day, ideal for lettuce. The code switches the light on between 06:00 and 22:00 based on the time read from the DS3231. If you want the light to fade in and out, drive a 12 V LED strip with PWM through a MOSFET.
| Plant group | Light period | Target DLI (mol/m²/day) | Example |
|---|---|---|---|
| Seedlings and cuttings | 16–18 hours | 6–10 | Germination tray |
| Leafy greens | 14–16 hours | 12–17 | Lettuce, spinach, arugula |
| Herbs | 14–16 hours | 12–18 | Basil, mint, parsley |
| Fruiting vegetables | 12–16 hours | 20–30 | Tomatoes, peppers, strawberries |
Arduino Uno hydroponics controller code
- Install the OneWire, DallasTemperature and RTClib libraries from the Library Manager.
- Dip the pH probe in the 6.86 and 4.00 buffer solutions in turn, measure the Po voltage in each and write them into V_NEUTRAL and V_ACID.
- Pick EC_MIN, EC_MAX, PH_MIN and PH_MAX for your plant from the table.
- Set the pump times for your method: 15/45 minutes for ebb and flow, 15/15 for NFT.
- Upload the code; on first start the DS3231 clock is set to the compile time.
- Open the Serial Monitor at 9600 baud and watch the values and alarm lines every 10 seconds.
1// Arduino hidroponik kontrol: pompa, ışık, EC, pH, su sıcaklığı / Arduino hydroponics controller: pump, light, EC, pH, water temperature
2#include <OneWire.h>
3#include <DallasTemperature.h>
4#include <RTClib.h>
5
6const byte PH_PIN = A0; // PH-4502C Po çıkışı / Po output
7const byte TDS_PIN = A1; // TDS modülü A çıkışı / TDS module A output
8const byte ONE_WIRE_PIN = 2; // DS18B20 veri, 4,7 kΩ pull-up / DS18B20 data, 4.7 kΩ pull-up
9const byte FLOAT_PIN = 4; // şamandıra: su varken kapalı (LOW) / float switch: closed (LOW) when water is present
10const byte ALARM_PIN = 5; // LED ya da buzzer / LED or buzzer
11const byte LIGHT_RELAY = 6; // büyüme ışığı rölesi / grow light relay
12const byte PUMP_RELAY = 7; // pompa rölesi / pump relay
13const byte TDS_POWER = 8; // TDS modülü beslemesi pinden / TDS module powered from a pin
14const bool RELAY_ON = LOW; // çoğu röle modülü LOW ile çeker / most relay modules switch on with LOW
15const float VREF = 5.0;
16
17// Hedefler: marul / Targets: lettuce
18const float EC_MIN = 0.8, EC_MAX = 1.2; // mS/cm
19const float PH_MIN = 5.5, PH_MAX = 6.5;
20const float TEMP_MIN = 16.0, TEMP_MAX = 24.0; // °C
21
22const unsigned long PUMP_ON_MS = 15UL * 60UL * 1000UL; // 15 dk açık / 15 min on
23const unsigned long PUMP_OFF_MS = 45UL * 60UL * 1000UL; // 45 dk kapalı / 45 min off
24const byte LIGHT_ON_HOUR = 6, LIGHT_OFF_HOUR = 22; // 16 saat ışık / 16 hours of light
25
26// pH iki nokta kalibrasyonu (kendi ölçtüğün gerilimler) / two-point pH calibration (your measured voltages)
27const float PH_NEUTRAL = 6.86, PH_ACID = 4.00;
28const float V_NEUTRAL = 2.50, V_ACID = 3.03;
29
30OneWire oneWire(ONE_WIRE_PIN);
31DallasTemperature waterSensor(&oneWire);
32RTC_DS3231 rtc;
33bool rtcOk = false;
34
35float waterTemp = 25.0, ecValue = 0, tdsValue = 0, phValue = 7.0;
36bool waterOk = true, pumpOn = true, lightOn = false;
37unsigned long pumpChanged = 0, lastMeasure = 0;
38
39float readVolts(byte pin) { // 15 ölçümün ortancası / median of 15 readings
40 int s[15];
41 for (int i = 0; i < 15; i++) {
42 s[i] = analogRead(pin);
43 delay(20);
44 }
45 for (int i = 1; i < 15; i++) { // ekleme sıralaması / insertion sort
46 int x = s[i], j = i - 1;
47 while (j >= 0 && s[j] > x) { s[j + 1] = s[j]; j--; }
48 s[j + 1] = x;
49 }
50 return s[7] * VREF / 1023.0;
51}
52
53void measure() {
54 waterSensor.requestTemperatures();
55 float t = waterSensor.getTempCByIndex(0);
56 if (t > -50 && t < 80) waterTemp = t; // -127 = sensör yok / sensor missing
57
58 digitalWrite(TDS_POWER, LOW); // TDS kapalıyken pH oku (girişim olmasın) / read pH with TDS off (no interference)
59 delay(800);
60 float vPh = readVolts(PH_PIN);
61 phValue = PH_NEUTRAL + (vPh - V_NEUTRAL) * (PH_ACID - PH_NEUTRAL) / (V_ACID - V_NEUTRAL);
62
63 digitalWrite(TDS_POWER, HIGH); // şimdi TDS'yi aç ve oku / now power and read TDS
64 delay(800);
65 float v = readVolts(TDS_PIN) / (1.0 + 0.02 * (waterTemp - 25.0)); // 25 °C'ye göre düzelt / compensate to 25 °C
66 float ecUs = 133.42 * v * v * v - 255.86 * v * v + 857.39 * v; // µS/cm
67 digitalWrite(TDS_POWER, LOW);
68 ecValue = ecUs / 1000.0; // mS/cm
69 tdsValue = ecUs * 0.5; // ppm (500 ölçeği / 500 scale)
70}
71
72void updatePump() {
73 unsigned long now = millis();
74 if (!waterOk) {
75 pumpOn = false; // su yoksa pompayı koru / protect the pump when dry
76 } else if (pumpOn && now - pumpChanged >= PUMP_ON_MS) {
77 pumpOn = false;
78 pumpChanged = now;
79 } else if (!pumpOn && now - pumpChanged >= PUMP_OFF_MS) {
80 pumpOn = true;
81 pumpChanged = now;
82 }
83 digitalWrite(PUMP_RELAY, pumpOn ? RELAY_ON : !RELAY_ON);
84}
85
86void updateLight() {
87 if (rtcOk) {
88 byte h = rtc.now().hour();
89 lightOn = (h >= LIGHT_ON_HOUR && h < LIGHT_OFF_HOUR);
90 }
91 digitalWrite(LIGHT_RELAY, lightOn ? RELAY_ON : !RELAY_ON);
92}
93
94bool checkAlarms() {
95 bool alarm = false;
96 if (!waterOk) { Serial.println(" ! Su seviyesi dusuk / water level low"); alarm = true; }
97 if (ecValue < EC_MIN) { Serial.println(" ! EC dusuk: besin ekle / EC low: add nutrients"); alarm = true; }
98 if (ecValue > EC_MAX) { Serial.println(" ! EC yuksek: saf su ekle / EC high: add plain water"); alarm = true; }
99 if (phValue < PH_MIN) { Serial.println(" ! pH dusuk / pH low"); alarm = true; }
100 if (phValue > PH_MAX) { Serial.println(" ! pH yuksek / pH high"); alarm = true; }
101 if (waterTemp > TEMP_MAX) { Serial.println(" ! Su cok sicak / water too warm"); alarm = true; }
102 if (waterTemp < TEMP_MIN) { Serial.println(" ! Su cok soguk / water too cold"); alarm = true; }
103 return alarm;
104}
105
106void setup() {
107 Serial.begin(9600);
108 pinMode(FLOAT_PIN, INPUT_PULLUP);
109 pinMode(ALARM_PIN, OUTPUT);
110 pinMode(TDS_POWER, OUTPUT);
111 pinMode(PUMP_RELAY, OUTPUT);
112 pinMode(LIGHT_RELAY, OUTPUT);
113 digitalWrite(PUMP_RELAY, !RELAY_ON);
114 digitalWrite(LIGHT_RELAY, !RELAY_ON);
115 waterSensor.begin();
116 rtcOk = rtc.begin();
117 if (rtcOk && rtc.lostPower()) rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); // saati derleme anına kur / set clock to compile time
118 if (!rtcOk) Serial.println("RTC yok: isik zamanlamasi kapali / no RTC: light schedule off");
119 pumpChanged = millis(); // ilk döngü pompa açık başlar / first cycle starts with the pump on
120}
121
122void loop() {
123 waterOk = (digitalRead(FLOAT_PIN) == LOW);
124 updatePump();
125 updateLight();
126
127 if (millis() - lastMeasure >= 10000UL) { // 10 saniyede bir ölç / measure every 10 s
128 lastMeasure = millis();
129 measure();
130 Serial.print("Su / water: ");
131 Serial.print(waterTemp, 1);
132 Serial.print(" C EC: ");
133 Serial.print(ecValue, 2);
134 Serial.print(" mS/cm (");
135 Serial.print(tdsValue, 0);
136 Serial.print(" ppm) pH: ");
137 Serial.print(phValue, 2);
138 Serial.print(" Pompa / pump: ");
139 Serial.print(pumpOn ? "ON" : "OFF");
140 Serial.print(" Isik / light: ");
141 Serial.println(lightOn ? "ON" : "OFF");
142 digitalWrite(ALARM_PIN, checkAlarms() ? HIGH : LOW);
143 }
144}The heart of the code is the two quick functions in loop(): updatePump() checks the pump cycle and updateLight() the light schedule on every pass. Measurements run every 10 seconds, because a DS18B20 reading takes 750 ms and the analog readings are cleaned of noise with the median of 15 samples. The measure() function first cuts the TDS module's power, reads pH, then powers the TDS module, measures conductivity and switches it off again; since the probe isn't energized all the time, deposits on the electrodes are reduced too. The EC calculation uses the third-order curve published by DFRobot and corrects the result to 25 °C at 2%/°C. Most relay modules switch on when their input is LOW, so the RELAY_ON constant is defined as LOW; if your module switches on with HIGH, just change that line.
Nutrient warning: when and how to add nutrients
EC changes for two reasons, and you need to know which one before acting on a warning. As plants take up nutrients, EC drops; then you should add nutrients. But on hot days water evaporates, the salts stay, the water level falls and EC rises; then you should add plain water, not nutrients. So check the water level first, top the tank up with plain water, stir and measure again. If EC is still low, add the two-part (A and B) fertilizer separately in small doses and wait 10–15 minutes after each addition. Never mix A and B concentrates in the same container: the calcium in A combines with the sulfate and phosphate in B and precipitates, and the plant can't take up those nutrients. Adjust pH last, because adding nutrients changes it. Even so, replace the whole solution every 1–2 weeks. Automatic dosing with peristaltic pumps is possible, but since a faulty sensor can poison the tank, it's safer to start with a warning system.
| Situation | Likely cause | What to do |
|---|---|---|
| EC low, level normal | Plants used up the nutrients | Add A and B separately, a little at a time |
| EC high, level low | Evaporation | Add plain water, no nutrients |
| pH above 6.5 | Normal drift from nutrient uptake | Add pH down drop by drop, wait 15 min |
| pH below 5.5 | Too much acid or a root problem | Correct with pH up, check the roots |
| Water above 24 °C | Warm room, tank in the sun | Shade the tank, add an air stone |
| Float switch low | Water ran out or there is a leak | The pump stops automatically; refill and look for the leak |
Remote monitoring with an ESP32
If you want to keep an eye on the system while you're away, make the ESP32 the brain. The ESP32 reads the same sensors, shows the measurements on a web page over Wi-Fi and gets the time from the internet (NTP), so the DS3231 is no longer needed. The only thing to watch is the 3.3 V limit: the PH-4502C is powered from 5 V and its output can exceed 3.3 V in very acidic solutions. So connect the Po output to GPIO 34 through a 10 kΩ and 20 kΩ voltage divider; the code multiplies the reading by 1.5 to get back the module's real output. You can check the divider values with the voltage divider calculator. The TDS module also works on 3.3 V and its output never exceeds 2.3 V. Since ADC2 pins can't be used while Wi-Fi is on, the sensors are on ADC1 pins (GPIO 34 and 35), and analogReadMilliVolts() gives a more accurate voltage using the ESP32's factory calibration. When choosing a relay module, make sure it can switch with a 3.3 V input.
1// ESP32 hidroponik izleme: web sayfası, NTP ile ışık, pompa döngüsü / ESP32 hydroponics monitor: web page, NTP light schedule, pump cycle
2#include <WiFi.h>
3#include <WebServer.h>
4#include <OneWire.h>
5#include <DallasTemperature.h>
6#include <time.h>
7
8const char* WIFI_SSID = "WIFI_ADIN"; // kendi ağ adın / your network name
9const char* WIFI_PASS = "WIFI_SIFREN"; // kendi şifren / your password
10const char* TZ_INFO = "<+03>-3"; // Türkiye saati (UTC+3), kendi bölgene göre değiştir / Turkey time, change for your zone
11
12const int PH_PIN = 34; // PH-4502C Po, 10 kΩ + 20 kΩ bölücüden / through a 10 kΩ + 20 kΩ divider
13const int TDS_PIN = 35; // TDS modülü A çıkışı / TDS module A output
14const int TDS_POWER = 27; // TDS beslemesi pinden (3,3 V) / TDS powered from a pin (3.3 V)
15const int ONE_WIRE_PIN = 4; // DS18B20 veri / data
16const int FLOAT_PIN = 13; // şamandıra / float switch
17const int LIGHT_RELAY = 25;
18const int PUMP_RELAY = 26;
19const bool RELAY_ON = LOW;
20const float PH_DIVIDER = 1.5; // (10k + 20k) / 20k
21
22const float EC_MIN = 0.8, EC_MAX = 1.2, PH_MIN = 5.5, PH_MAX = 6.5, TEMP_MAX = 24.0;
23const float PH_NEUTRAL = 6.86, PH_ACID = 4.00, V_NEUTRAL = 2.50, V_ACID = 3.03; // modül çıkışında / at the module output
24const unsigned long PUMP_ON_MS = 15UL * 60UL * 1000UL, PUMP_OFF_MS = 45UL * 60UL * 1000UL;
25const int LIGHT_ON_HOUR = 6, LIGHT_OFF_HOUR = 22;
26
27WebServer server(80);
28OneWire oneWire(ONE_WIRE_PIN);
29DallasTemperature waterSensor(&oneWire);
30
31float waterTemp = 25.0, ecValue = 0, tdsValue = 0, phValue = 7.0;
32bool waterOk = true, pumpOn = true, lightOn = false, timeOk = false;
33unsigned long pumpChanged = 0, lastMeasure = 0;
34
35float readVolts(int pin) { // 15 ölçümün ortancası (mV kalibrasyonlu) / median of 15 calibrated mV readings
36 int s[15];
37 for (int i = 0; i < 15; i++) {
38 s[i] = analogReadMilliVolts(pin);
39 delay(10);
40 }
41 for (int i = 1; i < 15; i++) {
42 int x = s[i], j = i - 1;
43 while (j >= 0 && s[j] > x) { s[j + 1] = s[j]; j--; }
44 s[j + 1] = x;
45 }
46 return s[7] / 1000.0;
47}
48
49void measure() {
50 waterSensor.requestTemperatures();
51 float t = waterSensor.getTempCByIndex(0);
52 if (t > -50 && t < 80) waterTemp = t;
53
54 digitalWrite(TDS_POWER, LOW); // pH okunurken TDS kapalı / TDS off while reading pH
55 delay(800);
56 float vPh = readVolts(PH_PIN) * PH_DIVIDER;
57 phValue = PH_NEUTRAL + (vPh - V_NEUTRAL) * (PH_ACID - PH_NEUTRAL) / (V_ACID - V_NEUTRAL);
58
59 digitalWrite(TDS_POWER, HIGH);
60 delay(800);
61 float v = readVolts(TDS_PIN) / (1.0 + 0.02 * (waterTemp - 25.0));
62 float ecUs = 133.42 * v * v * v - 255.86 * v * v + 857.39 * v;
63 digitalWrite(TDS_POWER, LOW);
64 ecValue = ecUs / 1000.0;
65 tdsValue = ecUs * 0.5;
66}
67
68String alarmText() {
69 String a = "";
70 if (!waterOk) a += "Su seviyesi dusuk / water level low<br>";
71 if (ecValue < EC_MIN) a += "EC dusuk: besin ekle / EC low: add nutrients<br>";
72 if (ecValue > EC_MAX) a += "EC yuksek: saf su ekle / EC high: add plain water<br>";
73 if (phValue < PH_MIN || phValue > PH_MAX) a += "pH aralik disinda / pH out of range<br>";
74 if (waterTemp > TEMP_MAX) a += "Su cok sicak / water too warm<br>";
75 if (!timeOk) a += "Saat alinamadi / no time sync<br>";
76 return a.length() ? a : "Her sey yolunda / all good";
77}
78
79void handleRoot() {
80 String h = "<!DOCTYPE html><html><head><meta charset='utf-8'><meta name='viewport' content='width=device-width'>"
81 "<meta http-equiv='refresh' content='10'><title>Hidroponik</title></head><body style='font-family:sans-serif'>"
82 "<h2>Hidroponik / Hydroponics</h2>";
83 h += "<p>Su / water: " + String(waterTemp, 1) + " °C</p>";
84 h += "<p>EC: " + String(ecValue, 2) + " mS/cm (" + String(tdsValue, 0) + " ppm)</p>";
85 h += "<p>pH: " + String(phValue, 2) + "</p>";
86 h += "<p>Pompa / pump: " + String(pumpOn ? "ON" : "OFF") + " · Isik / light: " + String(lightOn ? "ON" : "OFF") + "</p>";
87 h += "<p><b>" + alarmText() + "</b></p></body></html>";
88 server.send(200, "text/html", h);
89}
90
91void handleApi() { // diğer uygulamalar için JSON / JSON for other apps
92 String j = "{\"temp\":" + String(waterTemp, 1) + ",\"ec\":" + String(ecValue, 2) +
93 ",\"ppm\":" + String(tdsValue, 0) + ",\"ph\":" + String(phValue, 2) +
94 ",\"water\":" + String(waterOk ? "true" : "false") + ",\"pump\":" + String(pumpOn ? "true" : "false") + "}";
95 server.send(200, "application/json", j);
96}
97
98void updateOutputs() {
99 unsigned long now = millis();
100 if (!waterOk) pumpOn = false;
101 else if (pumpOn && now - pumpChanged >= PUMP_ON_MS) { pumpOn = false; pumpChanged = now; }
102 else if (!pumpOn && now - pumpChanged >= PUMP_OFF_MS) { pumpOn = true; pumpChanged = now; }
103 digitalWrite(PUMP_RELAY, pumpOn ? RELAY_ON : !RELAY_ON);
104
105 struct tm t;
106 timeOk = getLocalTime(&t, 10); // NTP saati / NTP time
107 if (timeOk) lightOn = (t.tm_hour >= LIGHT_ON_HOUR && t.tm_hour < LIGHT_OFF_HOUR);
108 digitalWrite(LIGHT_RELAY, lightOn ? RELAY_ON : !RELAY_ON);
109}
110
111void setup() {
112 Serial.begin(115200);
113 pinMode(FLOAT_PIN, INPUT_PULLUP);
114 pinMode(TDS_POWER, OUTPUT);
115 pinMode(PUMP_RELAY, OUTPUT);
116 pinMode(LIGHT_RELAY, OUTPUT);
117 digitalWrite(PUMP_RELAY, !RELAY_ON);
118 digitalWrite(LIGHT_RELAY, !RELAY_ON);
119 waterSensor.begin();
120
121 WiFi.mode(WIFI_STA);
122 WiFi.begin(WIFI_SSID, WIFI_PASS);
123 for (int i = 0; i < 40 && WiFi.status() != WL_CONNECTED; i++) delay(500);
124 Serial.print("IP: ");
125 Serial.println(WiFi.localIP());
126 configTzTime(TZ_INFO, "pool.ntp.org", "time.google.com");
127
128 server.on("/", handleRoot);
129 server.on("/api", handleApi);
130 server.begin();
131 pumpChanged = millis();
132}
133
134void loop() {
135 server.handleClient();
136 waterOk = (digitalRead(FLOAT_PIN) == LOW);
137 updateOutputs();
138
139 if (millis() - lastMeasure >= 10000UL) {
140 lastMeasure = millis();
141 measure();
142 if (WiFi.status() != WL_CONNECTED) WiFi.reconnect(); // bağlantı koptuysa yeniden dene / retry if disconnected
143 Serial.printf("Su %.1f C EC %.2f mS/cm pH %.2f\n", waterTemp, ecValue, phValue);
144 }
145}After uploading, type the IP address shown in the Serial Monitor into the browser of a phone on the same network. The page refreshes itself every 10 seconds and shows the water temperature, EC and ppm, pH, pump and light status and any warnings. The /api address returns the same data as JSON, so Home Assistant or your own app can read it easily. If you also want to see it when you're away from home, you can send the data to a cloud service; the ESP32 ThingSpeak article shows how to log it with charts, and the ESP32 Telegram bot article shows how to send alarms to your phone as messages.
Arduino hydroponics project ideas
- Countertop lettuce garden: Grow fresh lettuce all year with a small 8-hole NFT channel, a 12 V pump and an LED strip.
- Growth experiment for school: Grow the same plant in two tanks at different EC values, log hourly measurements with Arduino and compare the results.
- Aquaponics: Pump water from a fish tank to a plant bed and back; see the aquarium controller article for details.
- Automatic dosing: Add A and B fertilizer one after the other with two peristaltic pumps, leaving a waiting time in between.
- Greenhouse integration: Connect the hydroponic tank to a smart greenhouse system and manage it together with air temperature, humidity and a fan.
- Seedling station: Prepare seedlings for the hydroponic system with a warm germination tray under 18 hours of light.
Common mistakes and fixes
| Symptom | Likely cause | Fix |
|---|---|---|
| pH value keeps drifting | TDS probe running at the same time | Power the TDS module from a pin and switch it off while reading pH |
| pH stuck near 7, no response | Probe dried out or never calibrated | Soak the probe in KCl solution, calibrate at two points |
| EC stays the same with a heavy feeder | Gravity TDS sensor saturated at 1000 ppm | Use an industrial EC probe with K=1 |
| Temperature reads -127 °C | DS18B20 pull-up missing or broken wire | Fit 4.7 kΩ between data and VCC |
| Pump never stops or never runs | Relay switches on with LOW, logic inverted | Change RELAY_ON to suit your module |
| Brown, smelly rot on the roots | Warm water and low oxygen | Bring the water below 22 °C, add an air stone, darken the tank |
| Arduino resets randomly | Pump or relay coil creates noise | Separate power supply, diode or capacitor across the pump |
An Arduino hydroponics system brings sensor reading, calibration, timing, relay control and IoT together in one living project, and in the end it puts a fresh salad on your table. Start with a small lettuce tank, watch how the values change over a few weeks, then grow the automation step by step. In the BlueGrays app you can open the smart irrigation station, temperature measurement and ESP32 web server projects with step-by-step circuit diagrams and ready-to-use code and try the parts of the hydroponic system one by one.
Frequently asked questions
What should EC be in a hydroponic system?
It depends on the plant: 0.8–1.2 mS/cm for lettuce, 1.0–1.6 for basil, 1.8–2.2 for strawberries and 2.0–5.0 mS/cm for tomatoes are good starting points. Start at the low end for seedlings and raise it as the plant grows. The dose on your fertilizer label always comes first.
Why is pH important in hydroponics?
pH decides how well the roots can take up nutrients; most plants absorb all nutrients best between 5.5 and 6.5. If pH leaves this range, the plant can't take up a nutrient even when it's in the tank, and deficiency symptoms appear on the leaves. Check pH once a day and correct it in small doses if needed.
What is the difference between TDS and EC?
EC is the water's electrical conductivity and is measured directly; TDS is the amount of dissolved solids in ppm estimated from that measurement. Most meters use ppm = EC (µS/cm) × 0.5, and some multiply by 0.7. When comparing sources, converting the values to EC is the safest option.
How long should a hydroponic pump run?
It depends on the method: in NFT the pump runs continuously or 15 minutes on and 15 minutes off, and in ebb and flow 15 minutes 4–6 times a day is enough. DWC uses an air pump running 24 hours instead of a water pump. On hot days and with large plants you may need shorter intervals.
How often should you change a hydroponic nutrient solution?
The general rule is to replace the whole solution every 1–2 weeks. In between, top up with plain water as the level drops and with nutrients as EC falls. If you see a bad smell, cloudiness or algae in the tank, change it right away.
Is building a hydroponic system with Arduino expensive?
A basic system only needs an Arduino, a TDS sensor, a DS18B20, a float switch, a relay module and a small pump, and these are quite cheap. The most expensive part is usually the pH probe, which needs replacing every 1–2 years. Starting with Kratky or a simple DWC and adding automation later keeps the cost very low.
Projects to build after reading this
See all projects
Smart Irrigation Station
A gardener that waters your plants on its own, so they don't dry out while you're on vacation.

Temperature Measurement with NTC and 2x16 Lcd Display
Measure the temperature around you with a sensor that looks like a tiny bead. This part, called an NTC, lets electricity through more easily as it warms up; the Arduino reads that change, turns it…

Temperature and Humidity with DHT11
How warm is your room, and is the air humid or dry? The DHT11 sensor measures temperature and humidity, and the Arduino writes the values on a two-line LCD screen, refreshing every couple of seconds.

ESP32 DHT22 Temperature and Humidity (with LCD Display)
This project measures ambient temperature and humidity using a DHT22 sensor and displays the data in real time on a 16x2 I2C LCD. Data is read from the sensor using the one-wire protocol via the Adafruit DHT library. This project serves as the foundation for IoT weather stations, smart home automation, or environmental monitoring systems in greenhouses. Communication with the DHT22 is established via the ESP32's GPIO 4 pin.

ESP32 Temperature Data Logger (DHT22 + DS1307 RTC + microSD + OLED)
Build a timed temperature and humidity logger with the ESP32! A DHT22 sensor reads temperature and humidity once a minute, and each reading is saved to a microSD card in CSV format with a real-time stamp from the DS1307 RTC module. The OLED display shows the latest temperature, humidity, timestamp and total number of records live, in large text.

ESP32 Asynchronous Web Server (with IP Display on LCD)
In this project, we’re turning the ESP32 into an asynchronous web server that you can control from your phone or computer on the same Wi-Fi network. Thanks to the ESPAsyncWebServer library, the server can process multiple requests simultaneously (unlike the classic WebServer.h, which blocks on a single request). You’ll be able to open the ESP32’s IP address in a browser and click the ON/OFF buttons (the /on and /off routes) to turn the LED connected to GPIO 5 on and off.

ESP32 Wi-Fi STA Connection (with LCD Screen)
In this project, we connect the ESP32 to the home Wi-Fi network in Station (STA) mode in a secure, fault-tolerant manner. We store the SSID and password in a separate secrets.h file to prevent leaking to Git, set up an auto-reconnect mechanism, and display the RSSI signal level and IP address on an I2C LCD screen. The internal LED works as a status indicator. It is a production-grade connection manager.
More articles
BlueGrays app
Build this circuit step by step on your phone
Wiring diagram, code and parts list on one screen. 500+ Arduino, ESP32, ESP8266, Pico, mBot and micro:bit projects ready to build.
Scan with your phone
Point your camera at the code and your phone's app store opens.
or open the store

