Hans63
Published © GPL3+

PH meter

How do you determine the PH value of your pool...

BeginnerWork in progress10 hours2,300
PH meter

Things used in this project

Hardware components

PH sensor with board
×1
128*64 OLED
×1
Arduino Nano
×1
PH test solution
×1

Story

Read more

Custom parts and enclosures

3D printing STL-file CASE TOP

For the PH Meter

3D printing STL-file CASE BOTTOM

For the PH Meter

Schematics

PH Meter

Fritzing breadboard layout

Code

PH meter

Arduino
Code for PH measuring tool
#include <Arduino.h>
#include <U8g2lib.h>  // https://github.com/olikraus/u8g2
#include <SPI.h>
#include <Wire.h>

/* Parts:
 * PH-sensor kit - https://nl.aliexpress.com/item/32957428276.html?spm=a2g0o.productlist.0.0.27c2955a3zkZKd&algo_pvid=895b0bc4-d7b4-4763-8e68-30f63c00df31&algo_expid=895b0bc4-d7b4-4763-8e68-30f63c00df31-0&btsid=0b0a0ad815838579833514438e0eab&ws_ab_test=searchweb0_0,searchweb201602_,searchweb201603_ 8,77 €
 * OLED 128*64   - https://nl.aliexpress.com/item/32982681500.html?spm=a2g0s.9042311.0.0.47a64c4ddJNBgj 1,40 €
 * Arduino Nano  - https://nl.aliexpress.com/item/32341832857.html?spm=a2g0s.9042311.0.0.47a64c4ddJNBgj 1,89 €
 * some wires
 * case
 * 
 */
 
U8G2_SSD1306_128X32_UNIVISION_F_HW_I2C u8g2(U8G2_R0);
/*
Display:
GND - GND
VCC - 3V3
SCL - A5
SDA - A4
*/
 
//Constants:
const int analogInPin = A0; 
int sensorValue = 0; 
unsigned long int avgValue; 
float b;
float x=-5.94872; // to calibrate - see description
float y=28.69179; // to calibrate - see description
int buf[25],temp;

void setup () {
  delay(500); // don't go to fast or the display will show nothing; it needs some time
  Serial.begin(9600);
  Serial.println("Ready 2");
  u8g2.begin();
  u8g2.clearBuffer();          // clear the internal memory of display
  u8g2.setFont(u8g2_font_crox3hb_tf);  // choose a suitable font at https://github.com/olikraus/u8g2/wiki/fntlistall
  u8g2.setCursor(7,25);
  u8g2.print("pH meter V1.1");
  u8g2.sendBuffer();
  delay(2000);
}
 
void loop () {
 // get 25 readings to avoid noise
 for(int i=0;i<25;i++) 
 { 
  buf[i]=analogRead(analogInPin);
  delay(10);
 }
 for(int i=0;i<24;i++)
 {
  for(int j=i+1;j<25;j++)
  {
   if(buf[i]>buf[j])
   {
    temp=buf[i];
    buf[i]=buf[j];
    buf[j]=temp;
   }
  }
 }
 avgValue=0;
 for(int i=1;i<25;i++)
 avgValue+=buf[i]; // get the sum of readings
 float pHVol=(float)avgValue*5.0/1024/25; // Get average value and make it in millivolts
 float phValue = x * pHVol + y; // calibrate PH-Value
 Serial.print("sensor = ");
 Serial.println(phValue);
 u8g2.clearBuffer();          // clear the internal memory
 u8g2.setCursor(7,12);
 u8g2.print("pH     |  Volt in"); // we show PH and voltage to be able to calculate x and y - See description
 u8g2.setCursor(1,32);
 u8g2.print(phValue);
 u8g2.setCursor(56,32);
 u8g2.print("|");
 u8g2.setCursor(80,32);
 u8g2.print(pHVol);
 u8g2.sendBuffer();
 delay(100); 
 }

Credits

Hans63
3 projects • 5 followers
I started programming innpascal and for 6800 and z80 cpu's and upgraded my TRS-80. Some years ago I began with Arduino and it is fun.

Comments