Project showcase
Color Sensor Type pH Meter

Color Sensor Type pH Meter © GPL3+

Goodbye calibration! Digitization of pH test paper! This is a pH meter that reads the color of the pH test paper.

  • 3,239 views
  • 11 comments
  • 11 respects

Components and supplies

Ard nano
Arduino Nano R3
×1
Adafruit RGB Color Sensor TCS34725
×1
4-Bit LED Digital Tube Module
×1

Necessary tools and machines

pH test paper

About this project

Operation Test

Code

Color Sensor Type pH MeterArduino
The pH function needs to be adjusted according to the distance between color sensor and pH test paper.
//Color Sensor Type pH Meter

#include <Wire.h>//I2C
#include "Adafruit_TCS34725.h"//Color Sensor
#include <TM74HC595Display.h>//7LED

Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_50MS, TCS34725_GAIN_4X);

//7LED
int SCLK = 7;
int RCLK = 6;
int DIO = 5;

//7LED
TM74HC595Display disp(SCLK, RCLK, DIO);
unsigned char LED_0F[14];//

void setup() {
  //
  LED_0F[0] = 0xC0; //0
  LED_0F[1] = 0xF9; //1
  LED_0F[2] = 0xA4; //2
  LED_0F[3] = 0xB0; //3
  LED_0F[4] = 0x99; //4
  LED_0F[5] = 0x92; //5
  LED_0F[6] = 0x82; //6
  LED_0F[7] = 0xF8; //7
  LED_0F[8] = 0x80; //8
  LED_0F[9] = 0x90; //9
  LED_0F[10] = 0x7F; //.
  LED_0F[11] = 0xBF; //-
  LED_0F[12] = 0x8C; //P
  LED_0F[13] = 0x89; //H

  disp.send(LED_0F[11], 0b1111);//----
  delay(1000);//1000ms

  //PH
  for(int i=0; i<=2999; i++){
    disp.send(LED_0F[12], 0b0100);
    disp.send(LED_0F[13], 0b0010);
  }

  //
  Serial.begin(9600);
  Serial.println("Color View Test!");

  if (tcs.begin()) {
    Serial.println("Found sensor");
  }
  else {
    Serial.println("No TCS34725 found ... check your connections");
    while (1); // halt!
  }
}

void loop() {
  //16RGB
  uint16_t clear, red, green, blue;

  tcs.getRawData(&clear, &red, &green, &blue);
  //delay(1000);//1000ms

  //RGB
  Serial.print("C:\t"); Serial.print(clear);
  Serial.print("\tR:\t"); Serial.print(red);
  Serial.print("\tG:\t"); Serial.print(green);
  Serial.print("\tB:\t"); Serial.print(blue);

  //
  uint32_t sum = clear;
  float r, g, b;
  r = red; r /= sum;
  g = green; g /= sum;
  b = blue; b /= sum;
  r *= 256; g *= 256; b *= 256;
  Serial.print("\t/");
  Serial.print("\tr:"); Serial.print((int)r);
  Serial.print("\tg:"); Serial.print((int)g);
  Serial.print("\tb:"); Serial.print((int)b);

  //pH
  float pH_r, pH_g, pH_b;
  int pH;
  
  //pH Function
  pH_r = 0.0000001216*r*r*r-0.0001876*r*r+0.1009*r-11.62;//r
  pH_g = 0.000000007332*g*g*g-0.00001259*g*g+0.01022*g+4.676;//g
  pH_b = 0.000000005716*b*b*b-0.00001896*b*b+0.02183*b-1.428;//b

  pH = (pH_r+pH_g+pH_b)*10/3;

  //pH
  for(int i=0; i<=999; i++){
    disp.digit4(pH, 3);
    disp.send(LED_0F[10], 0b0010);
  }

  //pH
  Serial.print("\t/");
  Serial.print("\tpH_r:"); Serial.print((int)pH_r);
  Serial.print("\tpH_g:"); Serial.print((int)pH_g);
  Serial.print("\tpH_b:"); Serial.print((int)pH_b);
  Serial.print("\tpH:"); Serial.print(pH);
  Serial.println();

}

Comments

Similar projects you might like

Color Sensor Prototype: Detect Color Name from Objects

Project tutorial by moretticb

  • 7,344 views
  • 7 comments
  • 32 respects

DIY Benchtop pH Meter

Project tutorial by Atlas Scientific

  • 7,187 views
  • 4 comments
  • 25 respects

Touch Sensor and Sound Sensor Controlling AC/DC Lights

Project showcase by Anbumachi

  • 3,488 views
  • 2 comments
  • 7 respects

DHT11 Humidity + Temperature Sensor with 16x2 LCD display

Project showcase by onatto22

  • 28,412 views
  • 6 comments
  • 44 respects

Mobile Fine Dust (PM10 & PM2.5) and NO2 Meter

Project showcase by Telina

  • 12,441 views
  • 28 comments
  • 77 respects

Building a Sensor Network for an 18th Century Gristmill

Project showcase by Jeremy McGinnis

  • 5,271 views
  • 4 comments
  • 26 respects
Add projectSign up / Login