Select your language

© Borgmann Aquaponik & Hydroponik
Alle Rechte Vorbehalten
https://borgmann-aquaponik-hydroponik.ch

Viel Erfolg wünschen wir Ihnen!

  Laying the Foundation
    Sensors and Data Acquisition for Smart Gardens

The precise and reliable monitoring of relevant system parameters forms the indispensable foundation for the optimized operation of aquaponics and hydroponics systems. This article explains the technical functionality, selection criteria, and implementation of sensors for automated data acquisition, with a special focus on quality differences, calibration procedures, and communication protocols.

The first thought of many readers will (presumably) be: this is too much technology - far too complicated, I have no idea about electricity or power. Nothing could be further from the truth than this judgment. On the one hand, there are countless aids and examples on the internet, and on the other hand, programming is surprisingly simple if you take some time and accept from the beginning: you cannot understand everything immediately.

I have selected a short example for you, exactly on this topic "Sensors", from the "Learn Robotics" website www.learnrobotics.org. It clearly explains how to program a microcomputer, even if you have never had contact with the subject before. The address of the original article can also be found here in the code example. There you will also find the circuit diagram and how to connect the sensor to the controller. No prior knowledge is necessary.

Use the following code from the Learn Robotics example page: https://www.learnrobotics.org/blog/read-analog-sensors-arduino/

What the program does: you have a light-dependent resistor (LDR). This changes its electrical resistance as it gets brighter or darker. The program now simply reads the electrical resistance and with an "If -> Then" query ( if(reading >= threshold){... ) the Arduino responds with either "daylight" or "nighttime".

/* Read an Analog Sensor with Arduino * Example using LDR Light Sensor * * For use without warranty * www.learnrobotics.org */ int ldr = A0; int reading; int threshold = 900; void setup() { pinMode(ldr, INPUT); Serial.begin(9600); } void lightCheck(){ reading = analogRead(ldr); Serial.print("reading = "); Serial.print(reading); if(reading >= threshold){ Serial.println(" daylight"); } else{ Serial.println(" nighttime"); } delay(1000); } void loop() { lightCheck(); }

 

1.1 Relevant Parameters and Sensor Technologies

Measuring specific environmental and water parameters is crucial for plant growth and system stability. The choice of the right sensor type largely depends on the required accuracy, longevity, and budget.

1.1.1 pH Value Measurement

The pH value is a logarithmic measure of hydrogen ion concentration and affects nutrient availability for plants as well as the well-being of fish (aquaponics). An ideal range typically lies between pH 5.5 and 6.5 for hydroponics and pH 6.0 and 7.0 for aquaponics.

Sensor Types and Pricing:
  • Hobby-Grade Electrodes (approx. 20–100 €): Often with plastic casing, glass membrane, and a KCl gel electrolyte. These electrodes are designed for intermittent use and systems with low demands on long-term stability. Their lifespan is limited (typically 6–12 months of continuous operation), and they require more frequent calibrations. Accuracy can be in the range of ±0.1 to ±0.2 pH units.
  • Industrial / Laboratory-Grade Electrodes (approx. 150–1000+ €): Feature more robust glass membranes, liquid reference systems (KCl solution that needs refilling) for higher stability and accuracy (up to ±0.01 pH), and more durable casings (e.g., made of PPS or stainless steel) for industrial applications or continuous use over several years. These often also offer integrated temperature sensors and special designs for different installation environments.

1.1.2 Electrical Conductivity (EC Value)

Electrical conductivity measures the concentration of dissolved ions in water and serves as an indicator of nutrient concentration in the solution. It is usually expressed in microsiemens per centimeter (µS/cm) or millisiemens per centimeter (mS/cm).

Sensor Types and Pricing:
  • 2-Pole Carbon or Stainless Steel Sensors (approx. 30–150 €): These simple probes measure the resistance between two electrodes. They are cost-effective but can be prone to drift due to deposits (biofilm, scale) on the electrodes and require regular cleaning.
  • 4-Pole Inductive Sensors (approx. 300–1500+ €): These sensors measure conductivity contactlessly via an induction loop. They are less sensitive to contamination and surface deposits, offer higher long-term stability and accuracy, but are significantly more expensive. Commonly used in industrial and professional aquaponics systems.

1.1.3 Temperature Measurement

Water temperature influences the solubility of oxygen and nutrients, the metabolic rate of plants and fish, and the activity of microorganisms. It is also a critical parameter for compensating pH and EC measurements.

Sensor Types:
  • DS18B20 (approx. 5–15 €): A digital temperature sensor from Maxim Integrated that communicates via the OneWire bus. It is often available in waterproof stainless steel sleeves, inexpensive and precise (±0.5°C). Ideal for water and soil temperature measurements.
  • NTC Thermistor (approx. 1–5 €): Analog resistance sensors whose resistance changes with temperature. Inexpensive, but require calibration and more complex evaluation.
Temperature Dependence of pH and EC:

Both pH and EC values are highly temperature-dependent. Ion activity (pH) and ion mobility (EC) change with temperature. Professional measuring devices and sensors have automatic temperature compensation (ATC). Without ATC, measurement values can deviate significantly. Typically, a reference temperature of 25°C is assumed. With a deviation of 1°C from the reference value, the pH value can vary by up to 0.01-0.03 pH units, the EC value even by 1-3% per degree Celsius. Therefore, the integration of a temperature sensor into pH and EC measurement circuits is essential. (Reference: ISO 10523:2008 for water quality measurement, manufacturer datasheets of pH/EC electrodes).

1.1.4 Water Level Measurement

Monitoring the water level is essential to ensure the safe operation of pumps, prevent dry running, and ensure the correct functioning of flood-and-drain systems or the continuous supply of NFT channels.

Sensor Types:
  • Float Switches (non-invasive, approx. 5–20 €): Mechanical sensors triggered by the water level. They are robust, reliable, and cost-effective. However, they are invasive, meaning they are in the water, which can lead to biofouling or corrosion in the long term. Ideal for simple on/off switching at critical levels.
  • Capacitive Water Level Sensors (non-invasive, approx. 10–30 €): These sensors measure a change in capacitance caused by the presence of water on the opposite side of a non-conductive wall (e.g., plastic tank). They are non-invasive, contactless, and thus insensitive to corrosion and biofilm. They are well suited for measuring levels through container walls.
  • Ultrasonic or Infrared Sensors (non-invasive, approx. 15–50 €): These sensors measure the distance to the water surface using sound waves (ultrasonic) or light (infrared). They are non-invasive and enable continuous level measurement. However, they can be affected by moisture, fog, or condensation and require a clear view of the water surface.

1.1.5 Light Intensity / Photosynthetically Active Radiation (PAR)

The light spectrum and intensity of photosynthetically active radiation (PAR) are crucial for plant growth. Measurement helps to optimize the efficiency of artificial lighting.

Sensor Types:
  • Photoresistors (LDR) (approx. 1–5 €): Very cost-effective, measure general brightness based on their resistance. Not spectrally selective or PAR optimized, but sufficient for simple light/dark detection or rough intensity measurement.
  • Digital Ambient Light Sensors (e.g., BH1750, VEML6070, approx. 5–20 €): Provide digital output in lux and are often spectrally adapted to the human eye. Better than LDRs for more accurate brightness values.
  • PAR Sensors (approx. 100–500+ €): Specialized sensors that measure Photosynthetically Active Radiation (400-700 nm) in µmol/m²/s. Essential for precise control and optimization of professional growth lighting. Very precise, but significantly more expensive.

1.2 Sensor Communication Protocols for Microcontrollers

The way sensors transmit data to a microcontroller is crucial for system architecture and wiring complexity.

  • Analog (Voltage Signal):

    Functionality: Many basic sensors provide a variable voltage signal (e.g., 0-3.3V or 0-5V) that is connected directly to the analog-to-digital converters (ADC) of the microcontroller.
    Advantages: Simple implementation, inexpensive sensors.
    Disadvantages: Susceptibility to noise, limited accuracy due to ADC resolution (e.g., 10-bit ADC = 1024 steps), often only short cable runs without signal loss. Hobby-grade pH and EC modules use this method. An important point is the isolation of the sensors from each other (e.g., by galvanic isolation) to avoid measurement interference, especially with pH and EC probes.

  • I²C (Inter-Integrated Circuit):

    Functionality: A serial bus protocol that requires only two lines (SDA for data, SCL for clock). Sensors are addressed via unique addresses, allowing multiple I²C devices to be connected to the same bus.
    Advantages: Digital precision, reduced wiring, good noise immunity, master-slave architecture.
    Disadvantages: Limited bus length (typically up to a few meters), address conflicts with sensors with fixed addresses. Examples: BH1750 light sensor, some CO2 sensors, more advanced pH/EC interfaces.

  • UART (Universal Asynchronous Receiver-Transmitter):

    Functionality: A serial communication protocol that uses separate transmit (TX) and receive (RX) lines. Point-to-point connection.
    Advantages: Simple protocol implementation, higher data rates than I²C possible, often used for more complex data packets and configuration options.
    Disadvantages: Requires separate RX/TX pins per sensor (or multiplexers), less efficient for many sensors on the same bus. Often used by specialized sensors (e.g., some CO2 sensors, more precise pH/EC interface boards with RS232/RS485 converters for longer distances).

  • OneWire:

    Functionality: A special serial bus protocol that requires only one data line and has unique 64-bit addresses.
    Advantages: Minimal wiring, very efficient for multiple temperature sensors (like the DS18B20) on one bus.
    Disadvantages: Low data rate, only a few sensor types available (mainly temperature).

1.3 Detailed Calibration of pH and EC Sensors

Regular and correct calibration is crucial for maintaining measurement accuracy over the lifespan of the sensors. Neglecting it leads to unreliable data and potential problems in the system.

1.3.1 pH Sensor Calibration

Frequency and Costs:

Hobby-Grade Electrodes: Depending on use and accuracy requirements, every 1-4 weeks. Industrial / Laboratory-Grade Electrodes: Every 1-3 months, less frequently with stable use.

Cost for Buffer Solutions: Calibration solutions (pH 4.0, pH 7.0, pH 10.0) cost approx. 10-25 € per liter. Additionally, a special KCl storage solution (3M potassium chloride) is required for the electrode (approx. 10-15 € per 100ml).

Specific Procedure (Two- or Three-Point Calibration):
  1. Cleaning: Rinse the electrode thoroughly with distilled or demineralized water before and after each calibration. Use a soft cloth or paper towel to gently blot, not rub.
  2. Buffer pH 7.0 (Neutral Point): Immerse the electrode in pH 7.0 buffer solution (reference point). Wait until the reading on the display device or in the microcontroller's serial monitor is stable (usually 30-60 seconds). Note the raw analog value output by the microcontroller.
  3. Second Buffer Point (Slope): Rinse the electrode again. Immerse it in a second buffer solution (e.g., pH 4.0 or pH 10.0) that is close to the expected operating range of your system. Wait for stability and note the raw value.
  4. Third Buffer Point (Optional): For highest precision, a third buffer solution can be used (e.g., pH 4.0 and pH 10.0 if pH 7.0 was the first point).
  5. Linear Regression in Code: A linear equation (pH = m * raw_value + b) is used in the microcontroller code for conversion. The calibration points are used to calculate the slope (m) and intercept (b) of this line. Many libraries for pH sensor modules perform this calculation internally.
    Example (simplified for 2 points): Let (R1, pH1) = (raw value at pH 7.0, 7.0) and (R2, pH2) = (raw value at pH 4.0, 4.0). Then m = (pH2 - pH1) / (R2 - R1) and b = pH1 - m * R1.
  6. Temperature Compensation: Integrate the water temperature measured by the temperature sensor into the pH calculation to correct for temperature-dependent deviations. Modern pH sensor modules often have a separate temperature input for this.
  7. Storage: Always store the pH electrode in the special KCl storage solution or, if necessary, in pH 4.0 buffer solution, never in distilled water, as this dries out the sensitive glass membrane and irrevocably damages the electrode.

1.3.2 EC Sensor Calibration

Frequency and Costs:

EC sensors should also be calibrated every 2-4 weeks. Calibration solutions are available in various concentrations (e.g., 1.413 µS/cm for typical plant solutions, 2.778 µS/cm for higher concentrations) and cost approx. 15-30 € per liter.

Specific Procedure:
  1. Cleaning: Thoroughly clean the probe of biofilm or deposits with distilled water and a soft cloth.
  2. Calibration Solution: Immerse the probe in a calibration solution of known conductivity (e.g., 1.413 µS/cm at 25°C). Wait for temperature stabilization and a stable reading.
  3. Cell Constant & Temperature Compensation: Every EC sensor has a "cell constant" (k-value, often k=1.0 or k=0.1) that describes its geometry. Calibration consists of adjusting this value or the compensation factor in the microcontroller code (or in the module) so that the measured raw value corresponds to the known conductivity of the calibration solution at the reference temperature (25°C). Temperature compensation is particularly important here, as conductivity varies greatly with temperature (approx. 2% per °C).
    Formula (simplified): EC_compensated = EC_measured / (1 + α * (T_measured - T_reference)), where α is the temperature coefficient (typ. 0.02).
  4. Verification: After calibration, you can immerse the probe in a second calibration solution with a different conductivity to verify accuracy over the measurement range.

1.4 Example: Hardware Configuration for a Hobby System

A typical setup for a do-it-yourself system utilizing the discussed sensors and communication protocols might look like this:

ComponentInterfaceNote
ESP32 DevKitC Various Powerful microcontroller with integrated WLAN/Bluetooth and many GPIOs.
pH Sensor Module (e.g., Analog module with BNC connector) Analog Inexpensive option, outputs a voltage signal. Often requires an isolated power supply and careful wiring to avoid measurement errors.
EC Sensor Module (e.g., Analog module with 2-pole probe) Analog Similar to the pH module. Galvanic isolation of pH and EC modules can minimize interference.
DS18B20 Temperature Sensor (waterproof) OneWire For water and possibly air temperature. Easily connectable to a digital pin.
Capacitive Water Level Sensor Analog/Digital Attached to the outside of the tank. Outputs analog values or digital switching signals.
BH1750 or similar light sensor (for Lux) I²C Easy connection via the SDA/SCL pins of the ESP32.
Voltage Converter / Level Shifter (e.g., Buck Converter 5V to 3.3V)   If sensors provide 5V signals and the ESP32 has 3.3V logic, or for stable sensor supply voltages.

The integration of these components requires basic knowledge of electronics, soldering, and microcontroller programming (Arduino IDE or PlatformIO). Careful planning of wiring and isolation is crucial to achieve precise and stable readings.

1.5 Conclusion

The informed selection and correct calibration of sensors are crucial for acquiring precise data, which forms the basis for all further automation and optimization. Understanding the underlying technologies, different qualities, and implementation details enables the operator to build a reliable and cost-effective monitoring system that ensures the long-term success of the smart garden. Equipped with these fundamentals, the next article can focus on smart irrigation and nutrient dosing.

 

Context:

Kontext: