-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgardener.ino
112 lines (85 loc) · 2.18 KB
/
gardener.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#include <Wire.h>
#include <LiquidCrystal.h>
#include <SoftwareSerial.h>
#include <string>
#include "PhProbe.h"
#include "EcProbe.h"
#include "Pump.h"
#include "Valve.h"
#define pHSensorRX 3
#define pHSensorTX 2
#define eCSensorRX 5
#define eCSensorTX 4
#define usSensorEcho 6
#define usSensorTrigger 7
#define height 32
#define pumpPin 10
#define valvePin 9
PhProbe pHSensor(pHSensorRX, pHSensorTX);
EcProbe eCSensor(eCSensorRX, eCSensorTX);
Pump drainPump(pumpPin);
Valve reservoirValve(valvePin);
LiquidCrystal lcd(0);
char computerdata[20];
byte received_from_computer=0;
void updateDisplay() {
lcd.setCursor(0, 0);
lcd.print("pH: ");
lcd.setCursor(0,1);
lcd.print("TDS: ");
lcd.setCursor(0,2);
lcd.print("cm: ");
lcd.setCursor(0,3);
lcd.print("Pump: ");
lcd.setCursor(10,3);
lcd.print("Valve: ");
lcd.setCursor(4,0);
lcd.print("6.5 (good)");
lcd.setCursor(5,1);
lcd.print("1000 ppm");
lcd.setCursor(4,2);
lcd.print("25 / 32");
lcd.setCursor(6,3);
lcd.print("off");
lcd.setCursor(17,3);
lcd.print("off");
}
void setup() {
pinMode(pumpPin, OUTPUT);
pinMode(valvePin, OUTPUT);
Serial.begin(9600);
pHSensor.begin(9600);
eCSensor.begin(9600);
lcd.begin(20, 4);
lcd.setBacklight(HIGH);
}
void serialEventRun(void) {
if (Serial.available()) serialEvent();
}
void serialEvent() {
received_from_computer = Serial.readBytesUntil(13,computerdata,20);
computerdata[received_from_computer]=0;
String module = String(computerdata[0]) + String(computerdata[1]);
String command = String(computerdata[2]) + String(computerdata[3]) + String(computerdata[4]) + String(computerdata[5]);
String parameter = String(computerdata[6]);
if (module == "PH") {
pHSensor.command(command, parameter);
} else if (module == "EC") {
eCSensor.command(command, parameter);
} else if (module == "PM") {
drainPump.command(command, parameter);
} else if (module == "VL") {
reservoirValve.command(command, parameter);
} else {
Serial.println("ERMODU");
}
}
void loop(){
if(pHSensor.available() > 0) {
pHSensor.read();
}
if(eCSensor.available() > 0) {
eCSensor.read();
}
updateDisplay();
}