#include "RTClib.h"
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,20,4);
const float BETA = 3950;
RTC_DS1307 rtc;
void setup() {
//Para o LCD
lcd.init();
lcd.backlight();
//Para o RTC
if (! rtc.begin()) {
Serial.println("RTC não identificado!");
Serial.flush();
abort();
}
Serial.begin(115200);
}
void loop() {
int tempV1, tempV2, tempV3, tempV4;
float temp1, temp2, temp3, temp4;
tempV1 = analogRead(A0);
tempV2 = analogRead(A1);
tempV3 = analogRead(A2);
tempV4 = analogRead(A3);
//Conversão
temp1 = 1 / (log(1 / (1023. / tempV1 - 1)) / BETA + 1.0 / 298.15) - 273.15;
temp2 = 1 / (log(1 / (1023. / tempV2 - 1)) / BETA + 1.0 / 298.15) - 273.15;
temp3 = 1 / (log(1 / (1023. / tempV3 - 1)) / BETA + 1.0 / 298.15) - 273.15;
temp4 = 1 / (log(1 / (1023. / tempV4 - 1)) / BETA + 1.0 / 298.15) - 273.15;
//Tela LCD
lcd.setCursor(0,0);
lcd.print("Sensores Temperatura");
//Exibição da data
DateTime now = rtc.now();
lcd.setCursor(2,1);
lcd.print(now.hour(), DEC); lcd.print("h: ");
lcd.print(now.minute(), DEC); lcd.print("min: ");
lcd.print(now.second(), DEC); lcd.print("s");
//Exibição das temperaturas
lcd.setCursor(0,2); lcd.print("T1:"); lcd.print(temp1,1); lcd.print('\xDF'); lcd.print("C");
lcd.setCursor(0,3); lcd.print("T2:"); lcd.print(temp2,1); lcd.print('\xDF'); lcd.print("C");
lcd.setCursor(11,2); lcd.print("T3:"); lcd.print(temp3,1); lcd.print('\xDF'); lcd.print("C");
lcd.setCursor(11,3); lcd.print("T4:"); lcd.print(temp4,1); lcd.print('\xDF'); lcd.print("C");
}
Vermelho - Vcc
Preto - GND
Azul - SCL
Cinza - SDA
Amarelo - Ligação sensor de temperatura - ARDUINO