Agree. At the very least consider posting an Instructable.
/K
@DocDrum great work - can you elaborate on what code you used? Iām not asking you to share all your work with the world, just the part which does the calculation of the PH and voltage. I used the out of the box code from seeedstudio which comes with their adjustment values built in and havent had time to play with it yet:
#define SensorPin A0 //pH meter Analog output to Arduino Analog Input 0
#define Offset 0.00 //deviation compensate
#define LED 13
#define samplingInterval 20
#define printInterval 800
#define ArrayLenth 40 //times of collection
int pHArray[ArrayLenth]; //Store the average value of the sensor feedback
int pHArrayIndex=0;
void setup(void)
{
pinMode(LED,OUTPUT);
Serial.begin(9600);
Serial.println(āpH meter experiment!ā); //Test the serial monitor
}
void loop(void)
{
static unsigned long samplingTime = millis();
static unsigned long printTime = millis();
static float pHValue,voltage;
if(millis()-samplingTime > samplingInterval)
{
pHArray[pHArrayIndex++]=analogRead(SensorPin);
if(pHArrayIndex==ArrayLenth)pHArrayIndex=0;
voltage = avergearray(pHArray, ArrayLenth)5.0/1024;
pHValue = 3.5voltage+Offset;
samplingTime=millis();
}
if(millis() - printTime > printInterval) //Every 800 milliseconds, print a numerical, convert the state of the LED indicator
{
Serial.print(āVoltage:ā);
Serial.print(voltage,2);
Serial.print(" pH value: ");
Serial.println(pHValue,2);
digitalWrite(LED,digitalRead(LED)^1);
printTime=millis();
}
}
double avergearray(int arr, int number){
int i;
int max,min;
double avg;
long amount=0;
if(number<=0){
serial.println(āError number for the array to averaging!ā);
return 0;
}
if(number<5){ //less than 5, calculated directly statistics
for(i=0;i<number;i++){
amount+=arr[i];
}
avg = amount/number;
return avg;
}else{
if(arr[0]<arr[1]){
min = arr[0];max=arr[1];
}
else{
min=arr[1];max=arr[0];
}
for(i=2;i<number;i++){
if(arr[i]<min){
amount+=min; //arr<min
min=arr[i];
}else {
if(arr[i]>max){
amount+=max; //arr>max
max=arr[i];
}else{
amount+=arr[i]; //min<=arr<=max
}
}//if
}//for
avg = (double)amount/(number-2);
}//if
return avg;
Actually I found working pyton code right in this thread (Grove - PH Sensor Kit (E-201C-Blue) Raspberry pi Zero - #16 by cyclicalobsessive). I more or less used the GrovePH-Class, this is my current code for reading the pH-Value
import math
import sys
import time
from grove.adc import ADC
# CONSTANTS
Vref = 4.95 # volts
Vcal_mv = 646 # milli-volts (using raw value 535 * 4.95/4096 * 1000)
#Vcal_mv = 2588 # milli-volts (using raw value 535 * 4.95/1023 * 1000) note 10-bit A2D
mv_per_ph = 59.6
ph_per_mv = 1.0 / mv_per_ph
class GrovePH:
def __init__(self, channel):
self.channel = channel
self.adc = ADC()
@property
def PH(self):
value = self.adc.read(self.channel)
if value != 0:
voltage_mv = value * Vref / 4096.0 * 1000
#voltage_mv = value * Vref / 1023.0 * 1000
PHValue = 7 - ((voltage_mv - Vcal_mv) * ph_per_mv)
return PHValue
else:
return 0
def main():
#if len(sys.argv) < 2:
# print(āUsage: {} adc_channelā.format(sys.argv[0]))
# sys.exit(1)
#sensor = GrovePH(int(sys.argv[1]))
sensor = GrovePH(0)
print('Detecting PH...')
while True:
try:
print('PH Value: {:2.1f}'.format(sensor.PH))
time.sleep(1)
except KeyboardInterrupt:
print("\nExiting...")
sys.exit(0)
if __name__ == '__main__':
main()
Right now I donāt do any fancy averaging of values, simply read the value once in 10 seconds and use it. I will try to do some calibration and fiddling with the constants used in the calculation of the pH, but since I still get a very good reading of 7 for my tap water here this is not on the top of the to-do-list.
This screen is what I ordered:
You can get cheaper ones without a grove connector, but I wanted to simplify the connection of the screen. Should arrive tomorrow, then I will do some redesign of the hard- and software on the weekend if I find time for it. If erverything is up and running and I still find more time then maybe I will post the project somewhere.
thanks - whats your h/w setup and how is it connected? Are you using arduino in there? I was going to use piā>arduinoā>pi sensor but was going to get the arduino code working first then sort out the interfacing to the pi
I was curious about the large tablet-like screen shown in your first picture. That looks awesome and if it uses i2c, that would be totally wizard for my 'bot.
I donĀ“t use arduino. My Hardware setup for pH-Measurement is
- Raspberry pi zero/w
- Grove Base Hat
- seeed PH Sensor Kit (E-201C-Blue)
Using this setup it was nearly plug-and-play for the pH-Measurement.
For Temperature Measurement I use a DS18B20 Temperature Sensor, connected via 1-Wire to GPIO. LCD Display and Button are connected to I2C and GPIO, but will be replaced with grove-components and will be connected to the Base Hat in the next Version.
I was curious about the large tablet-like screen shown in your first picture. That looks awesome and if it uses i2c, that would be totally wizard for my 'bot.
The large screen is my iPad showing the dashboard , sorry to have to disappoint you there.
Ups, I just noticed that some of my posts are now hidden because I have a tendency to post links to the components I used. This seems to look like advertising for the forum community here. Sorry, I wasnĀ“t aware of the guidelines and will stop including links from now on.
Doc,
I reviewed the postings you created and, (IMHO), thereās absolutely nothing wrong with them. The comments and links were relevant, they referred to accessories you used to complete your project, and provided guidance about what you did and how you did it.
I would strongly suggest that these postings be un-flagged because they were not āblatant advertisingā but were relevant links to materials used - no worse than links in earlier posts about the LIDAR units used on some of the GoPiGo robots, or books on ROS that people here acquired and are using for their own experiments.
I, myself, have included links to Adafruitās site when discussing adding a RTC to the Pi. I provided both links to the product I used as well as instructions on how to configure it. This is essential information. How can you attempt to duplicate my work if you donāt know what materials, (or code), I used?
If thereās been a policy change, I donāt know about it and it hasnāt been advertised on the forum. (I monitor all new messages.)
I donāt know who flagged your postings, (I suspect they were flagged in error), and I am going to ask @cleoqc (et. al.) to step in and review them.
Thanks everyone who kept this thread alive!
As it turns out, my probes were just fine. I donāt know why my readings have been so unstable. I canāt get any of the sensors to give me a stable calibrated reading. Iām anxoius to see how @DocDrum does with the pH referance solutions. I could get a steady reading with the Grove sensor with pH 7 but as soon as I tried pH 4 my readings were all wonky.
I do know that the probes have to be kept wet. As stated above by @DocDrum , they are in a KCL solution for storage and must be maintained in that when not in use. I was told that if they are dry, they will not maintain accurate readings.
As with my project, when youāre dealing with organics, you will need to recalibrate them on a semi-regular basis.
@DocDrum Thank you for continuing on with this! It gives me hope that I might be able to try going back to that device once I get things done. Also I apologize for not getting to post the code. The code you ended up finding was the code we used before. I also believe it was posted here too. Good luck!!
Maybe, just maybe, (as a previous poster said), the probes are environmentally sensitive. If they were allowed to get too cold and/or freeze, thatād explain everything.
Since your probes were all over everywhere, and @DocDrumās readings were rock-solid, something has to be fishy somewhere. Ā My first guess would be the probe.
As @pdmarsh5466 discovered in his own experiments with the Dexterās GPS sensor for the NXT platform, (Coordinates from dGPS Not Accurate - #38 by pdmarsh5466), a replacement sensor made all the difference in the world.
You may want to try that too.
Let us know what happens!
OK, short update here (I hope the post survives, because it will contain Fotos):
- put everything in a small Tupperware Container (the case I ordered was made of some quite hard plastic and I donĀ“t have a tool to cut that ā¦ )
- first field test in the aquarium: if the fish survived what I measured they would be really tough. The pH readings were far to low (as low as 2.5), something is wrong here ā¦
- retesting with tap water: everything is fine (pH 7).
I know that pH is affected by temperature, the water in the aqarium is at about 28 degree celsius, but that canĀ“t be the reason for this readings. IĀ“ll contact an old colleague, he might still have access to the lab in the pharmaceutical company I worked once. Maybe he can get me some standard buffer solutions, I think IĀ“ll have to try to calibrate the electrode.
Excellent job! Ā Totally professional looking.
You can go to a pool or aquarium shop and get a pH test kit. Ā That should allow you to standardize solutions close enough for what you need. Ā You can also test the aquarium water - who knows, it might really be that low!
P. S.
Get an aquarium ammonia test kit too. Ā If the ammonia is too high, that could be throwing your readings off.
My Girlfriend tests the water regularly with test stripes (after all itĀ“s her aquarium ) The pH is OK there, but I will see what I can get in our aquarium shop, good idea.
DonĀ“t look to closely at the case, it was all hack and slash with a kitchen knive getting those cutouts made , IĀ“m glad I still have all my fingers ā¦
It could be a matter of changing the offset and slope of the PH curve.
Since 7 is right around the center, you could measure your tap-water with the PH kit, adjust offset to the correct value, and then measure at both ends, (vinegar and baking-soda should be good titration chemicals), use the PH strips as your standard, and adjust the slope to put both ends at (or near) to where they should be.
Since you appear to have a good probe, it should be nothing more than calibration to āstandardā solutions.
And since you donāt need incredible amounts of accuracy, (this isnāt rocket science or drug research), commercially available test strips should be fine.
Is this fresh or salt water?
Itās been years since I had aquariums, (yes, plural), including a huge one with a gigantic Pacu in it that ate feeder goldfish. All mine were fresh water.
I am having the vendor (not Seeed) send me a new probe. Iām hoping that resolves it. I had ordered a new probe a while back but when I went to test it, I accidently broke the bulb in the bottom of the probe. The new probe SHOULD arrive free of cold weather and or other environmental factors that may interfere with itās effectivacy. Weāll see what happens!
@DocDrum Thatās a nice looking project. Great job!
Whereās it coming from? Hopefully if they fly it in itās in a (at least somewhat) pressurized and heated cargo compartment!
Heck. . . they say āThird timeās the charm!ā
My curiosity is riz, let me know what happens when it arrives.
Youāre right about one thing, Docās rig there is one sharp looking cookie. Ā Phenomenal job for what she thinks is a hack-job. Ā Iāve seen commercial stuff do worse.
Will do! This one is coming from California, so not very far to travel.
One BIG thing I forgot to mention that I discoveredā¦
Did you know that the blue probe has a built in temp sensor? I bet you did not. It does! I put that probe on the board provided by the company I am using now and it reads temperature just fine and is accurate.
Here is a link to that project:
AnyLeaf
They use the voltage reading to calculate temperature. If you go to the Github page provided above you will see how they do this. It may be handy for some folks to do. He has options in his code to read temperature from an additional sensor as well. Itās all worth a look.
Iāll let you know what I discover here later in the week.
Cheers!
@mountbaldybrewing : Well I never knew that, this is well worth a deeper look, thank you for the link. I will try that.
This fits nicely with my discoveries: as soon as there are changes in the temperature my pH-readings go haywire and I thought about coding some corrective factors for temperature. My testing cup stands on my window sill and as soon as the sun comes round and heats the water the pH-values tend to become unstable. As I said, I know pH is sensitive to temperature, but not in the amounts I saw when testing in the aquarium. So all in all thanks for your appreciation of my project, but the usability in the aquarium seems to be still far away.
In my search for a good way to calibrate my electrode I stumbled over pH-teststripes, testkits containing universal indicators and finally a digital pH testing device for less than 20 Euros which comes with a temparature compensation and calibration solutions . Plus: it can be used to measure the pH of beer . I tend to buy this gadget, just to have a reference for the readings of my probe. So I will end up with two cheap chinese pH electrodes and spend more money, but this project is more of a how-the-hell-works-this-nature anyway .
Edit: just had a quick look at the anyleaf code. IĀ“m curious if this will work when the pH-Probe-board is connected via the grove-hat? As far as I can see the code expects a direct connection to the I2C-Ports, but I really had just a glimpse of the code.
More edit: as far as I understand the anyleaf code the temperature sensor is on their board and not on the electrode itself. Furthermore the datasheet states that they do temperature compensation in the software with a coefficient which is what I thought of too. Have to dig deeper into this ā¦
Last edit : feel free to have a look of my data at IO - Adafruit. You can observe nicley how jittery the pH-readings become when there are temparature changes ā¦