AquaStats
Last summer I chose to build a pool in my backyard. The only thing I was struggeling with was the statistics of my pool like chlorine, etc..
So I had an idea of creating a compact project that would read Ph, temperature and ORP measurements from my water and publish them in a database so I can publish them automatically on a website.
Supplies
- raspberry Pi
- Atlas scientific EZO Ph circuit
- Atlas scientific EZO ORP circuit
- Atlas scientific consumer ORP probe
- Atlas scientific Ph probe
- Atlas scientific Preassembled BCM connector
- One wire temperature sensor
- 5V-12V water pump
- Water tubing that fits your pump
- BC337 transistor
- Rxternal power adapter to match your motor
- Resistor set
- Jumper wires
- Breadboard
- Ph 4.00 7.00 10.00 calibration kit
- 225Mv callibration fluid
Setting Up Your Raspberry Pi
The brain of aquastats is running on a Raspberry Pi 4. The OS of choice here is raspbian.
Raspbian can be easily installed on a micro SD card with Win32DiskImager.
Before you boot on the SD card
- open the file cmdline.txt that is on the SD cards root directory
- place "ip=169.254.10.1" at the end with a space between the previous value. Save the file
- create a new file named "ssh.txt" and remove the ".txt" extension so you are left with a file just named "ssh".
This will allow you to ssh into your raspberry pi.
Put your SD card in your raspberry pi and boot him up
Settings
To make sure everything will work properly. We need to make sure all our interfaces that we need are enabled.
Go into sudo mode wit the following command.
sudo -i
then open the raspberyr pi config manager to enable some interfaces
raspi-config
go to Interfacing options and select I2C and 1-wire and enable them.
The Pi may ask you to reboot.
Wifi
To make sure you are connected to wifi. You will have to execute the following command as root.
wpa_passphrase "SSID" "Password" >> /etc/wpa_supplicant/wpa_supplicant.conf
After that we have to connect to that network by doing the following commands
wpa_cli<br>interface wlan0<br>reconfigure
To make sure you are connected, execute the following command to check your IP adress at wlan0
ip a
Package installation
Because our backend is running on Python3 we want to tell the PI to use Python3 instead of 2.
we do that with the following commands
update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1<br>update-alternatives --install /usr/bin/python python /usr/bin/python3 2
Database
We are using MariaDB to store our data. You can install the database with the following commands
sudo apt install mariadb-server mysql_secure_installation
It will ask you some little questions. Like passwords and so on. Just follow along.
Python Addons
Last but not least, we need to add some Python packages to make sure everything is working as we want to.
- Flask
- Flask_cors
- Flask_socketio
- Python-mysql-connector
You can install these with pip
Callibrating Your Sensors
Next we have to make sure our Atlas scientific sensors are callibrated properly before reading any data.
Atlas scinetific was so kind to provide a very helpfull and pleasing documentation on how to do this.
first of all you will have to install some things on your Pi
apt-get install python-smbus<br>apt-get install i2c-tools
Once these are installed you wil have to enable i2c in the raspi-config
Then we will have to clone the git repo from Atlas scientific
git clone https://github.com/AtlasScientific/Raspberry-Pi-sample-code.git
Before doing anything, disconnect RX and TX from your EZO modules and disconnect power.
we first have to put them in i2C mode. to do this connect the TX to PGND then apply power to the module. When the LED turns blue the process is done. You can now connect RX and TX again to the Pi.
Now to the callibrating part.
First check if your I2C devices are showing up by entering the following command:
i2cdetect -y 1
Both adresses will show up, like in the first image. If this is not the case, connect a pull up resistor of 4K7 to both the RX and TX.
When they do show up, navigate to the cloned repository and run i2c.py
Get the addresses:
By entering List and pressing enter, you will see the sensors with their adress.
Callibrating:
-Ph module:
pour the 4.00 callibrating fluid in a cup and put the connected sensor in the fluid. Make sure the tip is submerged.
Then type the following in the program:
ADRESS:cal,low,4.00
Do this aswell for 7.00 (mid) and 10.00 (high)
-ORP module:
Pour the 225mV in a cup and submerge the tip of the connected sensor in the fluid.
Then type the following in the program:
ADRESS:cal,225
Then the callibration is done.
Installing the Files
Aquastats is fully published onto github and can be cloned with the following command at any place you like.
Backend
git clone https://github.com/DebaveyeEliasProjects/Project1-Backend.git
Frontend
git clone https://github.com/DebaveyeEliasProjects/Project1-Frontend.git
Installing the Database
To store all our data you will have to import the included .sql file that is stored in the backend repo into your MariaDB database
To import the database execute the following commands:
mysql create database aquastats quit mysql -u root -p aquastats < Your_Path_to_Backend_Repo/aquastats_database.sql
Installing the frontend
To make the website work. I have used Apache2. This can be installed with the following command
apt-get install apache2 -y
From there you can navigate to the following folder /var/ww/html
There you can place all the files that were included in the frontend repository
If you then navigate to the ip adress of your Pi or 169.254.10.1 if you are connected to your laptop, you will see the website.
Connecting the Sensors
The sensors can be connected with the included .PDF files
Making Aquastats Run
To start aquastats, we will have to create a service that is running on the Raspberry pi so it will start automatically when Aquastats is plugged in.
To do that we will have to create a service file by doing the following command
nano /etc/systemd/system/aquastats.service
in there you will have to paste the following
[Unit] Description=Aquastats Backend After=network.target mariadb.service [Service] Type=simple User=root ExecStart=/bin/sh /Path/To/Repo_with_launcher.sh [Install] WantedBy=multi-user.target
Make sure you place in the correct path to the launcher.sh file that is included in the backend repository.
To start the service, do the following
sudo systemctl daemon-reload sudo systemctl enable aquastats.service
Then you can reboot your Pi and the program will run autmatically