Hi!
I have looked at a lot of posts for controlling of the function millis(), but I need it to reset somehow. My program is about achieving a constant PH value, by controlling two pumps (one for acid and one for base). For instance, if the PH value goes above 7,10, then deliver a digital signal to turn on pump for acid. If it goes below 6,90, then deliver a digital signal to turn on pump for base. I only want the digital signal to be on for 3 seconds, and then wait a little while for the solution to stabilize and check the PH value.
My program so far:
const int acid = 6;
const int base = 8;
const int ledPin = 13;
int val = 0;
const double analogPin = 0;
unsigned long startMillis = 0;
const long interval = 3000;
void setup() {
Serial.begin(9600);
pinMode(acid, OUTPUT);
digitalWrite(acid, HIGH);
pinMode(base, OUTPUT);
digitalWrite(base, HIGH);
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);
delay(1000);
}
void loop() {
unsigned long currentMillis = millis();
val = analogRead(analogPin);
Serial.println(val);
if(val < 550) {
if(currentMillis - startMillis >= interval){
digitalWrite(acid, LOW);
startMillis = currentMillis;}
digitalWrite(acid, HIGH);
} else {
digitalWrite(acid, LOW);
}
if (val > 450){
if(currentMillis = startMillis > interval){
digitalWrite(base, LOW);
startMillis = currentMillis;}
digitalWrite(base, HIGH);
} else digitalWrite(base, LOW);
delay(500);
}
Constant_PH.ino (951 Bytes)