Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Wire.h>
- float calibration_value = 21.34 + 3;
- int phval = 0;
- unsigned long int avgval;
- int buffer_arr[10],temp;
- float pH_act;
- byte string_received = 0;
- const int Pump_1 = 2; // the Arduino pin, which connects to the pin of relay
- const int Pump_2 = 3; // the Arduino pin, which connects to the pin of relay
- void setup() {
- Wire.begin();
- Serial.begin(9600);
- pinMode(Pump_1, OUTPUT);
- pinMode(Pump_2, OUTPUT);
- }
- void loop() {
- // put your main code here, to run repeatedly:
- for(int i=0;i<10;i++)
- {
- buffer_arr[i]=analogRead(A0);
- delay(30);
- }
- for(int i=0;i<9;i++)
- {
- for(int j=i+1;j<10;j++)
- {
- if(buffer_arr[i]>buffer_arr[j])
- {
- temp=buffer_arr[i];
- buffer_arr[i]=buffer_arr[j];
- buffer_arr[j]=temp;
- }
- }
- }
- avgval=0;
- for(int i=2;i<8;i++)
- {
- avgval+=buffer_arr[i];
- }
- float volt=(float)avgval*5.0/1024/6;
- pH_act = -5.70 * volt + calibration_value;
- Serial.println("pH Val: ");
- Serial.print(pH_act);
- delay(1000);
- if (pH_act < 6.5) { //test condition against pH reading
- Serial.println("PH LEVEL LOW,Pump_1 = ON");
- digitalWrite(Pump_1, HIGH);
- delay(3000);
- //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.
- }
- else {
- digitalWrite(Pump_1, LOW); //if condition is false, send command to turn off pump (called PMP_UP)
- }
- if (pH_act > 7.5) { //test condition against pH reading
- Serial.println("PH LEVEL HIGH,Pump_2 = ON");
- digitalWrite(Pump_2, HIGH);
- 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.
- }
- else {
- digitalWrite(Pump_2, LOW); //if condition is false, send command to turn off pump (called PMP_DOWN)
- }
- Serial.println();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement