#include <LiquidCrystal_I2C.h>
#include <OneWire.h>
#include <DallasTemperature.h>
OneWire pino(3);
DallasTemperature barramento(&pino);
DeviceAddress sensor;
const int RED = 10;
const int GREEN = 9;
const int BLUE = 7;
const int POTENC = A5;
const int BUZZER = 8;
const int pinoBotao = 11;
LiquidCrystal_I2C lcd(0x27,2,1,0,4,5,6,7,3, POSITIVE);
void rgb();
void setup() {
lcd.begin(16,2);
Serial.begin(9600);
pinMode(pinoBotao, INPUT_PULLUP);
pinMode(RED, OUTPUT);
pinMode(GREEN, OUTPUT);
pinMode(BLUE, OUTPUT);
pinMode(POTENC, INPUT);
pinMode(BUZZER, OUTPUT);
barramento.begin();
barramento.getAddress(sensor, 0);
}
int val;
int val2;
int Sen;
void loop() {
val = map(analogRead(0), 0, 1023, 5, 15);
val2 = map(analogRead(2),0,1023,16,24);
Sen = map(analogRead(1), 0, 1023, 0, 29);
delay(100);
Serial.println(pinoBotao);
rgb();
delay(100);
}
int contador=0;
void rgb() {
if(digitalRead(pinoBotao) != 0){
contador ++;
if(contador == 1){
lcd.setCursor(0,0);
lcd.print("Temp: ");
lcd.print(Sen);
lcd.print(" C ");
lcd.print(val);
lcd.println(" ");
if((Sen < val && Sen > 4) || (Sen>val2 && Sen<24)) {
digitalWrite(BLUE, HIGH);
digitalWrite(RED, LOW);
digitalWrite(GREEN, LOW);
lcd.setCursor(0,1);
lcd.print("WARNING ");
lcd.print(val2);
lcd.print(" ");
digitalWrite(BUZZER, HIGH);
delay(800);
digitalWrite(BUZZER, LOW);
delay(3000);
}
else if(Sen>= val && Sen < val2){
digitalWrite(BLUE, LOW);
digitalWrite(RED, LOW);
digitalWrite(GREEN, HIGH);
lcd.setCursor(0,1);
lcd.print("ACEITAVEL ");
lcd.print(val2);
lcd.print(" ");
delay(1500);
}
else if(Sen <= 4 || Sen >= 25) {
digitalWrite(BLUE, LOW);
digitalWrite(RED, HIGH);
digitalWrite(GREEN, LOW);
lcd.setCursor(0,1);
lcd.print("CRITICO ");
lcd.print(" ");
lcd.print(val2);
lcd.print(" ");
digitalWrite(BUZZER, HIGH);
delay(800);
digitalWrite(BUZZER, LOW);
delay(800);
}
}
if(digitalRead(pinoBotao) ==0){
while(1){
barramento.requestTemperatures();
float temperatura = barramento.getTempC(sensor);
Serial.println(temperatura);
delay(500);
lcd.setCursor(0,0);
lcd.print("Temp: ");
lcd.print(temperatura);
lcd.print(" C ");
lcd.print(val);
lcd.println(" ");
if((temperatura < val && Sen > 4) || (temperatura>val2 && temperatura<24)) {
digitalWrite(BLUE, HIGH);
digitalWrite(RED, LOW);
digitalWrite(GREEN, LOW);
lcd.setCursor(0,1);
lcd.print("WARNING ");
lcd.print(val2);
lcd.print(" ");
digitalWrite(BUZZER, HIGH);
delay(800);
digitalWrite(BUZZER, LOW);
delay(3000);
}
else if(temperatura>= val && temperatura < val2){
digitalWrite(BLUE, LOW);
digitalWrite(RED, LOW);
digitalWrite(GREEN, HIGH);
lcd.setCursor(0,1);
lcd.print("ACEITAVEL ");
lcd.print(val2);
lcd.print(" ");
delay(1500);
}
else if(temperatura <= 4 || temperatura >= 25) {
digitalWrite(BLUE, LOW);
digitalWrite(RED, HIGH);
digitalWrite(GREEN, LOW);
lcd.setCursor(0,1);
lcd.print("CRITICO ");
lcd.print(val2);
lcd.print(" ");
digitalWrite(BUZZER, HIGH);
delay(800);
digitalWrite(BUZZER, LOW);
delay(800);
}
if(digitalRead(11) != 0){
break;
}
}
}
contador = 0;
}
}
Comments