How to Connect a PH Sensor to a Raspberry Pi 3

This site contains affiliate links to products. We may receive a commission for purchases made through these links.

Watch the water…

That is what you will be doing when you attach a PH sensor to a Rasberry Pi 3 instrument. This sensor’s job is to monitor the Ph levels in any body of water large or small and in either salt or fresh water.

The sensor used for these instructions is the Atlas Science PH sensor and it has the ability to be placed under water up to its BNC connector. Also, these instructions are connecting the sensor to a 12C interface on the Rasberry Pi

A Ph Balance Chart

image

This chart helps guide you to the right levels of Ph balanace you need in your swimming pools, hot tubs and other large amounts of water.

Going too far one way or the other and the use of that water may be harmful to you, your family’s or your pets’ health.

The wrong levels will also harm both fish and plants trying to live in that water. This is why you should have your PH sensor linked to a top quality and very accurate Raspberry Pi system.

You can stay on top of the Ph levels in your water and keep it safe for everyone.

Make Sure You Have All The Materials Needed

This ensures that your connection will go smoothly. Plus, if you have instructions keep them handy. Those guidelines are your most important tool and ensure that you can set the sensor up correctly or find where you went wrong if it doesn’t work.

Here are the supplies you will need:

  1. Raspberry Pi (2, 3 or 4)
  2. Micro SD Card
  3. Power Supply
  4. Atlas Scientific pH sensor kit
  5. Breadboard
  6. Jumper Wires
  7. Adafruit T-Cobbler Plus (Optional)
  8. Raspberry Pi Case (Optional)

How To Attach The Ph Sensor To The Raspberry Pi

Follow the instructions carefully to make sure you do not make a mistake. Leaving any step out will make you go back and find the problem then reconnect the two systems:

Step #1: Enable the 12C modules on your Raspberry Pi. You do this by:

  1. Pres option 5 which is your interfacing option
  2. Go to P5 -12C button and select it
  3. Next choose yes to all the questions
  4. Reboot your Raspberry Pi

Step #2: Once the reboot is completed, open the terminal and make sure all the Raspian packages are up to date. You will need to check or add the Raspbian i2c tools package.

Once you do your screen should be filled number and letters along the top line of the graph and 2 digit numbers on the left hand side. There should be — where those two measurement lines intersect

When you see that screen, it is okay to connect the sensor to the Raspberry Pi system

Step #3: To make the connection you have to change the ph’s UART serial mode to the 12C operation mode. This has to be done manually and when you are successful your ph code should be 99 (0 x 63)

To get this manual switch over done follow the following instructions:

  1. Turn off the power
  2. Disconnect any jumper wires from TX and RX going to your Pi
  3. Short the the PGND pin to the TX pin
  4. Power the device
  5. Wait till the LED changes color from green to blue
  6. Remove the PGND short to the TX pin
  7. Now power cycle the device

Step #4: At this point the device should be configured to the 12C mode and you are free to connect your Pi and the Ph sensor together. To do that, just follow the simple instructions:

  1. Connect the GND pin to the ground pin of your RPi
  2. Connect the TX (SDA) pin to the GPIO pin 2
  3. Connect the RX (SCL) pin to the GPIO pin 3
  4. Double check to make sure your PRB & PGND pins are connected through your breadboard in the center and shield pins of your BNC connector
  5. Power your ph sensor by attaching the Vcc pin to the +3.3V pin
  6. Do a test to make sure the connection is complete

One warning, do not use jumper cables to make these connections or you will not get accurate readings.

Also, if you have more than one sensor connected to your RPi the PH sensor should be indicated by the Hex 63 value. The factory reset value is 99 or 63 but if you have more than one ph sensor attached to your Raspberry Pi then you will need to add a new value for that sensor.

Just add some python code to your Raspberry Pi. Atlas Science should provide that python code for you. Import the python modules, add a class code to interface with the Ph sensor and you should be done.

Things To Remember About Ph Levels

  1. Ph levels differ across the country
  2. Natural and human processes determine the actual ph levels in bodies of water
  3. Pollution changes the ph level of any pool of water
  4. High ph levels give water a bitter taste
  5. High ph levels lower the effectiveness of chlorine thus more chlorine is needed
  6. Low ph levels in water corrode pipes, dissolve metals and other materials
  7. 7 is neutral not 0
  8. A ph level higher than 7 means the water is more alkaline
  9. A ph level lower than 7 means the water is more acid

Other Things To Remember

  • if your Raspberry Pi is not working, litmus paper is always a good substitute until you get the meter and the sensor connected.
  • calibrate your meter in a glass of water where you already know the ph level. Pure water should give you a neutral ph level

Some Final Words

It just takes a little patience and a little electronic know how to connect a ph sensor to your Raspberry Pi. Once it is done, you should have accurate readings and be able to properly adjust the ph levels in the right direction.

This should make that task a lot easier to do and help keep you and your family safe

About The Author