-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWateringSystem_v3.ino
More file actions
234 lines (204 loc) · 6.45 KB
/
Copy pathWateringSystem_v3.ino
File metadata and controls
234 lines (204 loc) · 6.45 KB
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
#include <SoftwareSerial.h>
#include <EEPROM.h>
#include <DS3231.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Adafruit_MotorShield.h>
SoftwareSerial Bluetooth(10, 9); // RX, TX
DS3231 rtc(SDA, SCL);
LiquidCrystal_I2C lcd(0x27, 16, 2);
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
Adafruit_StepperMotor *myMotor = AFMS.getStepper(200, 2);
int LED = 8; // LED
String Data; // the data received
//bool ReadFromEEPROMOnStartUp = 0;
int Hour;//Input from Bluetooth and EEPROM
int Minute;//Input from Bluetoothand EEPROM
int Revolutions;//Input from Bluetooth and EEPROM
int RPM;//Input from Bluetooth and EEPROM
int REVStepper;//Calculated from Revolutions
int BTRecOption;
char cData;//Bluetooth Read
String sOption;//Bluetooth Read
String sValue;//Bluetooth Read
String sBluetooth;//Bluetooth Read
String Option;//Option compare
String Value;//Data for Option
Time t;
int CurrentHour;
int CurrentMinute;
bool PumpTimeStart=0;
void setup() {
//Load from EEPROM----------------------------------------------
Revolutions = EEPROM.read(1);
Hour = EEPROM.read(2);
Minute = EEPROM.read(3);
RPM = EEPROM.read(4);
rtc.begin();
lcd.begin();
lcd.backlight();
AFMS.begin();
Bluetooth.begin(9600);
Serial.begin(9600);
myMotor->setSpeed(RPM); //RPM. 200 is good.
myMotor->release();
Serial.println("Waiting for command...");
pinMode(LED,OUTPUT);
//Reset Options
Option = "0";
// The following lines can be uncommented to set the date and time
//rtc.setDOW(WEDNESDAY); // Set Day-of-Week to SUNDAY
//rtc.setTime(15, 37, 0); // Set the time to 12:00:00 (24hr format)
//rtc.setDate(1, 1, 2014); // Set the date to January 1st, 2014
}
void loop() {
//Read Bluetooth Section----------------------------------------
while (Bluetooth.available()) {
delay(10); //small delay to allow input buffer to fill
cData = Bluetooth.read(); //gets one byte from serial buffer
sBluetooth += cData;
sOption = sBluetooth.substring(0,1);
sValue = sBluetooth.substring(2);
digitalWrite(LED,1);
}
if (sOption.length() >0) {
Serial.println("sOption ");
Serial.println(sOption); //prints string to serial port out
Option=sOption;
sOption=""; //clears variable for new input
sBluetooth = "";
digitalWrite(LED,0);
}
if (sValue.length() >0) {
Serial.println("sValue ");
Serial.println(sValue); //prints string to serial port out
Value=sValue;
sValue=""; //clears variable for new input
}
////Option Section-------------------------------
if (Option.length() >0) {
Serial.println("Option ");
Serial.println(Option); //prints string to serial port out
//Option=""; //clears variable for new input
}
if (sBluetooth.length() >0) {
Serial.println("sBluetooth ");
Serial.println(sBluetooth); //prints string to serial port out
//Option=""; //clears variable for new input
}
if(Option=="?"){
Serial.println("Running Option ?");
Bluetooth.println(" ");
Bluetooth.println(" ");
Bluetooth.println("-----------Plant Waterer------------.");
Bluetooth.println("Send 'Option:Value'.");
Bluetooth.println(" ");
Bluetooth.println("? Show Options");
//Bluetooth.println("* Reset Option");
Bluetooth.println("0 Release Motor");
Bluetooth.println("1 Manual Motor On");
Bluetooth.println("2:? Pump Revolutions");
Bluetooth.println("3:? Pump On Hour");
Bluetooth.println("4:? Pump On Minute");
Bluetooth.println("5:? Pump RPM");
Bluetooth.println(" ");
Bluetooth.print("Pump Revolutions: ");
Bluetooth.println(Revolutions);
Bluetooth.print("On Hour: ");
Bluetooth.println(Hour);
Bluetooth.print("On Minute: ");
Bluetooth.println(Minute);
Bluetooth.print("RPM: ");
Bluetooth.println(RPM);
Bluetooth.println(" ");
//Serial.println(Option);//debug..........................
Option="";
}
if(Option=="0"){
digitalWrite(LED,0);
Serial.println("Motor Released");
Bluetooth.println("Motor Released");
myMotor->release();
lcd.setCursor(0,1);
lcd.print("Motor Released");
Option="";
}
else if(Option=="1"){
digitalWrite(LED,1);
Serial.println("Pump On");
Bluetooth.println("Pump On");
lcd.setCursor(0,1);
lcd.print("Pumping");
myMotor->setSpeed(RPM); //RPM. 200 is good.
REVStepper = Revolutions * 200;
myMotor->step(REVStepper, FORWARD, DOUBLE);
//Program halts here until motor has completed revs
//Set Option to '0' to release pump
Option = "0";
}
else if(Option=="2"){
Revolutions = Value.toInt();
Bluetooth.println("Revolutions: Saving to EEPROM");
EEPROM.write(1,Revolutions);//(addr, val);
Option="";
}
else if(Option=="3"){
Hour = Value.toInt();
Bluetooth.println("Hour: Saving to EEPROM");
EEPROM.write(2,Hour);//(addr, val);
Option="";
}
else if(Option=="4"){
Minute = Value.toInt();
Bluetooth.println("Minute: Saving to EEPROM");
EEPROM.write(3,Minute);//(addr, val);
Option="";
}
else if(Option=="5"){
RPM = Value.toInt();
Bluetooth.println("RPM: Saving to EEPROM");
EEPROM.write(4,RPM);//(addr, val);
Option="";
}
else if(Option=="8"){
Bluetooth.println("Reading EEPROM values............");
Bluetooth.print("Revolution: ");
Bluetooth.println(EEPROM.read(1));
Bluetooth.print("Hour: ");
Bluetooth.println(EEPROM.read(2));
Bluetooth.print("Minute: ");
Bluetooth.println(EEPROM.read(3));
Bluetooth.print("RPM: ");
Bluetooth.println(EEPROM.read(4));
Option="";
}
else{;}
//Serial.println(rtc.getTimeStr());
//Serial.print(rtc.getTemp());
//Serial.println(" C");
lcd.setCursor(0,0);
lcd.print(rtc.getTimeStr());
lcd.setCursor(10,0);
lcd.print(((rtc.getTemp()*9/5)+32));
lcd.setCursor(15,0);
lcd.print("F");
t = rtc.getTime();
// Serial.println(t.hour,DEC);
// Serial.println(t.min,DEC);
CurrentHour = t.hour;
CurrentMinute = t.min;
if(CurrentHour == Hour){
if(CurrentMinute == Minute){
if(PumpTimeStart == 0){
Serial.println("Pump Timer Start");
Bluetooth.println("Pump Timer Start");
PumpTimeStart = 1;
Option = 1;
}
}
}
if(CurrentMinute != Minute){
PumpTimeStart = 0;
}
delay(1000);
}