-
Notifications
You must be signed in to change notification settings - Fork 11
/
plant.ino
80 lines (74 loc) · 1.25 KB
/
plant.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
int blue = 0; // for incoming serial data
int moisture_sensor = A0;
int moisture;
int limit = 500;
int pump = 3;
int led = 13;
int pump_time = 3000;
void setup()
{
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
pinMode(moisture_sensor,INPUT);
pinMode(pump,OUTPUT);
pinMode(led,OUTPUT);
}
void loop()
{
moisture = analogRead(moisture_sensor);
Serial.print("Moisture=");
Serial.print(moisture);
Serial.println();
while(Bluetooth()==1)
{
Pump(1);
blue = 0;
break;
}
while(Bluetooth()==0)
{
if(moisture<limit)
{
Pump(1);
break;
}
else
{
Pump(0);
break;
}
}
}
int Bluetooth()
{
// send data only when you receive data:
if(Serial.available() > 0)
{
// read the incoming byte:
blue = Serial.read();
// say what you got:
Serial.print("Bluetooth");
Serial.println(blue);
if(blue == 48)
return 0;
if(blue == 49)
return 1;
}
else
return 0;
}
void Pump(int stat)
{
if(stat == 0)
{
digitalWrite(pump,stat);
digitalWrite(led,stat);
Serial.println("Pump OFF");
}
if(stat == 1)
{
digitalWrite(pump,stat);
digitalWrite(led,stat);
Serial.println("Pump ON");
delay(pump_time);
}
}