-
Notifications
You must be signed in to change notification settings - Fork 0
/
TURBIDITY.ino
73 lines (59 loc) · 1.57 KB
/
TURBIDITY.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <Wire.h>
#include <EEPROM.h>
#include "GravityTDS.h"
#define TdsSensorPin A0
String str;
#define sensorPin A0
float volt;
float ntu;
float temperature = 25,tdsValue = 0;
GravityTDS gravityTds;
void setup()
{
Serial.begin(115200);
gravityTds.setPin(TdsSensorPin);
gravityTds.setAref(5.0); //reference voltage on ADC, default 5.0V on Arduino UNO
gravityTds.setAdcRange(1024); //1024 for 10bit ADC;4096 for 12bit ADC
gravityTds.begin(); //initialization
delay(2000);
}
void TDS(){
gravityTds.setTemperature(temperature); // set the temperature and execute temperature compensation
gravityTds.update(); //sample and calculate
tdsValue = gravityTds.getTdsValue(); // then get the value
Serial.print("TDS VALUE:");
Serial.print(tdsValue,0);
Serial.println("ppm");
}
void TURBIDITY(){
volt = 0;
int s = analogRead(sensorPin);
for(int i=0; i<800; i++)
{
volt += ((float)analogRead(sensorPin)/1023)*5;
}
volt = volt/800;
volt = round_to_dp(volt,2);
if(volt < 2.5){
ntu = 3;
}else{
ntu = -1120.4*(volt*volt)+5742.3*volt-4353.8;
ntu = ntu/1000;
}
Serial.print("Turbidity : ");
Serial.print(ntu);
Serial.println(" NTU");
Serial.println();
}
void loop()
{
TDS();
TURBIDITY();
delay(700);
}
float round_to_dp( float in_value, int decimal_place )
{
float multiplier = powf( 10.0f, decimal_place );
in_value = roundf( in_value * multiplier ) / multiplier;
return in_value;
}