-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathH2Organizer.ino
66 lines (54 loc) · 1.44 KB
/
H2Organizer.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
#include <SoftwareSerial.h>
int bluetoothTx = 2;
int bluetoothRx = 3;
SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);
int sensorPin = A0;
int thresholdUp = 400;
int thresholdDown = 250;
void setup()
{
//Setup usb serial connection to computer
Serial.begin(9600);
//Setup Bluetooth serial connection to android
bluetooth.begin(115200);
bluetooth.print("$$$");
delay(100);
bluetooth.println("U,9600,N");
bluetooth.begin(9600);
}
void loop()
{
int sensorValue;
sensorValue = analogRead(sensorPin);
String DisplayWords_a;
String DisplayWords_b;
String DisplayWords_c;
Serial.println(sensorValue);
delay(2000);
//Read from bluetooth and write to usb serial
if(bluetooth.available())
{
char toSend = (char)bluetooth.read();
//bluetooth.print(sensorValue);
if (sensorValue <= thresholdDown){
DisplayWords_a = "This plant is thirsty!\nYou have to water it.";
bluetooth.println("\n");
bluetooth.println(DisplayWords_a);
} else if (sensorValue >= thresholdUp){
DisplayWords_b = "This plant is alright!";
bluetooth.println(DisplayWords_b);
} else {
DisplayWords_c = "Error";
bluetooth.println(DisplayWords_c);
}
Serial.print(toSend);
delay(1000);
}
//Read from usb serial to bluetooth
if(Serial.available())
{
char toSend = (char)Serial.read();
bluetooth.print(toSend);
Serial.print(toSend);
}
}