Advertisement
myarkqub

Untitled

Nov 1st, 2022
1,132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <Wire.h>
  2.  
  3. float calibration_value = 21.34 + 3;
  4. int phval = 0;
  5. unsigned long int avgval;
  6. int buffer_arr[10],temp;
  7. float pH_act;
  8. byte string_received = 0;            
  9.  
  10. const int Pump_1 = 2;  // the Arduino pin, which connects to the pin of relay
  11. const int Pump_2 = 3;  // the Arduino pin, which connects to the pin of relay
  12.  
  13. void setup() {
  14.     Wire.begin();
  15.     Serial.begin(9600);
  16.     pinMode(Pump_1, OUTPUT);
  17.     pinMode(Pump_2, OUTPUT);
  18. }
  19.  
  20. void loop() {
  21.     // put your main code here, to run repeatedly:
  22.     for(int i=0;i<10;i++)
  23.     {
  24.         buffer_arr[i]=analogRead(A0);
  25.         delay(30);
  26.     }
  27.     for(int i=0;i<9;i++)
  28.     {
  29.         for(int j=i+1;j<10;j++)
  30.         {
  31.             if(buffer_arr[i]>buffer_arr[j])
  32.             {
  33.                 temp=buffer_arr[i];
  34.                 buffer_arr[i]=buffer_arr[j];
  35.                 buffer_arr[j]=temp;
  36.             }
  37.         }
  38.     }
  39.     avgval=0;
  40.     for(int i=2;i<8;i++)
  41.     {
  42.         avgval+=buffer_arr[i];
  43.     }
  44.     float volt=(float)avgval*5.0/1024/6;
  45.     pH_act = -5.70 * volt + calibration_value;
  46.  
  47.     Serial.println("pH Val: ");
  48.     Serial.print(pH_act);
  49.     delay(1000);
  50.  
  51.     if (pH_act < 6.5) {     //test condition against pH reading
  52.         Serial.println("PH LEVEL LOW,Pump_1 = ON");
  53.         digitalWrite(Pump_1, HIGH);
  54.         delay(3000);
  55.         //if condition is true, send command to turn on pump (called PMP_UP) and dispense pH up solution, in amounts of 0.5ml. Pump turns clockwise.
  56.     }
  57.     else if (pH_act > 7.5) {        //test condition against pH reading
  58.         Serial.println("PH LEVEL HIGH,Pump_2 = ON");
  59.         digitalWrite(Pump_2, HIGH);
  60.         delay(3000);        //if condition is true, send command to turn on pump (called PMP_DOWN) and dispense pH down solution, in amounts of 0.5ml. Pump turns counter-clockwise.
  61.     }
  62.     else{
  63.         digitalWrite(Pump_1, LOW);      //if condition is false, send command to turn off pump (called PMP_UP)
  64.         digitalWrite(Pump_2, LOW);      //if condition is false, send command to turn off pump (called PMP_DOWN)
  65.     }
  66.     Serial.println();
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement