Go Down

Topic: SEN0161 pH sensor controller help (Read 147 times) previous topic - next topic

Darshal

Jul 15, 2019, 06:54 pm Last Edit: Jul 15, 2019, 07:03 pm by Darshal
Good day.

I am developing a pH controller that pumps pH Up or pH down nutrient according to the measured level of pH in a tank.

I have a pH sensor (SEN0161 DFROBOT) which is an analog input for my system that produces pH values upon placement in different liquids.
I would like my pumps to only go on after 10-15 readings from the pH sensor have been produced.

My current code is as follows:
Code: [Select]


       if (pHValue <5)
        {
          digitalWrite(pHUp,LOW);
          delay(30);
          digitalWrite(pHUp,HIGH);
        }
        if(pHValue>8.5)
        {
          digitalWrite(pHDown,LOW);
          delay(30); 
          digitalWrite(pHDown,HIGH);
        }
        if(pHValue>=5 || pHValue<=8.5)
        {
          digitalWrite(pHUp,HIGH);
          digitalWrite(pHDown,HIGH);
        }


How do I do this?



Regards,
Darshal

wvmarle

Use a counter... increase upon every reading.
Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

Darshal

Hi there.

What is a counter? How do I use a counter?

Regards,

wvmarle

Just a variable that you increase one at a time.
Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

Delta_G

Hi there.

What is a counter? How do I use a counter?

Regards,

Code: [Select]
int nameThisVariableWhateverYouWant = 0;

Then when something happens that you want to count

Code: [Select]
nameThisVariableWhateverYouWant ++;


and when you want to know how many you've counted, just look at that variable:

Code: [Select]
if (nameThisVariableWhateverYouWant > 5) {
     // we've counted more than 5 so do something
|| | ||| | || | ||  ~Woodstock

Please do not PM with technical questions or comments.  Keep Arduino stuff out on the boards where it belongs.

Darshal

Thank you.

In terms of using a 'for' loop or using millis() as a timer, what is the difference?

Delta_G

Thank you.

In terms of using a 'for' loop or using millis() as a timer, what is the difference?
I'm not sure what you're asking.  They're completely different things.  A for loop runs a given set of code over and over until a condition is met.  millis() returns the number of milliseconds since the board was last reset. Only one of those sounds very useful for timing anything. 

Got examples of what you're asking?
|| | ||| | || | ||  ~Woodstock

Please do not PM with technical questions or comments.  Keep Arduino stuff out on the boards where it belongs.

Go Up