-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
66 lines (56 loc) · 1.13 KB
/
main.cpp
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 <LiquidCrystal.h>
#include <Servo.h>
bool open;
Servo regar;
LiquidCrystal lcd(12, 11, 7, 8, 9, 10);
void setup()
{
pinMode(A0, INPUT);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
regar.attach(A5);
lcd.begin(16, 1);
lcd.print("Auto Irrigacao");
}
void display()
{
int umidadeDisplay = analogRead(A0);
lcd.begin(17, 2);
lcd.print("Umidade: ");
lcd.print(umidadeDisplay * 10 / 100);
lcd.print("%");
delay(3000);
lcd.clear();
if (open == true)
{
lcd.print("Comporta aberta");
}
else
{
lcd.print("Comporta fechada");
}
}
void loop()
{
delay(5000);
int umidadeSensor = analogRead(A0);
regar.write(0);
if (umidadeSensor <= 450)
{
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
regar.write(92);
open = true;
}
if (umidadeSensor >= 451 && umidadeSensor <= 900)
{
digitalWrite(2, LOW);
digitalWrite(3, HIGH);
digitalWrite(4, LOW);
regar.write(0);
open = false;
};
display();
}