I am completing a small project, where I take a PH reading and use that value to turn on one of two pumps.
So if PH reading is less than PH6 turn on a PH UP pump, and if reading is greater than PH6 turn on a PH DOWN pump with an allowable range of 1. So it can go to 5 and 7 before it turns on.
I am using two peristaltic pumps, connected to a 12v DC power source using an L298N driver.
The problem is I don’t know where to start to enter the code, I need to insert it in to the code I have for the PH probe.
Currently I have used the code with the probe and added an LCD, and all is good up to that point.
Would anyone have any advice on what the starting point is.
This is the probe I’m using:
I have to define the pins as an output, but then where do I go.
For now I want to get to a stage of where I can turn it on and off, then work from there.
I would greatly appreciate some help.
// PH Probe and LCD
#include <LiquidCrystal.h>
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
float calibration = 22.99; //change this value to calibrate
const int analogInPin = A0;
int sensorValue = 0;
unsigned long int avgValue;
float b;
int buf[10], temp;
void setup() {
lcd.begin(16, 2);
lcd.print("PH Calibrating");
delay(5000);
lcd.clear();
Serial.begin(9600);
}
void loop() {
for (int i = 0; i < 10; i++) {
buf[i] = analogRead(analogInPin);
delay(30);
}
for (int i = 0; i < 9; i++) {
for (int j = i + 1; j < 10; j++) {
if (buf[i] > buf[j]) {
temp = buf[i];
buf[i] = buf[j];
buf[j] = temp;
}
}
}
avgValue = 0;
for (int i = 2; i < 8; i++)
avgValue += buf[i];
float pHVol = (float)avgValue * 5.0 / 1024 / 6;
float phValue = -5.70 * pHVol + calibration;
Serial.print("PH = ");
Serial.println(phValue);
delay(500);
lcd.begin(16, 2);
lcd.print("PH = ");
lcd.print(phValue);
}