Software apps and online services
Hand tools and fabrication machines
The turbidity of a river tend to change significantly during a period of heavy rainfall. Climate change causes shifts in the air and ocean currents, which causes drastic changes in rainfall patterns. Due to this, the water quality of rivers can change abruptly throughout the year. These unpredictable changes in turbidity can massively increase the cost of drinking water treatment.
This project aims to determine how rainfall patterns coincide with the turbidity and turbulence of a flowing body of water, by using a floating sensor.
Note : Please note that this project is still in Proof of Concept (POC) stage, and further improvements may need to be done as the project matures.
A QuickFeather development kit, with an EOS S3 low power MCU + embedded FPGA, a SD card reader, ADS1015 12 bit ADC, RTC module and a SEN0189 analog turbidity sensor was used to build the floating unit.
A less permanent way of mounting the components was considered since this device is still in a POC stage.
This video provides a great introduction to the Quickfeather dev kit :
The following is the wiring diagram used for this project :
Tip : You can refer to the user guide found here to get more information regarding the pinout of the development board.
The QuickFeather has an integrated battery charging circuit which allowed me to connect a single cell LiPo battery directly to the VBAT pin. Two solar panels with a rated terminal voltage of 5V were connected in series, and fed to a LM2596 buck converter to drop the voltage down to 3.3V. This will ensure that the battery gets charged when there is sufficient sunlight available.
All the parts used for this project were designed using Solidworks and then 3D printed. (Original solidworks design files and STL files attached)
Two Styrofoam boards were used to provide the required buoyancy. I also used a fair amount of hot glue to make sure there were no leaks.
This project uses the QuickLogic Open Reconfigurable Computing (QORC) SDK and SensiML to generate a model that can predict certain events based on sensor readings.
The following video is a great intro for this approach :
In order to proceed with this tutorial, you will require the qorc sdk found here, and the SensiML data capture lab. Setting up the required libraries is fairly easy in Linux, so if you are using Windows like me, you can use Windows Linux Subsystem (WSL) to get things done quickly.
If you need guide on setting up WSL, GNU Arm embedded toolchain, qorck-sdk and the tinyfpga programmer, you can refer to this video :
PS : The envsetup.sh file that comes with the qorc-sdk didn't work for some reason, so I ended up making a different environment file to make things a bit easier.
alias qfprog="python3 $FLASH_PROGRAMMER_INSTALL_DIR/tinyfpga-programmer-gui.py"
You can save this as myenv.sh and use
when you want to get your environment set up. [Change the install paths accordingly]
The workflow of this project can be summed up as follows :
- Use a modified version of the simple data stream app that comes with the qorc sdk to gather data.
- Use the SensiML data capture lab to collect the data and define the labels.
- Use the SensiML analytics studio to create a model to identify specific events based on sensor data.
- Run the model on the QuickFeather.
The qf_ssi_ai_app that comes with the qorc-sdk was used as the code base of this project. It is possible to integrate existing Arduino Libraries with this code, which means you can easily integrate a wide range of sensors.
The changes done to the original code are as follows :
- Add the source and header files for the ADS1015 ADC into the inc and src directories
- Define the delay function and the byte and boolean data types required for the library
- Import the ADS1015 library in the sensor_ssss.cpp file, and make the necessary changes in the sensor_ssss_acquisition_buffer_ready function.
- Edit the json_string_sensor_config json descriptor in the sensor_ssss.cpp file.
- Make changes in sensor_ssss.cpp file to enable data livestream and datasave to SD card.
The following video explains how new i2c sensors can be integrated with the quickfeather :
If you plan on using a custom sensor, you will need to create a SSF file for the Data Capture Lab. More information on creating your on SSF file can be found here. [The SSF file created for this project is attached]
Once the generated.bin file is uploaded to the QuickFeather, it will begin streaming data over UART [gladly a UART to USB converter is provided with the QuickFeather Dev Kit. However, since I have used a SD card reader, the data can be saved to an SD card in instances where connecting a cable is not practical ]
Sensor data can be viewed from the Data Capture Lab.
For this stage of the POC, four distinct scenarios were considered.
- event-0 : Turbidity - LOW Turbulence - LOW
- event-1 : Turbidity - LOW Turbulence - HIGH
- event-2 : Turbidity - HIGH - Turbulence - LOW
- event-3: Turbidity - HIGH - Turbulence - HIGH
[High turbulence generally means an elevated rate of waterflow]
Due to the existing lockdown in Sri Lanka due to Covid19, I encountered difficulties when gathering sample data from actual water bodies. Therefore, most of the data was acquired at home using a controlled environment.
Segments and labels were assigned to the captures using the label explorer mode.
Once labels are assigned, the captures get automatically uploaded to the SensiML analytics studio.Building a Model in Analytics Studio
The process of generating a model was fairly straightforward.
- In the prepare data tab, create a new query with your captures. Make sure the labels are displayed correctly.
- In the build a model tab, select your query, and the window size. I used a window size of 100.
- After the model is successfully built, you can test it on different captures to check its accuracy.
The analytics studio also allows you to explore the created model, by providing you visualizations and a feature summary etc.
Once you are satisfied with the accuracy, you can proceed to download the model.
The downloaded files can be placed in qf_ssi_ai_app/knowledgepack. The downloaded file comes with a nifty script that helps you copy all the files into your project.
Note the class map : 1 is event-0, 2 is event-1, 3 is event-2 and 4 is event-3
Once the knowledgepack is copied, the SENSOR_SSSS_RECOG_ENABLED parameter can be set to 1, and the code can be reuploaded.
Image 15 - The sensor accurately predicting an event-2, with high turbidity and low turbulence :
Image 16 - When a little turbulence is introduced to the water container with high turbidity, event-3 is detected :
- Due to the low cost turbidity sensor used in this POC, the variance of the analog reading was not satisfactory. This is specially observed in events 0 and 1 where the accuracy of detection is fairly low. A better sensor or a better amplifying circuit needs to be used.
- Since only few of the data captures were done on actual water sources, real world results may vary. Once lockdown is lifted, the sensor can be tested on actual water streams. The model may need to be retrained with new captures.
- Since the event detections need to be compared with actual rainfall patterns, they need to be saved onto the SD card with a correct timestamp. The datasave.c file needs to updated to use the external RTC connected to the quickfeather board.
- The ability to use Arduino sensor libraries with the QuickFeather [with some minor changes] opens up a world of possibilities.
- The SensiML Data Capture Lab and Analytics studio were very straightforward, and I was able to generate a fairly accurate model using a few amount of captures. This allows you to focus more on the prediction results and their implications.
- The next stage of this POC will use a more sensitive turbidity sensor so that the number of detected combinations (events) can be increased.
- After testing the sensor on water bodies for some time, the next step is to compare with actual rainfall patterns in that region. This will provide an insight in to how the water quality of a river changes with respect to changing weather conditions - i.e climate change.
- An array of these sensors placed in different regions will provide water engineers in treatment plants the ability to predict the changes in water quality.