Main

Groundwater constitutes 98% of global freshwater sources1 and 50% of the world’s drinking water2. Dependence on groundwater is highest in rural areas1 and in emerging economies3. However, the increasing salinity of groundwater, attributed to aridification and climate change4, poses a growing concern, particularly to low- and middle-income countries5. In arid and semi-arid regions, groundwater is commonly the only source of water in spite of widespread salinity beyond permissible drinking limits2.

Inland brackish water desalination is an underutilized process with potential to provide water to under-served communities. However, it is a challenge to effectively harness saline water in these settings. The majority of current desalination processes focus on large-scale, centralized plants with stable power supplies near ocean coasts. Approximately 84.5% of all desalination is within 50 km of a coast with 61% of that for seawater desalination6,7. However, around 60% of the global population lives further than 100 km from the coast8.

Renewable, brackish water desalination could benefit inland, resource-constrained communities, but current desalination solutions for these communities incur high operating expenditures (OPEX)9, capital expenditures10 and complexity due to large, necessary energy storage for high water production11. These barriers are especially prevalent at small scales (10–100 m3 d−1) resulting in low adoption despite high demand12 and decentralized users accounting for 80% of the water stressed population13. Eliminating batteries could lower barriers to adoption, however, this poses a challenge due to the limited operating power bandwidth of traditional desalination methods14,15 and the variable nature of renewable energy technologies.

The current industry standard desalination technology is reverse osmosis (RO), which traditionally operates in stable environments with large, constant power supplies; its inflexible control and high energy consumption renders it challenging to adapt to decentralized desalination16,17. RO cannot traditionally tolerate or fully harness power intermittency (such as from renewable energy) without large energy storage capacity. Some literature has shown variable flow control on RO units for power tracking in simulation18,19,20, but in practice21,22,23, operating constraints24,25 related to membrane pressure and flux lead to a lack of operating power bandwidth. These variable flow control approaches consequently still require energy storage to operate with intermittencies. Other technologies prevalent in low-income communities include solar-thermal-based methods and atmospheric condensation, but these are commonly limited to household applications with low water productivity26 (Supplementary Section 1).

The potential of electrodialysis for batteryless operation

Electrodialysis (ED) is an alternative separation technique that has a number of merits relative to RO. ED functions by flowing feed solution through a stack of spacers, each separated by selectively charged cation and anion exchange membranes (Fig. 1). An applied electric field drives the transport of ions across these membranes. The process is operated with either continuous flow of water through the stack or via batches of water recirculating through the stack27. This electrically driven—rather than pressure-driven—process causes reduced energy consumption28 and cost29 in brackish water and partial desalination scenarios. The energy efficiency of ED reduces solar or wind array sizes and thus capital cost and system footprint. The high water efficiency of ED is especially beneficial in water stressed regions6; this feature reduces brine volume, which is often challenging to manage and a relatively large source of operational costs30. Moreover, ED exhibits the capability to adjust to changes in feedwater concentration and modify the target output concentration. ED can effectively manage feedwater with higher turbidity, and its membranes can endure exposure to chlorine, commonly utilized for disinfection and antifouling purposes31. Notably, ED membrane lifetimes can extend to 10–20+ years and demonstrate resilience to a wide range of pH and temperature fluctuations32. These characteristics of ED collectively contribute to a reduction in maintenance and OPEX, proving especially valuable in decentralized, resource-constrained scenarios.

Fig. 1: Conceptual diagram of a batch electrodialysis system.
Fig. 1: Conceptual diagram of a batch electrodialysis system.The alternative text for this image may have been generated using AI.
Full size image

Where water is fed from batch tanks via parallel pumps into optional cartridge filters and then directed through a reversal valve network into the electrodialysis stack. In the electrodialysis stack, ions are transferred across selectively charged membranes: including pairs of a cation exchange membrane (CEM) and anion exchange membrane (AEM). The labels on the valve networks show potential hydraulic pathways, where in this depiction, channel configuration ‘A' is engaged and ‘B' is disengaged.

A key feature of ED that makes it well suited for renewable desalination is the ability to operate at variable power levels33, which can aid in reducing or eliminating the need for energy storage. Power distribution in PV-ED (equation (1a)) is composed of the input power (Psolar), the power consumed by pumping water (Phydraulic), the electrodialysis stack (Pelectrodialysis) and auxiliary loads (Pauxiliary). The ED system power consumption may be altered by varying voltage and water flow rate. Equations (1b),(1c) describe the scaling and sensitivity of power, Phydraulic and Pelectrodialysis, to changes in flow rate, Q, and the resulting stack current, i, from an applied voltage. Power scaling arguments are presented in further detail in Supplementary Section 2. Practical limitations to ED system power range are discussed in Supplementary Section 3.

$${P}_\mathrm{solar}={P}_\mathrm{hydraulic}+{P}_\mathrm{electrodialysis}+{P}_\mathrm{auxiliary}$$
(1a)
$${P}_\mathrm{hydraulic}\propto {Q}^{3}$$
(1b)
$${P}_\mathrm{electrodialysis}\propto {i}^{2}$$
(1c)

An optimally controlled, direct-drive, batteryless electrodialysis system closely tracks and operates at variable power levels to reduce or eliminate battery capacity while maximizing the water produced for any given power. The water production rate is dictated by the desalination rate. This rate is maximized when applying the maximum current and flow rate to the stack34. In batch or recirculating systems, maximizing these parameters ensures the fastest water production. However, in a continuous system, the upper limit of the flow rate is often constrained to achieve a target salinity before exiting the stack in a single pass. These two levers, current and flow rate, are nonlinearly related to overall power consumption, as represented in equations ((1a)–(1c)). For all systems, there is a dynamic constraint on the applied current known as limiting current (also known as diffusion-limited current), ilim. This is the current at which complete salt depletion occurs in the boundary layer adjacent to the membrane and can be modelled as a function of flow rate and salt concentration within the stack. Exceeding limiting current results in water dissociation. Limiting current is described in equation (2), where Cd is the concentration in the diluate (least concentrated) stream, and α and β are empirically determined coefficients which depend primarily on the ED stack, but also can be influenced by water composition.

$${i}_\mathrm{lim}\propto \alpha {C}_\mathrm{d}{Q}^{\beta }$$
(2)

Despite the features of ED that make it theoretically promising, an optimally controlled, direct-drive, renewable-powered electrodialysis system has never been demonstrated in practice without considerable energy storage due to challenges with the control strategy. Variable power ED demonstrations exist but have not achieved both maximal productivity and energy storage reduction in practice; challenges to energy storage reduction include reducing computational speed, accounting for auxiliary loads and mitigating errors accumulated due to controller model inaccuracy. Some researchers have directly coupled the ED stack to photovoltaic (PV) arrays but neglected pump and auxiliary power35,36. Other work has examined optimally balancing pumping and stack power but neglected other sources of power consumption37. This prior art used predictive, model-based methods to calculate the optimal flow rate and voltage for a given power. However, these methods were too slow relative to solar variability to practically eliminate abrupt power overdraws and thus minimize energy storage; this latency is due to the use of iterative numerical solvers, computationally intensive models and inherent predictive nature. Furthermore, this prior system used voltage control, which required a comprehensive model of the stack resistance updated in real time and an empirically fitted pump model; these models were used to predict power consumption but are hindered by error accumulation from environmental degradation over time. Consequently, both of these models require constant re-calibration. Despite studies concluding PV-ED is a cost-effective solution for brackish water desalination34,35,36,37, these limitations hindered the ability to operate direct-drive practically and with minimal energy storage. Thus, there is a knowledge gap in responsively (rather than predictively) and simply (without complex models) applying direct-drive control to variable power electrodialysis systems.

In this work, we present a responsive, simple control scheme, which enables direct-drive, renewable electrodialysis desalination. We additionally constructed a community-scale pilot system and demonstrated controller robustness and reduction in energy storage in a long-term (6-month) field trial on real groundwater wells in New Mexico amid a variety of solar irradiance and feedwater conditions.

Flow-commanded current control

We propose a simple, responsive control scheme (Fig. 2a) without the need for complex models, which maximizes water production rate while closely aligning with a variable, renewable input power source. This control scheme is described as follows. If the system has surplus power, Psolar, it commands (rather than predicts) an increased flow rate and consumes more hydraulic power (equation (1b)). The system then uses current control to apply current to the stack equal to limiting current with a user-determined safety factor. Limiting current is calculated (equation (2)) using simple models27,38 based solely on flow rate (Q) and diluate conductivity (Cd) measurements. This current command concurrently increases consumed electrical power (equation (1c)). The system continues to increase the flow rate and concurrently and consequently, the applied current density, until the sum of their power has matched the available power (equation (1a)). In the case where the system has a reduction in power, it continues to decrease commanded pumping power, and the resulting current density, until it has matched the available power. This direct-drive control scheme operates optimally while theoretically utilizing no energy storage.

Fig. 2: Controller design and implementation.
Fig. 2: Controller design and implementation.The alternative text for this image may have been generated using AI.
Full size image

a, Conceptual flow-commanded current control (FCCC) block diagram involving cascade control, where the inner loop is used to maximize desalination rate and the outer loop is used for power tracking. Summation operators are intentionally excluded to keep the sign convention generalized, to designer discretion. b, Detailed implemented control scheme. c, Designed realization of the control strategy on fundamental hardware related to a PV-powered electrodialysis desalination system with colours matching their representative colours in the aforementioned control loops. d, Prototype community-scale direct-drive ED system.

The control scheme employs cascade feedback control39. The use of feedback control greatly increases response speed compared with prior control strategies that used computationally expensive numerical solvers34,37. Feed-forward control is an alternative method that could be faster but requires accurate understanding of the plant, which is transient and difficult to accurately model in our case. The cascade control scheme features an inner and outer feedback loop, which maximize desalination rate and track power intermittencies, respectively. The outer loop commands changes in flow rate to track power, allowing practical flexibility to changes in power source and auxiliary system power consumption (valves, sensors). The inner loop applies the maximum allowable current using current control rather than voltage control, guaranteeing maximum ionic transfer and thus maximum desalination rate. The model of limiting current involves only multiplication of several values (equation (2)), making it computationally efficient. Using current control circumvents the need to implement a resistance model of the stack, which is often inaccurate with respect to changes over time such as from fouling. Further details are in Supplementary Section 4.

A practical control loop implemented in this study is shown in Fig. 2b. The control loop uses current, ibattery to indicate net power usage and track a reference current, iref, of zero. The battery current is the difference between used current, iused and drawn solar current, isolar. The used current includes the sum of hydraulic, electrodialysis and auxiliary currents (ihydraulic, ielectrodialysis and iauxiliary, respectively). The practical feedback loop includes a proportional-integral-derivative (PID) controller, with control effort fed into an electronic speed controller directing current to a brushless direct current motor for flow rate changes. Solar power is drawn via a maximum power point tracker connected to the photovoltaic (PV) panels.

Whereas operating at higher flow rates increases water production, it also increases the specific energy consumption (SEC). At high flow rates, hydraulic power exponentially increases at a greater rate than the increase in applicable current to the stack (Supplementary Section 2). However, despite this increased SEC, it is always more favourable for a direct-drive system to consume all of the available energy.

Single-day of operation

We fabricated a fully automated, community-scale system using commercially available hardware and integrated the aforementioned flow-commanded current control (FCCC) control strategy (Fig. 2b) to be tested in a field deployment. The system (Fig. 2c,d) was deployed for 6 months, autonomously operating at the Brackish Groundwater National Research Facility (BGNDRF) in Alamogordo, New Mexico, on different wells (feed salinities of ~1,800 μS cm−1 and ~4,000 μS cm−1 at wells labelled one and three, respectively) to determine the robustness of this theory among variable solar irradiance conditions. The fabrication, control and modelling are described in Methods and Supplementary Section 58).

An example day of operation can be seen in Fig. 3. On this day, the system tracked available power with 7.5 W mean error (Fig. 3a) visually noted by the closeness of the used and extracted solar power over time. The minimum system start-up (~700 W) and operating power (~500 W) restrict the start and end time: on this day, approximately 9:00 a.m.–5:15 p.m. In the middle of the day, faster batch times (Fig. 3b) occurred as a result of higher solar irradiance. High solar irradiance led to more extracted solar power, Psolar, and the controller consequently commanded higher flow rate and applied current, resulting in increased production rate. The converse effect was observed at the beginning and end of the day, where lower irradiance led to longer batch times and thus slower production rate. This variable operation throughout the day also led to fluctuations in energy distribution between subsystems, where hydraulic pumping and auxiliary power dominate during the edges of the day.

Fig. 3: Single example day of operation on 13 October 2022.
Fig. 3: Single example day of operation on 13 October 2022.The alternative text for this image may have been generated using AI.
Full size image

a, Used power tracking solar power in blue overlaid on top of subsystem power distribution in red hues, where the subsystem powers consist of the electrodialysis stack power, the hydraulic power, and the auxiliary power. Solar irradiance is plotted on the right axis. b, The aggregate water production, which appears in steps due to batch-operation over the day.

Full operational summary

Throughout the duration of the field trial, the prototype was able to operate in direct drive with minimal energy storage capacity (Fig. 4a) amid a wide range of solar conditions (Fig. 4b) without control system failure. The energy storage capacity required was not strongly correlated to variability in solar irradiance (Supplementary Fig. 6), indicating the control scheme was robust and independent of a variety of solar power fluctuations. The prototype was able to harness 93.74%, on average, of the electrical energy from the solar panels (Fig. 4c) and thus had higher overall energetic efficiency and water productivity than prior art (later discussed in Fig. 6) despite having minimal energy storage. This was accomplished with product salinities consistently below the target of 1,000 μS cm−1, averaging 966 and 962 μS cm−1 on wells one and three, respectively.

Fig. 4: Overview of the performance over long-term operation from 4 August 2022 to 9 February 2023.
Fig. 4: Overview of the performance over long-term operation from 4 August 2022 to 9 February 2023.The alternative text for this image may have been generated using AI.
Full size image

a, Worst-case daily energy storage capacity required. b, Variability index, which represents solar irregularity54. c, Energy utilization, the percent of the available energy harnessed by the system defined as the percentage of used energy to extracted solar energy; in cases where it is above 100%, the used energy exceeded the extracted solar energy and drew excess energy from the battery. d, SEC: the energy to produce 1 m3 of desalinated water. e, Total water production for the day. Days of inactivity due to insufficient irradiance or maintenance were removed. A vertical line is shown to differentiate days of operation on well one and well three.

On wells one and three, the system produced an average of 5.29 and 2.18 m3 of water per day (Fig. 4e) using 8.35 and 6.54 kWh, resulting in an SEC (Fig. 4d) of 1.58 and 3.65 kWh m−3, respectively. However, SEC was increased by a variety of system defects including internal leakage within the prototype stack. We observed a stack current efficiency (the ratio of the mass transfer to the applied current) of 40% in contrast to the marketed 90%+ (V. Pavlovic, N. Moe, J. Barber, personal communication). Additionally, the system was limited by hydraulic and auxiliary inefficiencies: the ED stack used on average 8% and 19% of the overall energy, with pumping consuming 42% and 37% and auxiliary consumption at 50% and 45%, on wells one and three, respectively. Auxiliary consumption includes the converter losses, the electrode rinse and antiscalant pumps, control and sensing (Supplementary Fig. 6). The pump hydraulic efficiency is the ratio of hydraulic energy out (pressure drop times flow rate) to electrical energy in (current times voltage). The pump hydraulic efficiency was 10% on average due to its variable operation; centrifugal pumps are most commonly designed for fixed operating conditions. Finally, it should be noted that other direct-drive systems often oversize their solar arrays and run at constant power, thus under-utilizing the available energy; this underutilized energy is not often captured or reported in SEC metrics.

Energy storage reductions

In practice, with commercially available, off-the-shelf components, complete elimination of energy storage is limited by practical considerations including actuator response speed, the control and sensor sampling frequencies and the communication methods. Thus, we conducted system identification on the prototype to estimate the minimum energy storage required (Supplementary Section 8). We used the settling time of slowest dynamic response (the diluate conductivity to changes in current) and our maximum system operating power for a conservative battery sizing estimate (Supplementary Fig. 5f). We additionally constructed a model of the system dynamics to simulate a holistic system response (Supplementary Figs. 4 and 5). The energy storage identified for conservative and model-simulated sizing methodologies were 0.038 and 0.006 kWh, respectively. When compared to our long-term data (Fig. 5), both the model-simulated and conservative battery sizing estimates support the majority of power variability seen in our field trial, covering 99.8% and 99.3% of discharges, respectively; this means our simple energy storage sizing method for FCCC covers nearly all of the power mismatches in practice. On the basis of these predictions, we ran the system on a 0.12 kWh DeWalt drill battery for several days without failure. The drill battery was oversized but low cost, widely available and had an appropriate current rating.

Fig. 5: Logarithmic histogram showing the field pilot energy discharges and charges required over long-term testing compared with the predicted energy storage requirement.
Fig. 5: Logarithmic histogram showing the field pilot energy discharges and charges required over long-term testing compared with the predicted energy storage requirement.The alternative text for this image may have been generated using AI.
Full size image

The predicted capacities for the conservative and model-simulated estimate are 0.038 and 0.006 kWh, respectively. The worst-case energetic overshoot over this 6-month time period was 0.408 kWh. The pink shading indicates discharging from the battery and the blue shading indicates charging.

The ratio of battery capacity to production rate and battery capacity to rated system power of this prototype is shown in contrast to prior PV-RO and PV-ED systems in Fig. 6. Figure 6 was compiled using multiple review papers10,24,40,41,42,43,44,45 with additional investigations into their source materials (further detailed in Supplementary Table 3).

Fig. 6: Comparison of batteryless, direct-drive FCCC PV-ED to PV-RO and PV-ED systems in prior art.
Fig. 6: Comparison of batteryless, direct-drive FCCC PV-ED to PV-RO and PV-ED systems in prior art.The alternative text for this image may have been generated using AI.
Full size image

a, Logarithmic plot of daily production rates and associated battery capacities. For increasing production rate or larger systems, larger energy storage is often needed for traditional systems in contrast to FCCC PV-ED. b, Logarithmic dot and boxplot of battery to rated system power ratios. FCCC PV-ED is lower in energy storage to rated system power ratio than literature (refs. 10,24,40,41,42,43,44,45).

The ratio of energy storage to operating power for FCCC PV-ED is 0.015 kWh kW−1. The ratio of energy storage to operating productivity is 0.013 and 0.022 kWh (m3 d−1)−1 for well one and well three, respectively. Direct-drive PV-ED using FCCC uses 99.8% less battery per rated power and over 99.6% less battery per production rate than the median PV desalination systems in literature (7 kWh kW−1 and 3.9 kWh (m3 d−1)−1, respectively). These results support the hypothesis that implementing this control scheme results in a negligible fraction of energy storage, whereas still achieving high productivity compared to literature, enabling practical, batteryless renewable desalination.

Our experimental system architecture had a levelized cost of water of US$6.37 m3 and US$10.89 m3 for wells one and three, assuming a conservative system lifetime of 10 years, with a 40% efficient electrodialysis stack, using off-the-shelf components at retail price (Supplementary Table 2). For reference, <20 m3 d−1 on-grid brackish water RO systems are US$5.6–12.9 m3(ref. 45) and literature reports PV-RO at US$11.7–15.6 m3(ref. 46) and PV-ED at US$10.4–11.7 m3(ref. 47), without commercial markup. This shows we can achieve cost competitive, high-productivity desalination with the added feature of minimal to no batteries using ED (reducing maintenance and increasing adaptability). Furthermore, there is room for system cost reduction via optimization, architectural simplification and economies of scale, as our prototype was designed to demonstrate the controller rather than minimize cost.

Discussion

We created and validated a new, simple control scheme that enables direct-drive electrodialysis desalination with variable power such as renewables. The scheme was implemented on a fully automated system and shown to track power closely enough such that energy storage less than 0.069 kWh (smaller than a drill battery) was sufficient to run a 4.5-kW rated system.

Similarly sized, brackish water, ‘batteryless’ RO systems report requiring using some small batteries for the maintenance of controls and sensing10,24,40,41,42,43,44,45. The minimum energy storage of this prototype is comparable to or smaller than what is reported in these studies; our prototype’s energy storage can thus be considered negligible and comparable in size to state of the art ‘batteryless’ (direct-drive) reverse osmosis systems. The prototype additionally featured a battery capacity to water production ratio over 99% less than the median value existent in literature, indicating high production rates despite little energy storage. This advancement enables an entirely different operating scheme than presented in prior art—a reactive, rather than predictive, ED control technique without complex models—allowing immediate variable power tracking and reducing battery capacity.

FCCC could also be applied to directly link variable power sources to other emerging electrochemical membrane applications (for example, selective ED for agriculture, high temperature and high salinity ED for produced water from oil and gas, bipolar membrane ED for carbon capture, electrodeionization for ultra-pure water in semiconductors and field hospitals and potentially even fuel cells for hydrogen production. Finally, the utility of FCCC PV-ED as a partial desalination step before large-scale RO plants could also be investigated in future work.

A limitation of this work is that the effectiveness of FCCC and subsequent battery capacity required depend on the system components chosen. Actuators, including the electrodialysis stack power supply and the pumps, must be sized appropriately with respect to the energy source to utilize the desired range of power variability. For instance, an undersized pump may not capture the full bandwidth of power but would be less expensive. However, incorporating a slightly larger pump could enable exponentially greater power tracking bandwidth (equation (1b)) for a marginal increase in cost.

The long-term field test under authentic solar and challenging groundwater conditions presented herein demonstrates that FCCC can bridge the gap between renewable energy sources and desalination, enabling high production, batteryless, sustainable desalination. This work has the potential to broaden the reach of desalination to resource-constrained communities worldwide while also providing a catalyst for larger industrial desalination plants to economically decarbonize.

Methods

System fabrication

We constructed a fully automated, batch electrodialysis desalination system using commercially available hardware based on optimization from ref. 48 for a community-scale application but incorporated modified controls (Fig. 2b), sensing (Supplementary Table 1), communication and improved hydraulic architecture to implement and test FCCC (Fig. 2d and Supplementary Fig. 2). A community-scale system size was chosen to meet the requirements of humanitarian crises and remote development scenarios49 and is a size the authors have prior experience piloting.

We integrated a smaller footprint (relative to industrial plants), high production rate, commercially available stack (SUEZ WTS V20 prototype stack (2022) with 150 cell pairs) to test the control scheme. The stack contained capacitive carbon electrodes50,51, which reached charge saturation at approximately 80,000 coulombs. Our reversal mechanism was triggered if we reached this saturation threshold. However, we sized the batch tank volumes to reverse only between batches; reversing during the middle of a batch would cause remixing of high and low salt concentrations in the tanks, decreasing the energy efficiency. Reversing after every batch completion still results in partial remixing of solutions because of residual concentrate and diluate within the stack and piping; these losses can be avoided with shorter pipes, smaller stacks, cone- rather than flat-bottom tanks and by considering reversals after a series of batches. This prospect is possible with conventional metal electrodes (which do not reach charge saturation and rather operate with Faradaic reactions). However, reversing less frequently also creates more potential for fouling. The batch volumes in our pilot system were consequently designed to be 300 l as a function of our feed and target salinities. We additionally used equal sized diluate and concentrate batch volumes with conservative recovery (50%) relative to the capabilities of ED for convenience, however, it is common to run ED systems at higher recoveries (up to 95% (ref. 27)). The capacitive electrodes facilitated the use of feed salinity as the electrode rinse, which was periodically fed and drained via solenoid valves.

The remaining components were sized based on the stack chosen. The two pumps (3SV4GA30 Xylem Goulds Multistage centrifugal) were sized according to the stack flow rate ranges. The power electronics were sized according to the stack voltage and current ranges. The solar panels were sized to provide the maximum actuator (pumps and stack power supply) power at peak irradiance. We thus integrated six 280-W solar panels (SolaRover) available at BGNDRF. Two 1.2-kWh batteries were connected for maintenance and code adjustment during hours in which solar was unavailable; their size was chosen out of convenience and availability of old laboratory hardware. A 120-Wh drill battery (DeWalt) was used for demonstrating the minimal energy storage required by the direct-drive control scheme; its size was chosen based on the system identification and modelling conducted (Supplementary Figs. 4 and 5).

Our prefiltration architecture was also designed to meet requirements set by the stack manufacturer. This architecture included cartridge sediment filters and ion-exchange resin cartridges (iSpring FM25B) for removing >5-μm particles and producing <5 mg l−1 iron. On well three, we dosed approximately 14 ml per batch of antiscalant (SUEZ Hypersparse MDC776).

A full process and interface diagram including more details on system design can be found in the supplement (Supplementary Fig. 2) to the interested reader. These include additional sensors, the communication network for remote monitoring and any additional component specifications (Supplementary Table 1).

Controller integration

Both control loops (inner and outer loop) were implemented on a Koyo Click PLC, chosen for its low cost, familiarity to industry practitioners and simple ladder logic programming structure. We additionally employed a higher-level state machine (Supplementary Table 1) within the PLC main programme, incorporating some insights from refs. 34,48 for managing the batch states, errors and system start-up and nighttime shutdown.

The inner loop sensing scheme was implemented with an inductive flow meter (ProSense FMM100-1001) placed immediately before the stack inlet and toroidal conductivity meter (Sensorex TCS3020) placed directly after the desalination stack on the diluate stream. Both are read over Modbus TCP to the PLC at 100 Hz sampling frequency. A subroutine was built to determine and command limiting current using pre-programmed constants (α, β from equation (2)) based on stack geometry, spacer, membrane and solution characteristics. Using the constructed system and feedwater, we acquire α and β by measuring the limiting current at various flow rate and conductivity conditions following methodology from ref. 38. However, many other methods for modelling limiting current exist.

The limiting current equation was fit within 0.22 A root mean squared error of the actual identified limiting current values; the equation was fitted to the full operational range of flow rates and input salinities at our field site (Supplementary Fig. 3). The validity of the empirically fit limiting current equation should be considered in the context of the application; an application with wide ranges in salinity, pH and changes in composition may have worse accuracy to the fit equation. If these regions are not within the safety factor applied, over-limiting current may be applied. Solutions to avoid over-limiting current include larger safety factors, adjusting the equation to account for component compositions or superposition of multiple limiting current models. Limitations also include the need to empirically identify α and β parameters, however, there are values in literature that generally fit a variety of stack sizes and behaviours38.

The outer loop PID was implemented by using a built-in function within the PLC to track an analogue hall effect current sensor (Chen Yang CYHCT-C3TC) placed on the positive lead of the battery terminal, with a setpoint of zero; any current into the battery would indicate excess solar power and lead to an increase in pump speed. Any current out of the battery would indicate system overdraws and ramp down the pump speeds. A voltage sensor was considered but was not high enough in resolution given the relatively flat voltage–charge curve of a lithium ion phosphate battery; voltage sensors, however, could be better suited for capacitor banks or when using an integrated controller-maximum power point tracker architecture.

We set the PID constants by first using the operating bandwidth to determine integral gain heuristically52; these equations are detailed in Supplementary Section 5. We then increased the proportional gain until we observed instability and reduced it by a factor of safety from the unstable gain point. The tuned PID gains were Kp = 10, Ki = 1 and Kd = 0 (proportional, integral and zero derivative gain, respectively). This tracking was stable throughout all days of operation. Figures regarding the tuning can be found in the supplement. The outer loop is for power tracking and is not limited solely to PID control; other methods (for example, nonlinear, on–off) may be implemented. Feedback controller PID tuning using heuristics is useful for ease of operator implementation, but many alternative methods including frequency domain loop shaping, pole-zero cancellation and so on can be employed depending on user requirements.

System identification and modelling

Using the constructed system, we conducted system identification on the hydraulic and stack dynamics using step responses on the pump speed and stack current commands (Supplementary Fig. 5a–d). We aimed to construct (1) a simple, conservative battery estimate using the longest system settling time and maximum system power and (2) an estimate using a simulation-based construction (MathWorks Simulink). Feedwater from well three was utilized for the system identification. The longest settling time was the stack conductivity response to current changes (approximately 30 s) and was multiplied by the maximum system power (4,500 W) to determine the energy capacity required (0.038 kWh) (Supplementary Fig. 5f). The simulation-based construction used four plants that were identified: the hydraulic flow rate and power response to pump speed commands and the conductivity and power response to stack current commands (Supplementary Fig. 4). These plants were incorporated with a PID and associated time delays to simulate the overall system response. The overshoot from the step down (Supplementary Fig. 5e) was greater than the step up, and the energy associated with this worst-case overshoot from the step down was utilized to predict the energy capacity required (0.006 kWh).