-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSensor_de_Umidade_de_solo.ino
60 lines (41 loc) · 1.1 KB
/
Sensor_de_Umidade_de_solo.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
// Incluindo bibliotecas
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,2,1,0,4,5,6,7,3, POSITIVE);
int umidade;
int led = 2;
void setup()
{
lcd.begin (16,2); // Dimensão da tela
lcd.setBacklight(HIGH); //Liga a luz de fundo
pinMode(led, OUTPUT); // definindo led com saída
}
void loop()
{
umidade = analogRead(A0);
int Porcento = map(umidade, 1023, 0, 0, 100);
// mostra a porcentagem de umidade na tela
lcd.setCursor(0,0);
lcd.print("Umidade:");
lcd.setCursor(9,0);
lcd.print(Porcento);
lcd.setCursor(11,0);
lcd.print("%");
// se a porcentagem for menor ou igual a 20
if(Porcento <=20){ // você pode alterar esse valor se achar necessário
// uma mensagem de aviso surge na tela e o LED é ligado
lcd.setCursor(0,1);
lcd.print("Umidade Baixa !");
lcd.setCursor(0,0);
lcd.print("Umidade:");
lcd.setCursor(9,0);
lcd.print(Porcento);
lcd.setCursor(11,0);
lcd.print("%");
digitalWrite(led, HIGH);
delay(1000);
lcd.clear();
}else{
digitalWrite(led, LOW);
delay(1000);
}}