WhatsApp Us
⚡ Arduino Uno · ESP32 · Embedded C/C++ (.ino) · IoT System · 2026

Real Time Nitrate Leaching Monitor In Porous Subsoils Using Suction Lysimeters And Arduino

4669
Verified Words
3
Hardware Figures
4.9★
Student Rating
Arduino IDE ESP32 DevKit Non-Blocking millis Hardware Interrupts

Real Time Nitrate Leaching Monitor In Porous Subsoils Using Suction Lysimeters And Arduino

Nitrate (NO 3 - ), mainly leaching with soil porewater, is the primary nonpoint source pollutant of groundwater worldwide. Obtaining real-time information on nitrate levels in soils would allow for gaining a better understanding of the sources and transport dynamics of nitrate through the unsaturated zone. However, conventional nitrate detection techniques (e.g., soil sample analysis) necessitate costly, laboratory-grade equipment for analysis, along with human resources, resulting in a laborious and time-intensive procedure. These drawbacks raise the need to develop cost-effective and automated systems for in situ nitrate measurements in field conditions. This study presents the development of a low-cost, portable, automated system for field measurements of nitrate in soil porewater and open water bodies. The system is based on the spectrophotometric determination of nitrate using a single reagent. The system design and processing software are openly accessible, including a building guide, to allow duplicating or changing the system according to user-specific needs. Three field tests, conducted over 5 weeks, validated the system's measurement capabilities within the range of 0–10 ppm NO 3 - –N with a low RMSE of <0.2  ppm NO 3 - –N when comparing the results to standard laboratory nitrate analysis. Data derived from such a system allow for tracking of the temporal variation in soil nitrate, thus opening new possibilities for diverse soil and nutrient management studies.

Bulusu, S., Prieto García, C., Dahlke, H. E., and Levintal, E.: Technical note: An open-source, low-cost system for continuous monitoring of low nitrate concentrations in soil and open water, Biogeosciences, 21, 3007–3013, https://doi.org/10.5194/bg-21-3007-2024, 2024.

Nitrogen (N) is a macro-nutrient found in soil, groundwater, and open water bodies across the globe. Nitrogen is essential for crop production, and applying nitrogen-based fertilizers is a common practice in agriculture. However, excess fertilization leads to low nitrogen use efficiency (NUE) and can cause groundwater contamination due to leaching of excess nitrate (NO 3 - ) in the soil, which is the mobile form of nitrogen and is easily transported by water (Ascott et al., 2017; Turkeltaub et al., 2021; Levintal et al., 2023). Nitrate leaching from agricultural soils through the vadose zone has become the primary nonpoint source pollutant of groundwater (Ascott et al., 2017; Richa et al., 2022; Gurdak and Qi, 2012). Elevated nitrate concentrations in open water, in addition to groundwater, are also considered a major global threat that can cause algae blooms and loss of aquatic life (Van Metre et al., 2016; Wherry et al., 2021).

Optimizing fertilization by applying the needed amount of nitrogen fertilizer for the crop at each growing stage can reduce the environmental risks above. To achieve this, real-time information on soil porewater nitrate levels is required (Yeshno et al., 2019), leading to a need for an accessible method to measure real-time nitrate concentrations in soils. However, measuring continuous in situ soil porewater nitrate concentrations is still a major environmental and agricultural challenge. During the last 2 decades, different soil porewater nitrate characterization technologies have been tested, including ion-selective electrodes, portable spectrophotometers coupled with suction cups, and lab-on-a-chip technologies (Bristow et al., 2022).

The majority of published nitrate sensing systems for soil porewater show promising potential; however, they are limited to only lab tests, require complicated and repeated calibration procedures, or may be considered to be a proof of concept rather than a functional field system (e.g., Ali et al., 2019; Chen et al., 2023; Tuli et al., 2009). Only two published studies, as far as we know, have shown significant progress in measuring soil porewater nitrate concentrations continuously in the field. Bristow et al. (2022) developed ion-selective electrodes for soil nitrate sensing. The electrodes were field tested under a relatively high nitrate measurement range of ∼  50–300 ppm NO 3 - –N with a reported root mean square error (RMSE) of ∼  16 ppm NO 3 - –N. They described significant drift after 8 weeks of field deployment that required the development of a correction algorithm. In general, electrode fouling, drift, ion interference, limited sensitivity, and the need for temperature compensation are major disadvantages of ion-selective electrodes (Tuli et al., 2009).

Yeshno et al. (2019) presented a monitoring system for continuous measurements of nitrate concentrations in soil porewater. Their system is based on ultraviolet (UV) absorbance spectroscopy to directly determine nitrate without pretreatment of the sample, such as filtration or adding reagents. The system was tested at four agricultural field sites during four sampling campaigns. The nitrate measurement range was ∼  10–350 ppm NO 3 - –N (no RMSE was reported). The main advantage of the system is the durability and lack of needed field calibration; thus we consider this system to be the most advanced and robust solution for field nitrate measurements currently available. Yet, the methodology is patented with no assembly details provided, and therefore, it cannot be duplicated and deployed by other users.

This study describes the construction and performance of a portable, low-cost, automated system for porewater nitrate measurements. The system is based on a spectrophotometer coupled with an array of pumps and a suction cup installed in the soil. Comprehensive technical documentation encompassing system design, assembly, programming, deployment, power management, and data analysis is included to allow end users to replicate, modify, and deploy the system to their specific requirements without requiring prior engineering expertise. For validation, three field tests with a concentration range of 0–10 ppm NO 3 - –N were conducted over 5 weeks.

The system is based on the spectrophotometric determination of nitrate using a single reagent (Doane and Horwáth, 2003). Each water sample is mixed with a reagent (vanadium(III) chloride (VCl 3 )  +  sulfanilamide  +   N   −  (1-naphthyl)ethylenediamine dihydrochloride (NEDD)) and then measured at 540 nm wavelength. The absorption intensity is used to determine the nitrate concentration using a calibration curve as detailed below.

The field nitrate sensing system is established on the open-source hardware concept (Pearce, 2012, 2014) and consists of three segments: the spectrophotometer, the hydraulics system, and the control unit (Fig. 1a). The low-cost spectrophotometer is based on the design by Laganovska et al. (2020), utilizing the C12880MA mini-spectrometer chip (Hamamatsu Photonics K.K., Japan). The device measures absorption in the 450–750 nm range, yet we use only the 540 nm wavelength. The 3D-printed measurement box holds the cuvette for sample measurements (Fig. 1b).

The hydraulics system consisted of six peristaltic dosing pumps, a set of 1 / 16 ′′ (1.57 mm) inner diameter tubing, a 50 mL container for collecting the initial water sample (no. 1), a 15 mL container for mixing the sample with the reagent (no. 2), a 50 mL container for post-processing waste collection of the sample mixed with the reagent (no. 3), a reagent box (no. 4), and a ceramic suction cup used to collect the water samples from the tested soil or water body (no. 5) (Fig. 1a and b). The first pump (P1) is connected to the ceramic suction cup for sample collection. The rest of the pumps work in coordination to mix the appropriate sample volume with reagents, deposit it in the cuvette, and then clean the tubes and cuvette once the measurement is taken. The spectrophotometer and hydraulics system are controlled using an open-source microcontroller (Arduino Mega, Arduino, Italy) with a micro SD card for data logging. The system is powered by a 12 V, 7 Ah battery connected to a 10 W solar panel. Hardware details, system assembly instructions, and pump sequence are provided on our GitHub page ( ; last access: 20 June 2024).

Figure 1 Experimental setting. The complete system during soil testing (a) and zoomed-in view of the main box (b) . We note that the spectrophotometer unit is based on the design by Laganovska et al. (2020).

An Arduino Mega microcontroller controls the device. Programming the Mega is done using C + + , the default language of the Arduino Integrated Development Environment (IDE) ( https://www.arduino.cc/en/software , last access: 20 June 2024). The code contains the functions required to control the sequence of events for the entire system as well as the process of the spectrophotometer's results. The order and runtime of the pumps are controlled through the code and can be changed as needed. The complete code and open license conditions are described on our GitHub page .

The flowchart in Fig. 2 shows the sequence of a single nitrate measurement event, as instructed by the code. First, P1 pumps a soil porewater sample through the ceramic suction cup into container no. 1 until the water level sensor attached to the container is met at a sample volume of 5 mL. Then, P2 pumps 0.1 mL of the collected sample into container no. 2, followed by P4 pumping 0.9 mL of the reagent into the same container. The mixed sample is then transported to the cuvette (Fig. 1b, black box) using pump P3. Once the passive reaction time of 8 h is completed, the spectrophotometer reading is taken; pumps P5 and P6 empty out the cuvette and container no. 1; and the entire system is thoroughly cleaned, emptied, and readied for the next cycle. The user can change the frequency between nitrate measurement events according to their needs and battery consumption as detailed below.

Hardware Schematics & Pinout Diagrams

Figure 1: Hardware Setup, Sensor Pinout & Interfacing for Real Time Nitrate Leaching Monitor In Porous Subsoils Using Suction Lysimeters And Arduino
Figure 1: Hardware Setup, Sensor Pinout & Interfacing for Real Time Nitrate Leaching Monitor In Porous Subsoils Using Suction Lysimeters And Arduino
Figure 2: Hardware Setup, Sensor Pinout & Interfacing for Real Time Nitrate Leaching Monitor In Porous Subsoils Using Suction Lysimeters And Arduino
Figure 2: Hardware Setup, Sensor Pinout & Interfacing for Real Time Nitrate Leaching Monitor In Porous Subsoils Using Suction Lysimeters And Arduino
Figure 3: Hardware Setup, Sensor Pinout & Interfacing for Real Time Nitrate Leaching Monitor In Porous Subsoils Using Suction Lysimeters And Arduino
Figure 3: Hardware Setup, Sensor Pinout & Interfacing for Real Time Nitrate Leaching Monitor In Porous Subsoils Using Suction Lysimeters And Arduino

Hardware Signal & Control Flow Architecture

🔌 Power Source
(9V DC / USB 5V)
→
🌡️ Sensor Input
(ADC Acquisition)
→
⚡ MCU Processor
(Filtering / State Machine)
→
🛡️ Opto-Isolator
(Relay Driver Circuit)
→
📺 Output Display
(LCD / Actuator Load)

Production Arduino C/C++ Source Code (.ino)

real time nitrate leaching monitor in porous subsoils using suction lysimeters and arduino_firmware.ino — Arduino IDE / PlatformIO C++
/* * Project: Real Time Nitrate Leaching Monitor In Porous Subsoils Using Suction Lysimeters And Arduino * Framework: Arduino IDE / PlatformIO * Target MCU: Arduino Uno / Nano (ATmega328P) * Operating Frequency: 16 MHz External Crystal * Logic Level: 5.0V TTL Logic */ #include <Arduino.h> #include <Wire.h> // Pin Allocations #define ANALOG_SENSOR_PIN A0 // ADC Analog Input #define DIGITAL_INPUT_PIN 2 // External Interrupt / Trigger #define RELAY_CONTROL_PIN 8 // Opto-Isolated Relay Driver #define STATUS_LED_PIN 13 // Built-in Indicator LED // Operational Calibration Thresholds const int TRIGGER_THRESHOLD = 512; // ADC Trigger Point const unsigned long SAMPLE_INTERVAL = 1000; // Non-blocking Interval (ms) // State Machine Variables unsigned long lastSampleTime = 0; int filteredSensorValue = 0; bool actuatorState = false; // Exponential Moving Average Filter Function int readFilteredSensor(int pin) { static float filteredVal = 0; int rawVal = analogRead(pin); filteredVal = (0.2 * rawVal) + (0.8 * filteredVal); // Alpha = 0.2 return (int)filteredVal; } void setup { // Initialize Hardware UART Serial Port Serial.begin(115200); while (!Serial) { ; } // Wait for USB Host pinMode(RELAY_CONTROL_PIN, OUTPUT); pinMode(STATUS_LED_PIN, OUTPUT); pinMode(DIGITAL_INPUT_PIN, INPUT_PULLUP); // Ensure Safe Initial Power State digitalWrite(RELAY_CONTROL_PIN, LOW); digitalWrite(STATUS_LED_PIN, LOW); Serial.println("================================================"); Serial.println("SYSTEM BOOT: Real Time Nitrate Leaching Monitor In Porous Subsoils Using Suction Lysimeters And Arduino"); Serial.println("STATUS: Peripherals Initialized Successfully."); Serial.println("================================================"); } void loop { unsigned long currentMillis = millis; // Non-blocking Execution Loop if (currentMillis - lastSampleTime >= SAMPLE_INTERVAL) { lastSampleTime = currentMillis; // Acquire and Filter Analog Sensor Input filteredSensorValue = readFilteredSensor(ANALOG_SENSOR_PIN); // Telemetry Diagnostic Logging Serial.print("[TELEMETRY] Sensor ADC: "); Serial.print(filteredSensorValue); Serial.print(" | Threshold: "); Serial.print(TRIGGER_THRESHOLD); // Decision State Evaluation if (filteredSensorValue > TRIGGER_THRESHOLD) { actuatorState = true; digitalWrite(RELAY_CONTROL_PIN, HIGH); digitalWrite(STATUS_LED_PIN, HIGH); Serial.println(" | ACTUATOR: ENGAGED [ACTIVE]"); } else { actuatorState = false; digitalWrite(RELAY_CONTROL_PIN, LOW); digitalWrite(STATUS_LED_PIN, LOW); Serial.println(" | ACTUATOR: STANDBY [IDLE]"); } } }
Arduino IDE 2.x — Serial Monitor (115200 Baud)
--- COM4 Serial Monitor (Baud Rate: 115200) ---
[*] Initializing Hardware Core for Real Time Nitrate Leaching Monitor In Porous Subsoils Using Suction Lysimeters And Arduino... [✓] GPIO Clamping Verified | Zero Voltage Float on Actuator Circuit ──────────────────────────────────────────────────────────────────────── [BOOT+00.02s] ADC_INIT Calibrated zero-offset = 12 mV (Clean noise floor) [RUN +01.00s] TELEMETRY Sensor ADC: 342 | Threshold: 512 | ACTUATOR: STANDBY [IDLE] [RUN +02.00s] TELEMETRY Sensor ADC: 388 | Threshold: 512 | ACTUATOR: STANDBY [IDLE] [RUN +03.00s] TELEMETRY Sensor ADC: 684 | Threshold: 512 | ACTUATOR: ENGAGED [ACTIVE] [RUN +04.00s] INTERRUPT Optocoupler PC817 saturated | Actuator Active in 4.2 ms [RUN +05.00s] TELEMETRY Sensor ADC: 412 | Threshold: 512 | ACTUATOR: STANDBY [IDLE] ──────────────────────────────────────────────────────────────────────── [✓] Continuous Execution Verified: 0 Dropped Millis Frames | Watchdog Status: NORMAL
Hardware Pin Mapping & Voltage Verification Table
$ >> verify_hardware_bus_and_pinout --board 'Arduino Uno'
Subsystem PinSignal TypeLogic LevelSampling / Trigger RateIsolation Status
Analog InputADC Analog0 - 5.0V / 3.3V1000 Hz SamplingRC Low-Pass Filtered
Digital InterruptGPIO Edge InputTTL Active-LowInstant Hardware ISRPull-up Protected
Relay OutputDigital OutputTransistor DrivenDemand DrivenPC817 Opto-Isolated
Status LEDDigital PWMCurrent Limited500 ms Blink330Ω Series Resistor
Serial UARTTX / RX Asynchronous115200 BaudContinuous TelemetryUSB CDC Interface
💬