Water telemetry sensors for Raspberry Pi and C or C++

Hi guys,

I would really appreciate if you can help me to start my project with finding right sensors to measure different water telemetries.

I am new to this area and I want to build an application with Raspberry Pi to measure water temperature, pressure, ph and any other relevant telemetries.

I have to use C or C++ languages and I cannot use Python so please do not suggest Python.

My budget is around $2000 for high quality sensors and the sensors should not be heavy.

Sounds like too much requirements?

Please help to understand how I should choose the right sensors. I really appreciate your help and support.

Thanks again.

Hi Saman,

There are many different sensors out there for the Raspberry Pi. If you can you should select digital sensors, that operate on 3.3V logic. That way you won’t need a logic level shifter (not a big deal if you do). The Raspberry Pi does not have an analog to digital converter built in, so if you decide to use sensors that produce analog signals you will need an ADC to interpret that signal and convert it to digital for the Pi to use. A great place to start is just browsing through whats available. Just type “waterproof temp” into the search bar to get started!

Dear Stephen,

Please suggest me some sensors name and model that support C or C++ if it is possible. I need it for a professional project.

I really appreciate your help.

Dear Stephen,

Thanks again for your help. I have purchased DS18B20 water temperature sensor from your website tonight and I want to buy Gravity: Analog pH Sensor/Meter Kit V2 if you confirm that I can connect it to Raspberry Pi and program it in C++.

I really appreciate if you can tell me how I can connect Gravity: Analog pH Sensor/Meter Kit V2 to Raspberry Pi.

Thanks so much again.

Hi Saman,

All these sensors will work with any programming language, so long as you can read values on the GPIO of the Raspberry Pi with C++, which should not be a problem.

The Analog pH sensor will not be readable without an Analog to digital converter as I mentioned earlier. You can find hookup information and example code here, but not for the Raspberry Pi:

This is my favourite ADC:

and here is a guide to connect it:

1 Like

Dear Stephen,

I want to tank you so much for your help.

I have bought all those sensors and I will receive them today.
I am so excited about it. I hope the C++ code works.

If I had any problem I will ask you question again.

I really appreciate your helps.

Sincerely yours,


Hi Stephen,

Thanks again for helping me with sensors. During last few days I have been trying to work with PH sensor but I cannot understand how to convert the following python code to c or c++.
Would you please if it is possible help me with that.
I am using ADS 1115 and I know that there is a prebuilt c library for that.

import sys
import time
ADS1115_REG_CONFIG_PGA_6_144V = 0x00 # 6.144V range = Gain 2/3
ADS1115_REG_CONFIG_PGA_4_096V = 0x02 # 4.096V range = Gain 1
ADS1115_REG_CONFIG_PGA_2_048V = 0x04 # 2.048V range = Gain 2 (default)
ADS1115_REG_CONFIG_PGA_1_024V = 0x06 # 1.024V range = Gain 4
ADS1115_REG_CONFIG_PGA_0_512V = 0x08 # 0.512V range = Gain 8
ADS1115_REG_CONFIG_PGA_0_256V = 0x0A # 0.256V range = Gain 16

from DFRobot_ADS1115 import ADS1115
from DFRobot_PH import DFRobot_PH

ads1115 = ADS1115()
ph = DFRobot_PH()

while True :
#Read your temperature sensor to execute temperature compensation
temperature = 25
#Set the IIC address
#Sets the gain and input voltage range.
#Get the Digital Value of Analog of selected channel
adc0 = ads1115.readVoltage(0)
#Convert voltage to PH with temperature compensation
PH = ph.readPH(adc0[‘r’],temperature)
print “Temperature:%.1f ^C PH:%.2f” %(temperature,PH)

My code so far is like this

#include <wiringPi.h>
#include <stdio.h>
#include <sys/types.h> // open
#include <sys/stat.h> // open
#include <fcntl.h> // open
#include <unistd.h> // read/write usleep
#include <stdlib.h> // exit
#include <inttypes.h> // uint8_t, etc
#include <ads1115.h>
#include <linux/i2c-dev.h>

//#define BASE_I2C 456
using namespace std;

int main() {
int fd;
int ads_address = 0x49;
uint8_t buf[10];
int16_t val;

// open device on /dev/i2c-1 the default on Raspberry Pi B
if ((fd = open("/dev/i2c-1", O_RDWR)) < 0) {
	printf("Error: Couldn't open device! %d\n", fd);
	return 1;

// connect to ads1115 as i2c slave
/*if (ioctl(fd, I2C_SLAVE, ads_address) < 0) {
	printf("Error: Couldn't find device on address!\n");
	return 1;

// set config register and start conversion
// AIN0 and GND, 4.096v, 128s/s
buf[0] = 0x00;    // config register is 1
buf[1] = 0x02;
buf[2] = 0x04;
buf[3] = 0x06;
buf[4] = 0x08;
buf[5] = 0x0A;

//printf("Conversion %02x \n", buf[5]);
if (write(fd, buf, 3) != 3) {
	perror("Write to register 1");

I really appreciate your help

Hi Saman,

If you want to convert some Python code to C I suggest using the Cython compiler. I’ve used it with success recently:

Dear Stephen,

Does Cython convert Python to C or it is a mixed language that support both?
I am writing an application in C++ and whole my application is in C++ so I cannot change the whole thing to Cython.

I am wondering how I can read the PH and Temperature from https://wiki.dfrobot.com/Gravity__Analog_pH_Sensor_Meter_Kit_V2_SKU_SEN0161-V2 sensor in C++.
I am more than happy to pay someone to teach me as I have just being delayed because of this sensor.
I really appreciate your help.

Hi Saman,

You had asked to convert Python to C. That is what Cython does. I suggest you read through the documentation if you have questions about it.

I’m not aware of any way to convert Python to C++.

Dear Stephen,

I could finally write the right code for that. Thanks.

Would you please suggest me a presure sensor to measure the level of the liquid. Now I prefer analog since I could understand how to map the voltage and I could get ADS 1115 work.

I really appreciate your help.


Hi Saman,

This is a good Analog Pressure sensor:

It might not be suitable for low water pressure, like water sitting in a cistern. You might want to consider other ways to measure water level that would be more reliable. Ultrasonic sensors to the water surface, air pressure sensors in a sealed container, float sensors are all good options.

Dear Stephen,

Thanks again for your help.

Maybe I did not explain well. I need to take some water samples from lakes or rivers. I need to log from what depth of the lake or river I got the water sample. What is your suggestion for this scenario?

Thanks again.

A lateral thought - Can you simply have markers on the rope that is being used to “drop” the sensor into the water?

Also, if the full depth is needed for some reason, chances are you are on a boat and are there will be a depth finder onboard. Which could also be used to determine a safe level to drop the sensor without hitting the bottom or going into an obstacle.

Mr Graham,
Is it the way that you answer your customers?

Have you ever heard of live data streaming? Probably not.

Please upgrade your knowledge and do see more than your nose.

Wow, noted. Sorry to have ruffled your feathers, I thought it was a an idea worth sharing.

All the best with your project either way :slight_smile:

1 Like

Dear Graham,

I like your sense of humour mate! Sorry for being too sensitive.

You are right, those ideas are also not bad but not practical for me.

Believe me I would love to find right sensors to buy and I have already bought some from you.

I am a good customer and I like your services as well.

I apologise for asking too much questions.
Love you guys and thanks so much for your helps and support.

I will purchase more sensors by the beginning of next week.

Have a great evening.

Have a look at the ms5803 breakout board. Will require proper mounting but seems to fit the bill.