1
2#include <SoftwareSerial.h>
3#include <LiquidCrystal.h>
4
5
6SoftwareSerial BTserial(3,2);
7
8
9
10float reads;
11int pin = A0;
12
13float vOut = 0 ;
14float vIn = 5;
15float R1 = 1000;
16float R2 = 0;
17float buffer = 0;
18float TDS;
19
20float R = 0;
21float r = 0;
22float L = 0.06;
23double A = 0.000154;
24
25float C = 0;
26float Cm = 0;
27
28int rPin = 9;
29int bPin = 5;
30int gPin = 6;
31int rVal = 255;
32int bVal = 255;
33int gVal = 255;
34
35
36
37
38LiquidCrystal lcd(7,8,10,11,12,13);
39
40void setup() {
41
42 Serial.begin(9600);
43 BTserial.begin(9600);
44
45
46 lcd.begin(16, 2);
47
48
49 pinMode(rPin,OUTPUT);
50 pinMode(bPin,OUTPUT);
51 pinMode(gPin,OUTPUT);
52 pinMode(pin,INPUT);
53
54 lcd.print("Conductivity: ");
55}
56
57void loop() {
58 reads = analogRead(A0);
59
60 vOut = reads*5/1023;
61 Serial.println(reads);
62
63 buffer = (vIn/vOut)-1;
64 R2 = R1*buffer;
65 Serial.println(R2);
66 delay(500);
67
68
69 r = R2*A/L;
70
71 C = 1/r;
72 Cm = C*10;
73
74 TDS = Cm *700;
75
76 lcd.setCursor(0,1);
77 lcd.println(C);
78
79
80 if( reads < 600 )
81 {
82 if (reads <= 300){
83 setColor( 255, 0, 255 ) ;
84 }
85 if (reads > 200){
86 setColor( 200, 0, 255 ) ;
87 }
88 }
89 else{
90 if( reads <= 900 )
91 {
92 setColor( 0, 0, 255 ) ;
93 }
94 if( reads > 700 )
95 {
96 setColor( 0, 255, 255 ) ;
97 }
98 }
99
100
101BTserial.print(C);
102BTserial.print(",");
103BTserial.print(TDS);
104BTserial.print(";");
105delay(500);
106}
107
108
109void setColor(int red, int green, int blue)
110{
111 analogWrite( rPin, 255 - red ) ;
112 analogWrite( gPin, 255 - green ) ;
113 analogWrite( bPin, 255 - blue ) ;
114}