#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <OneWire.h>
#include <DallasTemperature.h>
// Configuraciones
#define PinLed 27
const int POT_PIN = 35;
const float BETA = 3950;
const int oneWireBus = 4;
int potValue = 0;
LiquidCrystal_I2C lcd(0x27, 20, 4);
OneWire ourWire(4);
DallasTemperature sensors(&ourWire);
void setup() {
lcd.init();
lcd.backlight();
analogReadResolution(10);
pinMode(15,INPUT);
pinMode( PinLed ,OUTPUT);
sensors.begin();
}
void loop() {
int potValue = analogRead(POT_PIN); // Leer el valor del potenciómetro
lcd.setBacklight(map(potValue, 0, 1023, 0, 100)); // LCD
// Leer la temperatura del NTC
int analogValue = analogRead(15);
float celsius = 1 / (log(1 / (1023. / analogValue - 1)) / BETA + 1.0 / 298.15) - 273.15;
// Leer la temperatura del DS18B20
sensors.requestTemperatures();
float temperatureC = sensors.getTempCByIndex(0);
// Mostrar la información en el LCD
lcd.setCursor(0, 0);
lcd.print("CONTROL DE SENSORES");
lcd.setCursor(0, 1);
lcd.print("Temp 1: ");
lcd.print(celsius);
lcd.print(" C");
lcd.setCursor(0, 2);
lcd.print("POT: ");
lcd.print(potValue);
lcd.setCursor(0, 3);
lcd.print("Temp 2: ");
lcd.print(temperatureC);
lcd.print(" C");
//condicion de led
if(celsius>=40)
digitalWrite(PinLed, HIGH);
else
digitalWrite(PinLed, LOW);
delay(1000);
}