/* # This sample code is used to test the pH meter V1.0. # Editor : YouYou # Ver : 1.0 # Product: analog pH meter # SKU : SEN0161 */ /* Example using the SparkFun HX711 breakout board with a scale By: Nathan Seidle SparkFun Electronics Date: November 19th, 2014 License: This code is public domain but you buy me a beer if you use this and we meet someday (Beerware license). This example demonstrates basic scale output. See the calibration sketch to get the calibration_factor for your specific load cell setup. This example code uses bogde's excellent library: https://github.com/bogde/HX711 bogde's library is released under a GNU GENERAL PUBLIC LICENSE The HX711 does one thing well: read load cells. The breakout board is compatible with any wheat-stone bridge based load cell which should allow a user to measure everything from a few grams to tens of tons. Arduino pin 2 -> HX711 CLK 3 -> DAT 5V -> VCC GND -> GND The HX711 board can be powered from 2.7V to 5V so the Arduino 5V power should be fine. */ #include #include "HX711.h" #define Offset 0.09//-0.31 //pH meter deviation compensate #define calibration_factor -9420.0 //This value is obtained using the SparkFun_HX711_Calibration sketch //#define DOUT 6 //#define CLK 7 // define pin numbers const int tempPin = 16; //PC3 const int pHPin = A1; //PC1 const int DOUT = 6; //PD6 const int CLK = 7; //PD7 float mass = 0; float mass0 = 0; //Set scale HX711 scale(DOUT, CLK); float Temperature() { float reading; reading = analogRead(tempPin); double Temp, T; double R = 10000 / (1023.0 / reading - 1); double loka = 10000 / R; //loka = R0/R T = 0.0033540164 + 0.00026666666 * log(loka); //Steinhart-Hart 1/T=1/T0 + 1/B*ln(R0/R) T = 1 / T; Temp = T - 273.15; //To get Celcius degrees } float PHRead() { float pHvalue = 0; float voltage = 0; voltage = analogRead(pHPin) * 5.0 / 1024; //pinMode(1, OUTPUT); // Serial.print("Voltage:"); // Serial.print(voltage, 5); //pinMode(1, INPUT); pHvalue = 0.1196836333 * pow(voltage, 6.2034289432) + Offset;//0.2543 * pow(voltage, 5.7574) + Offset; // Serial.print(" pH value: "); // Serial.println(pHvalue); return pHvalue; } void setup() { Serial.begin(4800); //pinMode(1, INPUT); pinMode(pHPin, INPUT); //pinMode(tempPin, INPUT); scale.set_scale(calibration_factor); //This value is obtained by using the SparkFun_HX711_Calibration sketch scale.tare(); //Assuming there is no weight on the scale at start up, reset the scale to 0 } void loop() { float pHValue = 0; float temperature = 0; float pHadjustment = 0; float fertilizerAdjustment = 0; float steps = 0; float H3PO4 = 0.1875; //ml/l float fertilizer = 3; //ml/l String motor1 = "9,1,"; String motor2 = "9,2,"; // String motor4 = "9,2,"; String message, message2; float steps3; int steps2 = 0; int steps4 = 0; pHValue = PHRead(); //pinMode(1, OUTPUT); // Serial.print("pH in loop: "); // Serial.println(pHValue); // Serial.print("Reading: "); // Serial.print(mass); // Serial.print(" kg"); //You can change this to kg but you'll need to refactor the calibration_factor // Serial.println(); //pinMode(1, INPUT); // Serial.println(scale.get_units()); mass = scale.get_units(); //scale.get_units() returns a float if (pHValue >= 6.5 && pHValue <= 7) { //Calculate the need for the phosphoric acid. //ml/l*l steps = 67; //single pumping volume 0.13333 ml, 200 steps full rotation -> 66.667 steps single volume steps = round(steps); steps2 = int(steps); message = motor1 + steps2; //pinMode(1, OUTPUT); Serial.println(message); //pinMode(1, INPUT); } else if (pHValue >= 7 && pHValue <= 7.5) { //Calculate the need for the phosphoric acid. pHadjustment = H3PO4 * mass * 0.25; //ml/l*l steps = pHadjustment / 0.133333 * 66.6667; //single pumping volume 0.13333 ml, 200 steps full rotation -> 66.667 steps single volume steps = round(steps); steps2 = int(steps); message = motor1 + steps2; //pinMode(1, OUTPUT); Serial.println(message); //pinMode(1, INPUT); } else if (pHValue >= 7.5 && pHValue <= 8) { //Calculate the need for the phosphoric acid. pHadjustment = H3PO4 * mass * 0.5; //ml/l*l steps = pHadjustment / 0.133333 * 66.6667; //single pumping volume 0.13333 ml, 200 steps full rotation -> 66.667 steps single volume steps = round(steps); steps2 = int(steps); message = motor1 + steps2; //pinMode(1, OUTPUT); Serial.println(message); //pinMode(1, INPUT); } else if (pHValue >= 8) { //Calculate the need for the phosphoric acid. //mass = 10; pHadjustment = H3PO4 * mass; //ml/l*l steps = pHadjustment / 0.133333 * 66.6667; //single pumping volume 0.13333 ml, 200 steps full rotation -> 66.667 steps single volume steps = round(steps); steps2 = int(steps); message = motor1 + steps2; //pinMode(1, OUTPUT); Serial.println(message); //pinMode(1, INPUT); } delay(5000); if(mass > mass0){ fertilizerAdjustment = fertilizer * mass; //ml/l steps3 = fertilizerAdjustment / 0.133333 * 66.6667; steps3 = round(steps3); steps4 = int(steps3); message2 = motor2 + steps4; Serial.println(message2); } mass0 = mass + 0.5; /* temperature = Temperature(); Serial.print(temperature); Serial.println(" C"); */ //pinMode(1, INPUT); delay(90000); }