I'm making a circuit with a temperature sensor. When the temperature goes above 40ºC, a hot display appears and a red LED turns on; if the temperature is between 18º and 25ºC the display says mild and a green LED lights up; and if it is at 15ºC it appears cold on the display and a blue LED lights up
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP280.h>
#include <LiquidCrystal_I2C.h>
Adafruit_BMP280 bmp;
LiquidCrystal_I2C lcd(0x27, 16, 2); // Endereço I2C do display LCD
const int redLed = 8;
const int greenLed = 10;
const int blueLed = 9;
void setup() {
Serial.begin(9600);
if (!bmp.begin()) {
Serial.println("Erro ao iniciar o sensor BMP280. Verifique as conexões!");
while (1);
}
lcd.begin(16, 2);
lcd.clear();
lcd.print("Monitor de Temp.");
pinMode(redLed, OUTPUT);
pinMode(greenLed, OUTPUT);
pinMode(blueLed, OUTPUT);
}
void loop() {
float temperatura = bmp.readTemperature();
Serial.print("Temperatura: ");
Serial.print(temperatura);
Serial.println(" °C");
if (temperatura > 40.0) {
digitalWrite(redLed, HIGH);
digitalWrite(greenLed, LOW);
digitalWrite(blueLed, LOW);
lcd.clear();
lcd.print("QUENTE");
} else if (temperatura >= 18.0 && temperatura <= 24.0) {
digitalWrite(redLed, LOW);
digitalWrite(greenLed, HIGH);
digitalWrite(blueLed, LOW);
lcd.clear();
lcd.print("AMENO");
} else if (temperatura < 17.0) {
digitalWrite(redLed, LOW);
digitalWrite(greenLed, LOW);
digitalWrite(blueLed, HIGH);
lcd.clear();
lcd.print("FRIO");
} else {
digitalWrite(redLed, LOW);
digitalWrite(greenLed, LOW);
digitalWrite(blueLed, LOW);
lcd.clear();
lcd.print("NORMAL");
}
delay(2000); // Aguarda 2 segundos antes de fazer a próxima leitura
}