Development of a sensor and measurement platform for water quality observations: design, sensor integration, 3D printing, and open-source hardware

A measurement and development platform for collecting water quality data (the WaterWatcher) was developed. The platform includes sensors to measure turbidity, total dissolved solids (TDS), and water temperature as variables that are often collected to assess water quality. The design is extensible for research and monitoring purposes, and all the design files are provided under open-source permissive licenses for further development. System design and operation are discussed for illustrative purposes. A block diagram indicates elements of mechanical, electrical, and software design for this system. The mechanical assembly used to house circuit boards and sensors is designed using 3D printing for rapid prototyping. The electronic circuit board acts as a carrier for an Arduino 32-bit microcontroller board and an associated cellular module along with a GPS for geolocation of water quality measurements. The cellular module permits data transfer for Internet of Things (IoT) functionality. System operation is set up using a command line interface (CLI) and C + + code that allows for calibration coefficients and human-readable transfer functions to be defined so that sensor voltages are related to physical quantities. Data are cached on a secure digital (SD) card for backup. The circuit was calibrated, and system operation assessed by deployment on an urban reservoir. Biogeochemical cycles were identified in the collected data using spectrogram and semivariogram analyses to validate system operation. As a system with hardware and software released under an open source license, the WaterWatcher platform reduces the time and effort required to build and deploy low-cost water quality measurement sensors and provides an example of the basic hardware design that can be used for measurements of water quality.


Introduction
Water quality refers to the properties of water that influence biological systems (Karr & Dudley, 1981). This includes civil engineering (Brabec et al., 2002) and toxicological applications (Vlaming et al., 2000), where characteristics of water are measured for determination of hazards related to potable water use and ecosystem services. Pollutants and toxins from sewage, industrial waste, and stormwater runoff enter rivers and streams (Deblonde et al., 2011), potentially modifying biogeochemical cycles. Nitrogen and phosphorus from agricultural and domestic uses of fertilizers stimulate the growth of algae and other microorganisms, decreasing oxygen levels in water and causing eutrophication (Conley et al., 2009). In some urban environments, runoff enters storm sewers (DeFilippi & Shih, 1971) that convey solutes to stormwater retention ponds (Borne, 2014) and surface hydrological systems (Marsalek, 1991). Due to an increase in urbanization and a decrease in infiltration associated with a reduction of soil permeability, stormwater discharge has increased in recent decades, and water quality has decreased due to a concomitant increase in transported chemicals and ions (McGrane, 2016).
In light of these aforementioned stressors, water quality is one of the central factors determining ecosystem functionality and the sustainability of human activities (Gleeson et al., 2020). Despite the importance of collecting water quality data, traditional techniques for sampling are prohibitive of early detection of changes (Madrid & Zayas, 2007). This is because manual sampling involves the collection of data (either directly using handheld probes, or from lab analysis of samples) from a field site by human investigators, which increases cost and limits throughput. Therefore, there is a need for methods that allow for collection of data at higher temporal and spatial resolutions.
The Internet of Things (IoT) concept involves the use of embedded computing devices to collect and transfer data over a network for automation of observations and the associated display and analysis of data in near real-time (Ng & Wakenshaw, 2017). IoT devices are designed to be ubiquitous and communicate over WiFi (Li et al., 2011), cellular (Mangalvedhe et al., 2016), or mesh radio networks (Yu et al., 2017) to transfer data between devices and systems (Suo et al., 2012). The collected datasets are used for decisionmaking (Lee et al., 2013), process control (Prathibha et al., 2017), or environmental modeling applications (Wong & Kerkez, 2016). IoT intends to provide adequate spatial and temporal coverage to obtain data useful for predictions and forecasts.
Water quality data have been collected using Internet of Things (IoT) technologies. Water quality sensors have been deployed to monitor river (Chen & Han, 2018) as well as inland water and maritime environments (Prasad et al., 2015) and have also been deployed on a robotic boat to obtain spatial estimates of water quality (Li et al., 2017). Commercial IoT sensor platforms have been utilized for this purpose (Wong & Kerkez, 2016). Commercial devices are relatively expensive, and the use of commercial hardware can result in vendor lock-in (Willocx et al., 2018), resulting in the need to upgrade devices when deprecated by the manufacturer (Pal et al., 2018), and supporting the necessity of paying for access to software and associated technical support required for system functionality (Boehm & Abts, 1999).
The Arduino platform provides easy-to-use hardware and software with an open source license (Badamasi, 2014;Sarik & Kymissis, 2010). Opensource hardware allows for design re-use and innovation and thereby enables a better understanding of system functionality due to the availability of schematics and associated design documentation (Fisher & Gould, 2012;Pearce, 2012). Open-source software also allows for code reuse: since the source code is available, software functionality can be easily extended and modified (Bonaccorsi & Rossi, 2003;Fitzgerald, 2006), especially when permissive licenses such as the GNU GPL allow for freedom of use (Di Penta et al., 2010). Arduino-based platforms have been used to collect water quality data and exchange data over WiFi (Chowdury et al., Pasika & Gandla, 2020), Zigbee (Encinas et al., 2017;Kamaludin & Ismail, 2017;Pranata et al., 2017), LoRa (Saravanan et al., 2017) and cellular (Moparthi et al., 2018;Saravanan et al., 2018) networks. However, most of these water quality measurement projects, although based on open-source hardware and software technologies, do not provide the complete design under a permissive open-source license. This does not allow previous research work to be easily re-used to create additional systems.
This paper introduces a floating water quality measurement platform with open-source hardware and software that can be utilized to develop water quality measurement applications without the need to replicate some common system components. This platform is named the "WaterWatcher." The hardware of the WaterWatcher platform is based around a custom electronic circuit that serves as a carrier printed circuit board (PCB) for an Arduino microcontroller. The microcontroller is interfaced to a cellular communications module. A 3D-printed enclosure is used to house the circuit board and provide a mounting platform for solar panels that power the circuit and charge an on-board lithium-ion battery. The 3D-printed enclosure, circuit board design files, and Arduino code are provided as an associated download licensed under permissive open-source licenses. The WaterWatcher platform is intended to enable future innovation and development of water quality measurements by the scientific community. This paper is also intended for educational or teaching purposes and serves as an overview of the ideas and technology for water quality measurements.

Block diagram and system operation
Electronic sensor systems for observations of water quality have common features as identified by the block diagram of the WaterWatcher system ( Fig. 1). There are three canonical sensors attached to the system: turbidity, total dissolved solids (TDS), and temperature. Additional sensors for chemical measurements can be eventually added. A 3D model of the PCB for this platform implementation is shown in Fig. 2(a), whereas the assembled PCB is shown in Fig. 2 An analog frontend provides signal conditioning for voltage inputs from sensors that measure turbidity and TDS. These two sensors are utilized for water quality estimates by many studies and were therefore provided for use in this development platform. Temperature influences TDS determined using an empirical sensor calibration curve (Rusydi, 2018), and temperature also influences water chemistry kinetics (Gholizadeh et al., 2016;Paul et al., 2019), so a temperature sensor should always be included.
Turbidity is related to particulate matter from erosion, sewage, geological, and biological sources. The particulate matter present during periods of higher turbidity reduces photosynthetic production, increasing absorption of solar radiation and water temperatures (Davies-Colley & Smith, 2001), and decreasing dissolved oxygen levels (Henley et al., 2000). Turbidity levels are used to assess the quality of drinking water since higher amounts of particulate matter can provide environments for pathogens (Farrell et al., 2018). Electronic turbidity sensors are usually optical and relate light extinction to nephelometric turbidity units (NTU) (Davies-Colley & Smith, 2001).
Total dissolved solids (TDS) are a measure of chemical and biological substances that exist as molecules, ions, or colloids in the water. Higher levels of TDS are related to greater amounts of dissolved substances (Weber-Scan & Duffy, 2007). Electronic TDS sensors relate parts-per-million (ppm) TDS to electrical conductivity (Ivan et al., 2011).
Inputs can also be added for additional sensors for measurement of water temperature gradients at depths below the water surface. These additional sensor inputs can be digital and attached to a multidrop bus. The WaterWatcher uses the 1-wire bus (Dudak et al., 2018) where multiple sensors are attached to the same wired connection, and each sensor is associated with a unique address. The temperature sensor used for the WaterWatcher is digital as an application-specific integrated circuit (ASIC) since the use of an ASIC decreases complexity.
The main microcontroller enables periodic sampling of analog and digital inputs. Interfaced with a cellular communications module, the microcontroller periodically sends data to a base station or server. However, since radio frequency (RF) communications are not always reliable due to topographic and environmental effects or infrastructure failure, there must be a means for data to be locally cached. This enables data to be retrieved later in the field or to be re-sent to the server at a time when the circuit can communicate with a network. A ubiquitous flash memory device for storing data is an SD card that is readily available from commercial sources. The SD card can be extracted and inserted into a reader to transfer data to a computer for analysis. A USB bus allows for Machine-2-Machine (M2M) communications where system operation is configured using a computer using the CLI as described in the Software Design section of this paper.
A GPS receiver module provides geographic location and elevation data. Although the water quality measurement platform might be installed at a stationary location in, e.g., a stormwater retention pond or reservoir, GPS measurements allow for WaterWatcher devices to be located on a web map interface or to be tracked for property inventory purposes. Moreover, if the water quality measurement platform is towed behind a boat or set adrift in a river or reservoir, geographic location can be related to spatial changes in water quality.
The system requires DC power and cannot be easily interfaced to AC power via a converter since water quality devices are often placed in bodies of water at remote locations and field sites. The Water-Watcher therefore requires a battery charger system interfaced to solar panels. To reduce the overall mass of the system, the batteries are Li-ion cell chemistry, but a protection circuit is also required to limit the rate of charge, reduce overcharge, and overdischarge, and also ensure that a battery fault does not cause an explosion or fire (Salerno & Korsunsky, 1998).
To protect the WaterWatcher circuit from water ingress and to provide a mounting platform for the water quality sensors, a mechanical enclosure is required. This mechanical enclosure can be created from plastic. To allow for rapid prototyping and modification (Oropallo & Piegl, 2016), the enclosure is 3D-printed for prototyping and low-volume applications.
At the time of writing, the cost of mechanical parts and electronic circuit boards is under $1000 CND. The WaterWatcher can thereby be created at a fraction of the cost of commercial water quality sensor platforms.

Mechanical design
The mechanical design for the WaterWatcher floating water quality sensor platform is shown as an exploded diagram (Appendix A) and a computer rendering as Fig. 3(a). Although buoy design can be conducted with specialized software packages that allow for modeling of wave interaction with the structure (García et al., 2018), we used a standard mechanical CAD system to maximize reproducibility and design sharing since this type of software is more readily available to researchers.
Mechanical design calculations are performed separately in accordance with engineering principles, and since the platform is intended for use at inland water locations, it is less important to model wave action thoroughly using numerical models. Design calculations ensure that the platform has a high enough metacentric height to guarantee static stability and sufficient period of roll to prevent internal damage of wiring during wave action. These are design goals nominally associated with marine structures (Terada et al., 2019).
Although a proprietary CAD system was used for the design, STEP files are also provided in a vendor neutral format for use with open-source CAD software packages or for 3D printing. All the assembly pieces shown on the diagram were printed on an engineering-grade 3D printer (Fortus F370, Stratasys Inc) using acrylonitrile styrene acrylate (ASA) plastic. ASA plastic was chosen since this material is UV-stabilized for outdoor locations and is similar in hardness to ABS plastic. Support material was used by the 3D printer to create holes. After removal of the support material in a detergent bath, the holes were functional and precisely located as specified by the mechanical CAD design. This eliminated the need for drilling of holes after 3D printing and reduced a step of the manufacturing process. The following paragraphs indicate alphabetic identifiers on the diagram provided in Appendix A.
A bottom rudder (A) is fastened to a circular inner assembly (B) that provides a conduit for wires and a mounting point for the three basic sensors that measure turbidity, TDS, and temperature. Analogous to rudders on boats (J. Liu & Hekkenberg, 2017), the rudder allows the sensor platform to travel with the flow in a river or stream. The rudder can be turned to different cardinal directions by removing the fasteners and updating the 3D model. Additional holes created in the circular inner assembly (B) can accommodate wires for additional sensors.
The circular inner assembly (B) is attached by fasteners to two carbon fiber (C) plates glued between polyethylene foam sheets (D, E). The edges of the sheets are rounded to prevent mechanical disaggregation of the sheets if a collision occurs. This distributes the collision force over a larger surface area.
Regions of the bottom foam sheet (D) were removed to ensure that the inner assembly and the carbon fiber plates are flushed with the foam sheet surface. The removal was done by hand, but a CNC machine can also be used. The removal of material ensures that the foam sheets can be glued together without a gap. The carbon fiber plates (C) were glued together using a marine adhesive epoxy.
The platform is assembled in a stacked fashion by threaded rods (F) inserted into holes created in the circular inner assembly. The rods are held in place by nuts inside of the circular inner assembly. A cap (G) protects against water ingress and provides a seating plane for the upper part of the assembly. A hole is created through the top of the cap to admit wires from the sensors.
A plate (H) with holes is placed on top of the polyethylene foam sheets. The plate is held in place by the threaded rods and provides a mounting location for GPS and cellular antennas. Conduits for the coaxial cables connected to each antenna are created in the foam. The plate was divided in half to not exceed the lateral build dimensions of the available 3D printer. This entails printing the single plate as two separate plastic pieces that are later joined together.
A plastic parallelepiped (I) is placed on top of the threaded rods. Holes on opposite sides of the parallelepiped allow for the coax cables from the GPS and cellular antennas to be brought into the internal cavity and connected to the PCB (Fig. 2). The sides of the parallelepiped are recessed to hold solar panels (J) glued to the sides using a marine epoxy. The solar cells are placed on all sides of the parallelepiped to maximize electrical power output.
Another cap (K) and a similar plastic parallelepiped (L) are placed on top of the lower parallelepiped (I). The threaded rods (F) are used to stack together the two parallelepipeds. The top parallelepiped has threaded inserts to admit bolts that fasten on a lid (M). Integrated into the lid is a holder for the PCB (N). The PCB is bolted to the holder ( Fig. 2(b)) along with a RF (radio frequency) bias tee module to provide power to the active GPS antenna. The top of the lid has a holder for a solar-powered strobe light (O). The strobe light (O) is inserted into the holder and glued in place.
During and after assembly, a silicone sealant was applied to waterproof portions of the design to protect against water ingress. A sprayable sealant was applied to all surfaces for weatherproofing and to fill in small gaps in the plastic. Since ASA tends to shrink after printing, the sealant further waterproofed the mechanical assembly.
The total height of the assembly from the bottom of the rudder to the top of the strobe light is 36 in. (91.4 cm). The maximum width of the foam is 18 in. (45.7 cm) and the maximum length is 24 in. (61 cm).
These dimensions indicate that the WaterWatcher is a compact platform for water quality measurements, and it has been successfully deployed and retrieved by a single person from a canoe.
Images of assembly are available for download. The images are licensed under a permissive license and serve as an example of how the WaterWatcher was assembled.

Electrical design
Appendix B provides schematics for the circuit. Two analog inputs (A0 and A1) allow for digitization of voltages from turbidity and TDS sensors. The analog inputs are connected to microcontroller port pins set up as analog inputs. The microcontroller has an integrated 12-bit ADC for digitization of voltages and a nominal resolution of 0.8 mV for a configured internal voltage reference of 3.3 V.
Op-amp U23A is configured as a unity gain buffer to provide a high-impedance input for the turbidity sensor. A voltage divider comprising resistors R35 and R36 scales the maximum sensor voltage to be less than 3.3 V as the input to a microcontroller port pin configured as an analog input. Op-amp U23B is another unity-gain buffer that provides a low driving impedance to the analog input port pin so that the accuracy of the measurement is not affected. Diode D3 is a low-capacitance electrostatic discharge (ESD) protection diode.
Since the TDS sensor voltage output is pre-processed using circuitry on a small PCB provided with the sensor module, the driving impedance is low enough to directly interface this sensor to the analog input. An ESD diode D4 also protects the input. Similar diodes are also used for ESD protection on other inputs shown throughout the schematic.
A 1-wire multidrop bus (D0) is implemented using microcontroller GPIO bit-banging. A 1-wire temperature sensor to measure water temperature is attached to this bus. The 1-wire bus has multidrop communications, where each sensor on the bus has a unique serial number and is enumerated using a bus protocol. As per the name, only one wire is used for the bus and another for electrical ground (GND) (Eisenreich & DeMuth, 2003, pp. 345-369). Similar to other digital busses, the maximum number of devices added to the bus is limited only by wire connection resistance and capacitance allowing for dozens of sensors to be added. Linear regulator U22 provides power to the temperature sensors.
Headers J1 and J2 connect two 3.7 V Li-ion batteries with a capacity of 2 A hr in series to provide a 7.4 V nominal source. U3 is an overvoltage protection IC that also performs cell balancing to ensure that the voltages of each battery are approximately equal during charging and discharging. This increases efficiency and battery life and protects against thermal runaway that can create a fire hazard. U1 and U2 are field effect transistors (FETs) with integrated charge pumps and current-limiting circuitry that limits the maximum bi-directional current flow to the battery. U4 is a battery monitor with a charge integrator that reports the battery state-of-charge. An ADC integrated into U4 is connected to header J3 to provide another ADC input (identified as A2). ADC input A2 can be used to measure the voltage output of another sensor.
The battery charger U5 provides maximum power point tracking (MPPT) for solar panels to ensure that the batteries are efficiently charged when enough solar energy is present. Each solar panel has a 9 V nominal open circuit voltage with a current of 220 mA for a maximum output power of approx. 2 W. Connecting the cells in the configuration shown results in a maximum 18 V open circuit voltage with a maximum current of 880 mA for a maximum output of approx. 16 W. Diodes D7 and D9 allow for the solar panels to power the circuit directly or when the battery is dead or not present.
The power supply built around U17 utilizes a switch-mode topology with inductor L4. This power supply is more efficient than a linear regulator to provide a 5 V main system rail. The input to U17 is filtered using an LC filter to reduce the effects of electromagnetic interference (EMI). U18 is a FET with integrated charge pump that acts as a switch to turn on and off the external 5 V rails that provide power to the sensors. This conserves current since the 5 V rail is only turned on during the time of a measurement.
U7 is a GPS module. Linear regulators U8 and U9 provide a quiet power supply to the GPS to reduce noise from the 5 V main system rail. U8 is the main linear regulator whereas U9 serves as a battery backup for the GPS, reducing the time to first fix (TTFF) when the main supply to U8 is turned off between measurements to conserve battery power. U20 is a unique serial number that identifies each circuit board. Linear regulator U21 provides current to a real-time clock (RTC), a port expander (U24), and a buffer (U15). The RTC provides a timestamp for each observation and allows for measurements to be taken on a schedule ranging from minutes to hours. The port expander samples battery state and is used to determine if there is a battery fault or if the battery is charging.
Buffer U15 protects against current flow to the GPS module when it is powered down and serves as a Faraday shield (Zumbahlenas, 2008, pp. 845-846) for reduction of logic noise from the main processor module port pins configured as a TTL serial port. The Arduino MKR GSM 1400 module (U14) is based around a 32-bit ARM processor interfaced to a cellular chipset for IoT connectivity. A SIM card is inserted into the module. For this reference implementation, we initially used the Hologram.io cellular platform to exchange data: the platform is inexpensive, provides a REST API for implementation of web services, and is supported for use with the Arduino ecosystem. Later experimentation utilized a web server with a web framework to store data in a custom database.
The main processor module U14 is interfaced to an SD card by a serial peripheral interface (SPI) bus. The SD card is operated in SPI mode in lieu of a 4-bit parallel bus, since the main processor module lacks a hardware SD card master but analogous to most microcontrollers incorporates an SPI master. For power-down between measurements, linear regulator U16 is turned off by the main processor module. To prevent current flow between the main processor module port pins and the SD card during powerdown, all port pins connected to the SD card are set as inputs.
A micro-USB connector on the main processor module U14 serves to implement a USB serial port that provides a command line interface (CLI) for the WaterWatcher. The CLI allows for the sampling platform to be configured and tested.

Software design
The software design for the WaterWatcher is based around the Arduino platform for reproducibility and to reduce the amount of effort required for modification. Although existing Arduino software libraries were used as required, custom code was also created for the RTC U19, port expander U24, battery monitor U4, and serial number integrated circuit U20. This ensured flexibility in the context of the application. The SD card library required for reading and writing the FAT filesystem was FatFs (version 86,604) with a custom media access interface written specifically for SPI communications. This custom implementation was chosen over Arduino-provided SD card libraries to ensure that high-capacity exFAT cards could be used as interfaced to the SPI bus. The use of exFAT cards allows for years of data to be stored on a single card.
An example of the setup is provided as C + + code in Table 1 as an Arduino sketch file. Arduino code requires two functions: setup() and loop(). The setup function initializes the hardware, whereas the loop function is an infinite loop that checks the state machine logic implemented by the code.
An instance of the WaterWatcher class is created as a global object in the main sketch. The setup is implemented by a call to class member setup(). The check of internal state is implemented by a similar call to class member function checkState() in the loop() function. These are the only required functions in the user code and the WaterWatcher class encapsulates functionality. Additional functionality, such as the sampling interval, is set using the command-line interface (CLI).
The basic structure of the code in Table 1 can be modified if required to add additional functionality. The code demonstrates how the WaterWatcherOptions sub-class is inherited from the associated base class to override transfer functions that provide processed analog outputs relating a voltage to a physical measurement such as turbidity or TDS. The processed water temperature can also be adjusted based on calibration. The analog channels are set to sample or not to sample during a measurement. Table 2 lists commands entered using the CLI when the WaterWatcher is attached to a host computer via the USB cable. The plaintext ASCII commands sent over USB via an emulated serial port allow for various sub-systems to be read, specify whether the data is to be sent over cellular, and indicate whether the system is to enter a power-saving mode. CLI arguments are separated by spaces. As indicated in the table, some settings can be saved into non-volatile flash memory using the write-flash command. These Table 1 Arduino setup code for WaterWatcher platform showing how system functionality is encapsulated by a Water-Watcher object. Some other functionality is provided by the CLI (Table 2), thereby reducing the amount of code required to be written by the user. The Arduino.h header file is only to be included when using an alternate IDE such as provided by Platform.io and is not required for the official Arduino IDE / Data can be stored on the SD card in JSON (JavaScript Object Notation) format. An example of the JSON format is shown as Table 3 along with documentation of field names. Each line of the file containing data consists of a JSON object. CSV (comma-separated values) format has been nominally used by dataloggers and is not self-documenting. Alternately, JSON format is widely used for data interchange and is human-readable (Bassett, 2015). Each object and associated field names are clearly identified, unlike CSV that relies on additional metadata to identify the contents of each column. Most programming languages (including R and Python) can easily parse JSON and convert this format to CSV or other Send a string over the cellular network to the server on-cell Turn on the cellular modem off-cell Turn off the cellular modem powersave-on Turn on powersave (i.e., shutdown modem and rails) powersave-off Turn off powersave sendcell-on Turn on sending of the cellular device sendcell-off Turn off sending of the cellular device sample Manually trigger a sample table-based formats. The code can be modified to store data in CSV or JSON formats.

IoT network design and business logic processing
After each sampled observation, the data is locally stored to SD card, and the sampled data is then sent over a cellular network via TCP/IP communication protocols (Fig. 4). Using a client-server model where the WaterWatcher circuit acts as a client and a cloud-hosted app is the server installed on a virtual machine, data from each WaterWatcher node is sent as JSON to a server endpoint implemented using the Berkeley socket application programming interface (API). The socket is bound to a port on the server and appropriate firewall rules allow inbound communications. Each connection up to a maximum number of connections n is handled by software worker threads, where n is the maximum number of WaterWatcher devices permitted to connect to the socket before further connections are refused. Data received by the socket endpoint is validated as proper JSON with the required number of fields and the IP address of any client connecting to the socket is logged in a database. The IP address is geolocated using a geolocation database, and the socket is closed by the server if the IP address is situated at a geographic location that does not coincide with the region where the Water-Watcher sensors are deployed. Each received JSON object (Table 3) is validated so that a sensor identification number and a known token are present along with required fields that include a human-readable sensor name identifying the site location. The sensor identification number and the token are compared with The JSON structure is human-readable and can also be easily parsed by a program. Moreover, each field name and object is clearly identified. The JSON output is produced by system functionality associated with the setup code listed in Table 1. After the JSON object is cached on an SD card, the object is transferred to a server network socket using TCP/IP protocols over a cellular communications network. Additional field names can be easily added and unlike CSV, the order of field names does not matter within the JSON object JSON sample text Field Identification { "num":1, "token":"23rdf", "a0_voltage":1.347, "a0_out":1.347, "a1_voltage":0.406, "a1_out":0.406, "temp0":21.3, "temp0_out":21.3, "serial_number":"112 152 74 74 1 0 0 199", "serial_number_good":true, "battery_fault":false, "battery_charging":false, "rtc_temperature":21.5, "start_time_str":"22/06/2020 22:30:03", "end_time_str":"22/06/2020 22:30:06", "btemperature":20.6875, "bvoltage":7.79, "bcurrent":0.098, "uptime":659,170, "name":"POND", "latitude":52.184673, "longitude":-106.551422, "altitude":498.299988, "gps_gdata_good":true } known values obtained from a database. After validation, the JSON data received by the server endpoint is stored in a database that is also indirectly accessible as a web service via a web framework. This allows web service clients to obtain database data and the data can be displayed on a web page. The database is periodically backed up to preserve data integrity and snapshots of the virtual machine are used to restore the software stack if required. Once the data is received and successfully stored in the database, the server sends back an ASCII-character "RECEIVED" response to the WaterWatcher client. Otherwise, if data corruption occurred during the network transfer or the JSON data could not be processed, the server sends back an ASCII-character "ERROR" response to the WaterWatcher client. The WaterWatcher embedded device software then attempts to send the data to the server a specified number of times before waiting for the next sampling interval. Since the cellular modem used by the WaterWatcher is placed into a power-down mode in-between communication events, the server does not send control commands to the WaterWatcher.
This current design does not preclude the possibility of the WaterWatcher client periodically checking the server for control commands to change operating parameters such as the sampling interval, or for new parameters to be set as a payload associated with the RECEIVED or ERROR responses as discussed in the previous paragraph. Moreover, the WaterWatcher nodes could potentially communicate between each other in a similar fashion to mesh or star topology IoT  . Other technologies such as SSL (Ammar et al., 2018) or Blockchain (Panarello et al., 2018) can be used to maintain data integrity and confidentiality. However, the current implementation was suitable for a lower-power resource-constrained system with a relatively simple implementation. An example of the server software implementation is given as a download associated with this paper, and this implementation can be extended as required.

Laboratory testing and calibration
The WaterWatcher was placed into a tank at the Toxicology Centre, University of Saskatchewan ( Fig. 3(b)). Waves were created in the tank by displacement to test the buoyancy and stability of the platform (Fig. 3(c)). A video of the wave testing experiment is provided in the associated downloads for this paper.
A commercial multiparameter sonde equipped with turbidity and TDS sensors (EXO2, YSI Incorporated, Yellow Springs, Ohio, USA) was also inserted into the tank and used to collect comparison data to relate WaterWatcher sensor voltages to turbidity and TDS. The tank was filled with deionized water and fitted with a standpipe to allow it to overflow. Commercially available coffee whitener and sodium chloride were used to create water with defined turbidity and TDS. After starting the readings, a constant flow of deionized water was used to dilute the colloid and salt. This caused a time-dependent drop in turbidity and TDS following first-order kinetics. All the laboratory data were logged to the SD card using a 5-min sampling interval. The same 5-min sampling interval was also used for the YSI sonde. Data were collected for approximately 31 h for a total of 365 samples.
The data were subjected to statistical analysis. Additional plotting and analysis were conducted using the Python programming language and the source code provided for download.
Field deployment and data sampling The WaterWatcher was deployed at an urban reservoir (Aspen Ridge Forebay) situated near the Northeast Swale within the municipal boundaries of the City of Saskatoon, Saskatchewan, Canada (Fig. 5). The urban reservoir is a pond with engineered storm drain discharge from surrounding neighborhood locations.
The Northeast Swale is a geographical area representative of ecosystem diversity with native grassland, wetlands, and rare species that are subjected to increasing urban land use (Shen et al., 2019). The WaterWatcher was anchored to the bottom of the reservoir using a coated aircraft cable and a concrete weight. To conserve power, measurements of turbidity, TDS, and temperature were collected every 30 min, cached on the SD card, and sent via cellular communications to a server.
To characterize the monitoring results of the WaterWatcher, manual water samples were collected from the urban reservoir by the City of Saskatoon and subjected to laboratory analysis. TDS was directly determined from the sum of ions present in the water sample (Soucek et al., 2011), whereas turbidity was computed from the total suspended solids (TSS) using a linear relationship between these two quantities (Rügner et al., 2013) developed using datasets from the same geographical location (City of Saskatoon, 2020, pp. 17-70).

Laboratory testing and calibration
The wave-testing experiment (Fig. 3(c)) showed that the platform did not capsize during water turbulence and demonstrated the veracity of the engineering design. Since water ingress was not observed after more than a week of the sensor floating in the tank, we deemed the enclosure sealing and the plastic thickness to be suitable for a waterproof design demonstrating system operation. This does not preclude the possibility of leaks arising over time, or water ingress from total submersion of the WaterWatcher, necessitating the need for maintenance and possible repair between field deployments in a similar fashion to commercial sensors.
As determined from laboratory testing and calibration, Fig. 6(a) shows the relationship between turbidity and voltage as well as the associated model found by curve-fitting. Figure 6(b) exhibits similar relationships and curve-fitting models related to TDS.
Polynomial curve-fitting was used to smooth the output voltage time series of the WaterWatcher turbidity sensor. The sensor voltage was related to YSI sonde turbidity measurements using polynomial curve-fitting subject to the constraint that the polynomial must be monotonic to model a decrease in turbidity over the time of experiment. This is to ensure that higher output voltages are always correlated with lower turbidities. Since the turbidity sensor measures turbidity by light extinction, lower levels of turbidity will be associated with less light extinction and higher voltages. A univariate spline model was then used to obtain a function relating turbidity sensor output voltage to turbidity ( Fig. 6(a)).
After polynomial curve-fitting to initially smooth the output voltage time series of the WaterWatcher TDS sensor, 2D polynomial curve-fitting was used to obtain a function relating the output voltage and water temperature to TDS as measured by the YSI Fig. 6 Calibration experiments to relate sensor output voltages to (a) turbidity and (b) TDS. The data are shown as circle markers, whereas the model is shown as a line on each plot Vol.: (0123456789) sonde ( Fig. 6(b)). The function outputs were corrected for linear offsets to compensate for differences between tank and field observations associated with differences in temperature and fluid mixing processes. Table 4 shows that the root mean squared difference (RMSD) and mean bias (MB) are sufficiently low for the calibration experiments, and this indicates that the models adequately characterize relationships between turbidity, TDS, and associated voltages.
The theoretical measurement resolution M r was estimated by converting the microcontroller ADC resolution to NTU and ppm using a transfer function f(v) determined using calibration curve-fitting and by averaging a difference as shown in Eq. (1) below over the calibration range of voltages.
The v i is the voltage output of a sensor (turbidity or TDS) measured at a known water temperature, i is an index, and N is the number of discrete data values collected during the experiment. The Δv=0.8 mV is the voltage resolution of the 12-bit ADC and v 1 =Δv. The theoretical measurement resolution M r for turbidity and TDS was estimated (Table 4). Although the actual measurement resolution (in bits) will be lower due to circuit noise and sensor circuit errors associated with non-linearities and component variation with respect to time and temperature, this theoretical resolution is likely sufficient to characterize water quality processes at a field site.
The 12-bit resolution is not as accurate as some commercial sensors that may use an ADC with a higher number of bits but digitization of voltages using this resolution can provide an estimate of water quality using low-cost electronics associated with an IoT open-source platform. A higher-resolution external ADC can be added as a circuit board revision for providing more accurate measurements along with additional front-end circuitry such as a programmable gain amplifier (PGA). The PGA can be used to change the amplification of the voltage inputs, thereby allowing for smaller voltages to be measured more precisely. The CLI allowed for system functionality to be expeditiously tested during calibration. At an indoor location with an average light flux exceeding 5Wm -2 from artificial lighting, the microcontroller module was observed to operate using power provided by the solar cells when the batteries were disconnected, demonstrating the efficiency of the switchmode topology power supply design. However, the Li-ion batteries are still required to provide additional power for reliable GPS, SD card, and cellular modem operation. The system current consumption during field deployment is discussed in the sections below.
Field deployment and data sampling Figure 7 shows turbidity ( Fig. 7(a)) and TDS (Fig. 7(c)) time series observations collected by the WaterWatcher at the Aspen Ridge Forebay. Manual water sample data collected on 30 June 2020 are shown as points on the graphs that approximately coincide with the WaterWatcher data curves. Root mean squared difference (RMSD) and mean bias (MB) values shown in Table 5 compare the manual water sample data to WaterWatcher data observations, indicating that over the time of data collection, the automated WaterWatcher observations are comparable to the manual water sample data observations, with differences occurring due to spatial sampling location in the waterbody, as well as temporal vertical mixing processes contributing to error, particularly with respect to turbidity. Moreover, as shown by horizontal lines on the graph indicating minimum and maximum water sample measured values ( Fig. 7(a,  c)), the turbidity and TDS time series collected by the WaterWatcher coincide with the maximum and minimum values of manual water sample observations between the years 2017 and 2020, suggesting that the automated WaterWatcher measurements are representative of the numerical range of biogeochemical processes at this location. To characterize cyclical biogeochemical processes occurring at this location, the time series of turbidity and TDS were subjected to spectrogram analysis ( Fig. 7(b,  d)). The spectrogram vertical axis is expressed in fractional frequency (FF) ranging from 0 to 0.5, where the high end of this range corresponds with half the sampling frequency as per the Nyquist sampling theorem. The vertical range of the spectrogram plot is set to a maximum of FF = 0.04 for visualization and because most of the power spectral density (PSD) of the signal occurs at a lower frequency than this maximum. Since the sampling interval for field deployment was 30 min as 1800s, the sampling frequency was ~5.56×10 -4 Hz.
The turbidity and TDS time series show diurnal cycles associated with water circulation and mixing in the reservoir that also includes the addition of water from storm sewer systems. The spectrogram corresponding to the turbidity time series (Fig. 7(b)) shows the gradual development of cyclical processes over the time of observation, whereas the spectrogram corresponding to the TDS time series (Fig. 6(d)) shows a reduction in cyclical processes. An increase in the turbidity and an increase in the TDS occurred concomitant with precipitation events (Fig. 6(e)) near the midpoint of the time series observations. After these precipitation events occur, the turbidity exhibits an increase in cyclical processes, whereas the TDS exhibits fewer cyclical processes. The increase in turbidity and associated cyclical processes in relation to the rainfall event may have been caused by an increase in water flow to the reservoir and an increase in sediment conveyed to the reservoir by runoff events. Alternately, an increase in TDS and a decrease in associated cyclical processes may indicate an increase in the mixing of water in the reservoir after the addition of runoff from the precipitation events. As expected, water temperature ( Fig. 7(e)) exhibits diurnal cycles associated with land surface temperature changes and heating by solar radiation.
The turbidity spectrogram exhibits a dominant cyclical process at FF ≈ 0.004 corresponding to 125 h or 5.2 days. This indicates a temporal change in reservoir turbidity associated with sediment transport from rainfall events. Alternately, the TDS spectrogram exhibits a dominant cyclical process at FF ≈ 0.02 corresponding to 25 h, indicating that the TDS has more temporal variability than the turbidity and suggesting the prevalence of diurnal mixing processes in the reservoir.
The battery voltage over the time of field deployment ( Fig. 7(f)) ranged between 8.33 and 5.92 V without any missing data indicating that the system was powered by the battery and solar panels over the time of deployment. Figure 7(f) also shows discrete battery charging events, demonstrating the operation of the battery charger connected to the solar panels. Battery charging events only occurred when solar power was sufficiently high to provide the required current for charging. The average operating current sourced from the battery over the time of deployment was 64.6 mA, with an increase in current consumption during cellular transmission events, during cloudy days, and at night when current could not be sourced from the solar panels. The average operating current could be reduced using a custom microcontroller in lieu of the Arduino module. This is because Table 5 Comparison of turbidity and TDS using mean bias (MB) and root mean squared difference (RMSD). The MB and RMSD are calculated for manual water sample measurements as shown by Fig. 7 (a and b), as well as for all-time series data collected by the WaterWatcher over the observation period. Since RMSD is numerically equal to MB for one sample, the associated cells in the  . 8 Semivariance of (a) turbidity, (b) TDS, and (c) water temperature-time series. The range is marked on the x-axis as a vertical dashed line to indicate temporal autocorrelation at time intervals less than the range the Arduino module and associated electronics has LEDs and the use of lower-efficiency circuit elements that are always powered over the time of deployment. Figure 8 shows semivariograms computed for the turbidity (Fig. 8(a)), TDS ( Fig. 8(b)), and (Fig. 8(c)) water temperature-time series. A temporal semivariogram γ indicates autocorrelation over successive time intervals (Haslett, 1997). The range is the position on the horizontal plot axis where the semivariogram reaches an approximate plateau referred to as the sill (Goovaerts, 1997, p. 89). For the turbidity time series, the range is 9100 min as 6.3 days, whereas for the TDS time series, the turbidity is 8000 min as 5.6 days. The temperature semivariogram exhibits a range of 9200 min as 6.4 days with some diurnal cycles evident at shorter time scales. Since the turbidity, TDS, and temperature time series become less autocorrelated at a time interval of ~ 6 days, this indicates that manual sampling of water quality data in the reservoir should be conducted at weekly intervals to capture longer-term trends in temporal variability aside from diurnal variability. However, automated measurements are still required to characterize shorter-term biogeochemical cycles. As suggested by cycles in the TDS semivariogram exhibited at time intervals less than the range (Fig. 8(b)), automated sampling is thereby more important to characterize TDS at shorter time scales than turbidity ( Fig. 8(a)). Turbidity ( Fig. 8(a)) and temperature (Fig. 8(c)) time series have a similar range.

Conclusions
This paper introduced a platform for measurement of water quality with extensible hardware and software. The platform includes sensors that are often used to measure water quality. The mechanical, electrical and software designs are released under permissive opensource licenses to encourage collaboration and reduce the time required to implement a functioning system.
The mechanical design, electronics, and software were described for educational purposes. The mechanical design allows for expeditious creation of parts on a 3D printer, enabling parts to be modified as required. For manufacturing of multiple sensor platforms to provide spatial coverage of a city or region, the parts could be created using injection molding. Although the initial setup costs of injection molding can be high, the cost per part during production is sufficiently low to allow for the creation of a network of multiple WaterWatcher systems.
The electrical design allows for sensors to be sampled and a complete IoT system to be constructed around a microcontroller platform associated with the Arduino ecosystem. This reduces the complexity of updating and editing the code for other associated applications. Moreover, since the basic system functionality can be setup using the CLI, this allows for system operation to be modified and calibration coefficients programmed as human-readable transfer functions without the need for additional computer code to be written. Since the CLI is associated with a virtual serial port, the possibility exists of a computer program with a graphical user interface (GUI) and associated hardware being used to automatically set up and calibrate the system after construction. This can allow for multiple sensors to be assembled and quickly tested before deployment.
The WaterWatcher system was calibrated in a lab tank. The calibration process demonstrates the sensor operation and indicates how the system can be calibrated to relate voltages to physical quantities. Despite the low 12-bit resolution of the microcontroller ADC, the WaterWatcher platform can provide estimates of turbidity and TDS that coincide with commercial sensors. The circuit board could be updated in the future with the addition of a higherresolution ADC and additional sensors that measure water chemistry for additional assessment of pollution and hazards.
The field deployment of the WaterWatcher demonstrated how the system can be used to collect data at a field location and characterized circuit operation. The time series data was subjected to spectrogram and semivariogram analyses to indicate biogeochemical cycles occurring in the North Swale reservoir.
Multiple WaterWatcher platforms have the potential to create a low-cost network of sensors that report data useful for predictions and forecasts of water quality. The use of open-source hardware and software reduces cost and allows for systems to be easily extended for civil engineering and toxicology applications.