Advertisement
Guest User

Untitled

a guest
Mar 26th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.70 KB | None | 0 0
  1. float calibration = 21.24;
  2. const int analogInPin = A1;
  3. int sensorValue = 0;
  4. unsigned long int avgValue;
  5. float b;
  6. int buf[10],temp;
  7. void setup() {
  8.  analogReference(DEFAULT);
  9.  Serial.begin(9600);
  10. }
  11.  
  12. void loop() {
  13.  for(int i=0;i<10;i++)
  14.  {
  15.  buf[i]=analogRead(analogInPin);
  16.  delay(30);
  17.  }
  18.  for(int i=0;i<9;i++)
  19.  {
  20.  for(int j=i+1;j<10;j++)
  21.  {
  22.  if(buf[i]>buf[j])
  23.  {
  24.  temp=buf[i];
  25.  buf[i]=buf[j];
  26.  buf[j]=temp;
  27.  }
  28.  }
  29.  }
  30.  avgValue=0;
  31.  for(int i=2;i<8;i++)
  32.  avgValue+=buf[i];
  33.  float pHVol=(float)avgValue*4.5/1000/6;
  34.  Serial.print("phvol = ");
  35.  Serial.println(pHVol);
  36.  float phValue = -5.70 * pHVol + calibration;
  37. Serial.print("sensor = ");
  38.  Serial.println(phValue);
  39.  delay(500);
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement