#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C MyLCD(0x27, 20, 4); // Creates I2C LCD Object With (Address=0x27, Cols=20, Rows=4)
//pines y variables para NTC
#define pinNTC 15
const float BETA = 3950;
//Pines y variables para pot
#define pinPot 4
//librerias y variables del sensor 18b20
#include <OneWire.h>
#include <DallasTemperature.h>
#define oneWireBus 12
OneWire oneWire(oneWireBus);
DallasTemperature sensors(&oneWire);
//Pin del led
#define led 33
//Variables
int analogValue;
float celsius;
int potValue;
float temperatureC;
void setup(){
Serial.begin(115200);
pinMode(pinNTC,INPUT);
pinMode(pinPot, INPUT);
pinMode(led, OUTPUT);
analogReadResolution(10);
MyLCD.init();
MyLCD.backlight();
sensors.begin();
}
void loop(){
//Leer el sensor de NTC
analogValue = analogRead(pinNTC);
celsius = 1 / (log(1 / (1023. / analogValue - 1)) / BETA + 1.0 / 298.15) - 273.15;
Serial.print("TEMP1: ");
Serial.println(celsius);
//Leer potenciometro
potValue = analogRead(pinPot);
Serial.print("Pot: ");
Serial.println(potValue);
//leer sensor 18b20
sensors.requestTemperatures();
temperatureC = sensors.getTempCByIndex(0);
Serial.print("S18B20: ");
Serial.print(temperatureC);
Serial.println("ºC");
presentaLCD();
//Condiciones
if(temperatureC >40){
MyLCD.print("NOVEDADES!!!");
digitalWrite(led, HIGH);
}else{
MyLCD.print("S/N ");
if(celsius > 30){
digitalWrite(led, HIGH);
}else{
digitalWrite(led, LOW);
}
}
delay(100);
}
void presentaLCD(){
//Presentar en LCD
MyLCD.setCursor(0, 0);
MyLCD.print("CONTROL DE SENSORES");
MyLCD.setCursor(0, 1);
MyLCD.print("TEMP1: ");
MyLCD.print(celsius);
MyLCD.print(" ");
MyLCD.setCursor(0, 2);
MyLCD.print("POT: ");
MyLCD.print(potValue);
MyLCD.print(" ");
MyLCD.setCursor(0, 3);
MyLCD.print("TEMP 2: ");
}Loading
ds18b20
ds18b20