1
7const float ArduinoVoltage = 5.00;
8const float ArduinoResolution = ArduinoVoltage / 1024;
9const float resistorValue = 10000.0;
10int threshold = 3;
11int inputPin = A0;
12int ouputPin = A5;
13void setup()
14{
15 Serial.begin(9600);
16 pinMode(ouputPin, OUTPUT);
17 pinMode(inputPin, INPUT);
18}
19void loop()
20{
21 int analogValue=0;
22 int oldAnalogValue=1000;
23 float returnVoltage=0.0;
24 float resistance=0.0;
25 double Siemens;
26 float TDS=0.0;
27 while(((oldAnalogValue-analogValue)>threshold) || (oldAnalogValue<50))
28 {
29 oldAnalogValue = analogValue;
30 digitalWrite( ouputPin, HIGH );
31 delay(10);
32 analogValue = analogRead( inputPin );
33 digitalWrite( ouputPin, LOW );
34 }
35 Serial.print("Return voltage = ");
36 returnVoltage = analogValue *ArduinoResolution;
37 Serial.print(returnVoltage);
38
39 Serial.println(" volts");
40 Serial.print("That works out to a resistance of ");
41 resistance = ((5.00 * resistorValue) / returnVoltage) - resistorValue;
42 Serial.print(resistance);
43 Serial.println(" Ohms.");
44 Serial.print("Which works out to a conductivity of ");
45 Siemens = 1.0/(resistance/1000000);
46 Serial.print(Siemens);
47 Serial.println(" microSiemens.");
48 Serial.print("Total Dissolved Solids are on the order of ");
49 TDS = 500 * (Siemens/1000);
50 Serial.print(TDS);
51 Serial.println(" PPM.");
52 if (returnVoltage>4.9) Serial.println("Are you sure this isn't metal?");
53 delay(5000);
54}
55