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.
- 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
- Ph 4.00 7.00 10.00 calibration kit
- 225Mv callibration fluid
Step 1: 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
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.
then open the raspberyr pi config manager to enable some interfaces
go to Interfacing options and select I2C and 1-wire and enable them.
The Pi may ask you to reboot.
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
To make sure you are connected, execute the following command to check your IP adress at wlan0
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
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.
Last but not least, we need to add some Python packages to make sure everything is working as we want to.
You can install these with pip
Step 2: 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.
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:
Do this aswell for 7.00 (mid) and 10.00 (high)
Pour the 225mV in a cup and submerge the tip of the connected sensor in the fluid.
Then type the following in the program:
Then the callibration is done.
Step 3: Installing the Files
Aquastats is fully published onto github and can be cloned with the following command at any place you like.
git clone https://github.com/DebaveyeEliasProjects/Project1-Backend.git
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.
Step 4: Connecting the Sensors
The sensors can be connected with the included .PDF files
Step 5: 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
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