LED PEDD Discharge Photometry: Effects of Software Driven Measurements for Sensing Applications

This work explores the effects of embedded software-driven measurements on a sensory target when using a LED as a photodetector. Water turbidity is used as the sensory target in this study to explore these effects using a practical and important water quality parameter. Impacts on turbidity measurements are examined by adopting the Paired Emitter Detector Diode (PEDD) capacitive discharge technique and comparing common embedded software/firmware implementations. The findings show that the chosen software method can (a) affect the detection performance by up to 67%, (b) result in a variable sampling frequency/period, and (c) lead to an disagreement of the photo capacitance by up to 23%. Optimized code is offered to correct for these issues and its effectiveness is shown through comparative analyses, with the disagreement reduced significantly from 23% to 0.18%. Overall, this work demonstrates that the embedded software is a key and critical factor for PEDD capacitive discharge measurements and must be considered carefully for future measurements in sensor related studies.

Throughout this literature, however, there has been no study related to the effects of embedded software implementations [31]. In lieu of this, most reports cite previous studies (including the seminal works of this field) on the subject [1,2]; however, these do not provide extensive or in depth accounts of the implemented software. What is clear is that different use cases have been identified, but not all aspects of this technique have been rigorously established. As timing is a critical aspect for a PEDD discharge measurements, a task the embedded software is responsible for, there are many factors that can impact measurements. This can be significant for the sensing fields requiring quantitative measurements, e.g., the physical/bio/chemical sensing domains.
Given that the bulk of the reported implementations of PEDD in the literature involve sensing [32], it is considered necessary to do the same here in order to explore the effects of

Components and Characterization
The ISO 7027 standard for turbidity measurements outlines conditions under which turbidity should ideally be measured [47], and is used to guide this study. To conform with ISO 7027, a high intensity 860 nm emitter LED with a small emission angle (±3 • ) was sourced-SFH 4550 (OSRAM Opto Semiconductors, Regensburg, Germany). The LED emission spectrum was determined from the manufacturer's data sheet, with data extracted using WebPlotDigitizer v4.3 (automeris.io). For the LED in detector mode, its External Quantum Efficiency (EQE) was measured with the device under short circuit conditions using monochromatic illumination (QEX10, PV Measurements, Boulder, CO, USA) from 700 nm to 900 nm, in increments of 10 nm.
A similar process, using the same light source, was performed using the LED in PEDD mode in order to examine and contrast the response from photo-voltaic (PV) measurements. This involved illuminating placing the LED under monochromatic light, again from 700-900 nm in 10 nm increments, but with data collected through the microcontroller rather than the QEX10 DAQ. The attained values were corrected based on the light intensity at each wavelength, measured independently using a calibrated photodiode (Hamamatsu S1010BR, Tokyo, Japan).

LED Detection Principle
The principle of detecting luminous intensity via a LED in reverse bias using a microcontroller has been known for some time now [1,2]. For context, Figure 1 shows the circuit schematic of the detector LED and Figure 2 presents an annotated version of a typical charge/discharge profile. The file 'firmware.ino', available in the Electronic Supplementary Information (ESI), provides the embedded code used in this study, with Table 1 listing all of the relevant functions associated with the undertaken experiments. The code was developed from an exact description of the process reported in the literature [1,2,48,49] and will be denoted as the 'uncorrected T s ' approach for reasons that will become evident later. Briefly, the detector LED is first charged in reverse bias mode ( Figure 1) by the microcontroller's I/O being set as an output for 100 ms. This time was heuristically determined for the LED used in this study. Subsequently, the I/O is switched to input mode, allowing the photo-capacitance to discharge over time (t Discharge ), see Figure 2. As it discharges, the logic state of the I/O is repeatedly checked (t C 0 . . . t C N ) and a software counter (typically 16-bit) is incremented when above the logic threshold. For example, in the case provided in Figure 2, the counter would report 7 as the measurement value. In addition to this, the total time taken for a measurement to take place (sampling period, T s ) is also recorded to adhere to the format of results expressed by studies in the literature [48,50].

Turbidity Measurement
The 1000 NTU and 100 NTU turbidity calibration standards were sourced (Formazin, TURBP1000 and TURBP100, respectively) from Sigma Aldrich, stored in a refrigerator until being diluted using purified water (Milli Q) to produce varying turbidity concentrations. The 0-1000 NTU range was prepared in steps of 200 NTU and within this a 0-100 NTU range was prepared in steps of 20 NTU to examine a lower sensing range. The solutions were transferred into fresh cuvettes where the maximum (1000 NTU) and minimum (0 NTU) suspension cuvettes were placed in the fabricated chamber ( Figure 1). Here, a resistor of 56 kΩ in series with the emitter LED was found to maximize the dynamic measurement range of the detector. After that, each suspension was measured in turn and ∼10 measurements were recorded. This process was repeated in triplicate in order to investigate reproducibility. Table 2 presents three methods used to read the I/O status and perform the comparison check during a measurement. As mentioned, the embedded software used in this study, with the identified function listed in Table 1 can be found in the ESI, all of which follow the discharge model discussed in Section 2.3. For reading the I/O status, Method 1 uses the Arduino standard library function 'digitalRead()', while Methods 2 and 3 accesses the registry directly using bitwise operators. For the comparative operation, the 'if' statement is the most commonly used and is part of Methods 1 and 2, while the switch statement was considered and implemented as part of Method 3. While it can be argued that the Wiring style can implement the switch statement, any effect will appear as a difference between Methods 2 and 3.  Figure 3 presents the emission spectra (at I F = 100 mA) of the SFH 4550 LED, along with its electrical response, measured in PV mode and in PEDD mode. A 20-30 nm Stokes shift is seen between the emission peak and the peak of the EQE in PV mode, which is typical for inorganic semiconductors (see Figure A1 in Appendix A for the JV Curve), and similar to observations by Anh-Bui [51], Li [52] and Tymecki [49,53]. It is noted that the EQE spectral band (PV mode) is wider than the emission by ∼60-70 nm, which is counter to claims in the seminal study of Lau et al. that "an LED is sensitive to all wavelengths of light equal to or shorter than the emission wavelength" [2]. On the other hand, such a response agrees with other reports [51,53], which clearly showed that the responses from LEDs in PV detector mode are poor at lower wavelengths, and typically have a FWHM of only ∼40-60 nm. While it is known that most semiconductors have very broad absorption for photons of greater than the bandgap energy, this may be mitigated by other components in the LEDs, such as charge selective layers, which may absorb some of these wavelengths before the photons can reach the active material. It is noted that in some of Lau's subsequent work [54,55], a multi-wavelength emitter LED system was used, with a single IR detector and a sensitivity of greater than ∼60-80 nm.

LED Spectral Sensitivity
The PEDD mode measurement is shown here as the reciprocal of the time constant for each wavelength, divided by the intensity determined by our calibration diode. The rationale for this approach is explored in further detail in the ESI, see Figures A2-A4 in Appendix B for this process. There is considerable disagreement between the modes of measurement, i.e., PEDD discharge and PV modes, with, to the best of our knowledge, no previous studies comparing these different modes. This difference may be, at least in part, due to non-linear responses (with respect to light intensity) in PV mode, which is explored in more detail in the ESI.
This could also be due to the use of a reciprocal value increasing sensitivity to the absorption tail. Consider that the PV measurements relies upon light induced generation/recombination and exceed the energy threshold in order to surpass the band gap, while in the PEDD mode, there may be more opportunity for trapped charges (related to defect states) to facilitate relaxation. While outside the scope of this study, this highlights that further, in depth, investigations into LED spectral range/sensitivities (including differences in measurements being conducted via PV and PEDD mode) is warranted. Ultimately, for this study, the primary purpose of Figure 3 is to validate that the emitter and detector (in PEDD mode) are within the ISO recommended spectral range [47] and that they overlap-perhaps more so in PEDD than PV mode.   Figure 4a in terms of discharge counts, in line with the bulk of studies in the literature [10][11][12]56]. Each of these provide a response that can be well fitted to a power growth function using a model of y = Ax τ + y 0 (R 2 ≥ 0.998), with parameters reported in Table 3. The data show that each method varies in their discharge count quantity when examining the same turbidity concentrations. This can be ranked from highest to lowest as Method 3, to 2, to 1, which implies that Method 3 can perform operations faster than Methods 2 or 1 and therefore can offer a higher resolution. As a result, if one wants to achieve the highest resolution and/or perform multiple measurements with a minimized sampling period then the 'switch-memoryAddressing' operation is recommended.
Considering that timing is the key factor in estimating the turbidity concentration using a PEDD setup, measurement of the samples was repeated and the sampling periods (duration for full measurements) were recorded, see Figure 4b and Table 3 for model parameters. While there is a difference in terms of implemented method, the sampling period was not constant and in fact varied for samples with different turbidities. This will introduce error as the PEDD measurement technique is time based on the discharge time, inferred from the number of cycles counted. The significance of this is that the response is not proportional to the turbidity concentration alone, but rather to an additional influencing factor attributed to the operational timing, which appears to be exponential in nature. When performing successive measurements, the very fact that the sampling period can vary, temporal data processing such as Fourier analysis/filtering would therefore not be possible.   Figure 4 for the uncorrected and corrected measurement sampling period (T s ). The most likely reason for the timing issues observed previously is based on the software operations. Referring back to Figure 2 for explanatory purposes, prior to the discharge profile crossing the logic threshold the operation includes the software increment, as described in Section 2.3. While such operations are rapidly executed, it is not clear whether this could have an effect on determining the sampling period. In the case of Figure 2, there would be a larger temporal weighting on the first 8 I/O logic checks (t C 0 . . . t C 7 ), and less thereafter (t C 7 . . . t C N ). In order to investigate this, an increment operation was added when the discharge profile was below the logic threshold (see ESI and Table 1 for the relevant code) with the experiments repeated. Figure 4c,d presents the calibration of the system with respect to the turbidity standards, which was implemented here in order to achieve a constant sampling period. As before, power trends are suggested in Figure 4c and confirmed via fitting of the model, R 2 ≥ 0.998 (see Table 3). Please note that methods 2 is difficult to see in Figure 4c. The reason for this is because methods 2 and 3 are in very good agreement (as per parameters in Table 3), resulting in method 3 obscuring method 2's presentation. For the discharge count data, it appears that there are less equivalent discharge counts (vertical axis) than shown in Figure 4a, which implies a lower sampling rate and therefore a lower resolution-also indicated through the parameters in Table 3. This directly confirms that the time for an increment to take place does affect the measurement. What is lost in resolution, however, is gained through a constant sampling frequency as seen in the parameters and Figure 4d, with a range visually less than the timing data in Figure 4b. The proposed correction allows for a minimization of the sampling period variation, which was observed from the previous approach. Figure 5 presents a comparison of the turbidity measurements between the literature derived (uncorrected T s ) approach (Figure 4a,b) and the proposed (corrected T s ) approach (Figure 4c,d). Figure 5a shows that there is a clear difference arising from the software method employed, which is in line with observations discussed previously. For uncorrected turbidity measurements, the resolution was affected by ∼67% (method 1) and 26% (method 2), with respect to method 3. When employing the proposed approach, the relative discharge counter difference (with respect to the uncorrected Method 3 data) decreased to 30% (method 1) and 63% (methods 2 and 3), demonstrating that the uncorrected approach leads to softwares being executed differently, with relative performance extending to 70%. For the timing of the measurements, Figure 5b shows that the sampling period range (T s max − T s min ) differs with the uncorrected approach (as much as 67%), while with the correction in place the sampling period has less than 1 µs difference over the entire range. This is a strong indication that the sampling period varies considerably with respect to the uncorrected approach by demonstrating that the embedded programming operations can affect the timing considerably, which has not been addressed by the sensor literature. This is supported by the data from the corrected approach where the discharge timing sampling period difference is considerably and relatively small.

Comparison via Photo-Capacitance
In order to further explore the timing aspects as discussed above in more detail, the photo-capacitance of each measurement per method was examined for both the literature derived approach (Figure 6a) and the proposed approach (Figure 6b). This was calculated by the fitted model: V = V 0 e −t/τ (τ = T NTU C, V 0 = 5 V, V TH = 1.5 V), with the photo-capacitance expressed as C = − t /T NTU ·ln(1.5/5).
For the literature derived/uncorrected T s approach in Figure 6a, it can be seen that there is a disagreement between the photo-capacitance calculated using each method, which is more prominent at lower NTU values, as shown in the inset. Considering that the physical processes and parameters are constant at each turbidity concentration, the calculated photocapacitance should agree regardless of the method employed. In this case the methods disagree by up to 23% or 160 pF, which is a factor that can impact estimations of the sensory target.
For the proposed/corrected T s approach in Figure 6b, the results were processed in the same way as before-to calculate the photo-capacitance. This shows that regardless of the implemented method, the estimated photo-capacitances are in excellent agreement, with a disagreement as low as 0.18% when compared to 23% in the uncorrected T s approach. Given the strong agreement between each methods, due to the corrected approach, a calculated percentage relative error between both approaches was found to be 9%, 20% and 26% for Methods 1, 2 and 3, respectively.

Graphical Comparison
In order to understand the implications of the timing effects more clearly in a graphical manner, consider that when measuring the same turbidity concentration the LED discharge profile should remain be identical, regardless of the software (method or correction) approach adopted. Figure 7 (middle) presents the measured values and extrapolated discharge profile of the 0 NTU and 1000 NTU samples expressed in the time domain. The corresponding results from the uncorrected approach is shown in Figure 7 (bottom) as horizontal bars. For each method a pair of bars of the same color (conforming with the color convention adopted previously and identification number as per Table 2) represent the results from the 0 NTU sample (top bar) and the 1000 NTU sample (bottom bar). Each bar's full width represents the sampling period, while the solid color (left segment) represents the proportion above the logic threshold, in line with the vertical dashed lines provided in the discharge profile. From this, it is clear that the reported time varies with respect to turbidity concentration (pronounced colored section), which is expected. Additionally, the sampling period (full bar width) also varies with respect to turbidity concentration. This shows that with the uncorrected T s approach, the signal is not proportional to the turbidity concentration alone. For the corrected T s approach, it is clear that there is strong agreements between the 0 and 1000 NTU sampling periods independent of the implemented method, which means that the resulting signal is directly proportional to the turbidity concentration under investigation and has removed the second/unwanted proportionality issue, albeit at the expense of a slightly extended T s .
The implications of this allows for temporal data processing such as Fourier analysis/filtering, which would not be possible with the uncorrected T s approach. This can be a significant issue when performing successive measurements if there is a rapid change in conditions. While the implementation of a hardware timer can control the starting time of the discharge and counter/timer, it cannot address the secondary issue-that the sampling period varies with respect to turbidity concentration, yet the proposed correction proposed herein evidently has.
One aspect of PEDD research that has gone unaddressed in the literature is the inability to assess implemented methods due to unpublished code. When following the methodology section exactly, it is clear that there are differences in implementable methods and a constant/non-constant sampling period approach, which can evidently affect the results as shown previously in this study. An interesting question arising from this is reproducibility of the studies given the unknowns and relative differences between methods and approaches. To investigate this possibility in the context of turbidity estimations Figure 8 presents a heat map comparing all methods, i.e., each of the three methods and both uncorrected and corrected sampling periods. To explain, the fitted model of one approach/method was used to predict the turbidity concentration using the measured values of another. The presented values represent the maximum percentage relative error of this prediction. When each method is compared against itself, the values are 2.2%, which is relatively low. Depending on the approach/method, this can extend up to 45% error in the case of using uncorrected method 3's model to estimate the corrected method 1's turbidity data. This opens up the question as to the reproducibility of previously published studies in the literature given the incomplete or unpublished code.

Discussion
It is understandable why studies in the literature have not accounted for the timing issues discovered in this study. In many cases, the primary focus of reported studies has been to explore the capabilities of the PEDD approach when investigating another sensory target/application. In sensing studies a calibration model is achieved with the adoption of the general PEDD detection procedure [1,2,48], although the embedded software is not reported. This is concerning as without a complete account one cannot reproduce these studies, as different software implementations can impact sensor characteristics such as resolution, LOD or sensitivity, which therefore cannot be fully verified. For instance, Table 4 presents these sensory characteristics for each approach and method explored in this study [57]. In the discharge time domain it can be seen that the corrected T s approach yields more appealing characteristics with higher sensitivities, lower limits of detection and a greater agreeable range compared to the uncorrected T s approach, which is in line with previous discussions. This also shows that there is a larger disagreements between the uncorrected methods, which only illustrates the need for a standard method of measurement for PEDD sensing. Furthermore, note that better analysis appears to take place using the discharge time domain over the counter domain. While the counter results shown in Figure 4a,c appear to show less sensitivity, when converted to an SI measurement unit (ms in this case) a more reliable analysis can result. It is therefore recommended to adopt the time domain for future analyses.
As the work in this study has shown, there is no ubiquitous procedure when it comes to PEDD implementations with the choice of methodology and timing demonstrated herein to have a considerable effect on the response characteristics. The PEDD capacitive discharge technique has been identified as a low-cost and cost-effective method for sensing purposes [58] and allowed for a large number of studies to take place, as reviewed in the introduction section. The embedded software has, however, been a missing reported factor and demonstrated herein to play a significant role. Given that the sensing domain has focused primarily on chemical and biological sensing, it would be interesting to explore the software effects on targets such as those highlighted earlier in the introduction or by others in various reviews on the subject [50,[59][60][61].
The timing effects would also be important to the research community adopting LEDs as optical communication devices [62][63][64] and warrants exploration. In all applications outside of controlled environments, noise can be a considerable issue for any detection device. While a detector LED can be quite sensitive [8,51], it relies on a very small currentoften discharged from a capacitance in the pico-Farad range-and therefore prone to electromagnetic interferences, which may be one reason for large error bars found in previous studies [5,65]. Filtering this is not possible with a variable sampling period, which highlights the importance of a constant sampling period/frequency and therefore highlights the importance of the work in this study. Finally, the full exploration of all factors associated with the PEDD capacitive discharge technique is necessary for this to become a sensing standard.

Conclusions
This work has demonstrated the impact of the embedded software in measurements of a sensory target when implementing the PEDD capacitive discharge technique. This was done by first performing absorbance measurements of turbidity samples from 0-1000 NTU, based on the operation described in the literature, and implementing multiple software methods to achieve this. The choice of method involved was shown to affect the detection performance in terms of resolution by up to 67%, which can therefore affect the LOD and sensitivity detection capabilities. The results have also shown that the sampling period was variable with respect to analyte concentration. This was demonstrated by a disagreement of the photo-capacitance by the adopted methods of up to 23%. Timing effects were recognized and corrected using the proposed approach in this study, which resulted in a constant sampling period/frequency, evident from a maximum disagreement between the photo-capacitance estimations of less than 0.185%. A comparison between both approaches has shown that the error associated with the uncorrected approach can be as high as 26% (%RE), meaning that the implemented software, and operations thereof, play a significant role in the accuracy of PEDD capacitive discharge measurements and must be taken into consideration if a standard is to be accepted by the sensing community-or indeed established by standards organizations.

Acknowledgments:
The authors wish to acknowledge support from the following teams/entities. The SMART Infrastructure Facility team for their support-Johan Barthelemy, Hugh Forehead, Benoit Passot, and Pascal Perez. In addition, support from Global Challenges under the iOyster fund and Blue Futures for material support. The Strategic Water Infrastructure Lab (SWIL) for their help with laboratory facilities-particularly Ling Tie and Faisal Hai.

Conflicts of Interest:
The authors declare no conflict of interest. The funders had no role in the design of the study; in the collection, analyses or interpretation of data; in the writing of the manuscript; or in the decision to publish the results.

Abbreviations
The following abbreviations are used in this manuscript:   Figure A2: The beam of monochromatic light (300 W Xe lamp, PV Measurements QEX10) was masked to its smallest size (6 × 6 mm) before being focused to a narrow point. An LED was placed in the test position, with the top of the dome at the focal point of the beam. For each wavelength 42 measurements were taken using method 1 for each wavelength.  Figure A3: These measurements of the counts before the LED output voltage dropped below the threshold value are inversely correlated to the amount of charge generated in the active layer of the device, i.e., the greater the charge generated, the faster the voltage decay occurs. As such, the reciprocal of the above values can be plotted as below. It is important to note that the Xe lamp does not have equal intensity at all wavelengths, and as such this needs to be accounted for. The light intensity as a function of wavelength was independently determined using a calibrated photodiode (Hamamatsu 1010BR). Figure A3. Inverse of discharge counter and light intensity. Figure A4: The resulting spectra is comparatively smooth and featureless, as would be expected from an inorganic semiconductor, particularly when compared to the direct, PV mode, measurements. PV mode measurements show a dip at~830 nm, which is where the excitation beam is brightest, suggesting that this may be an artefact. Note that the PEDD mode measurement has a longer tail into the NIR, which may be attributable to the different mode of operation, where non-band-to-band transitions may provide a response (inducing charge recombination). Again, this is an important topic, but beyond the scope of this study. We therefore suggest that it should be the focus of future studies. Figure A4. Corrected intensity.