#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2); // set the LCD address to 0x27 for a 16 chars and 2 line display
/* TMP36 analog temperature sensor with Arduino example code. More info: https://www.makerguides.com */
// Define to which pin of the Arduino the output of the TMP36 is connected:
#define sensorPin A0
void setup() {
// Begin serial communication at a baud rate of 9600:
Serial.begin(9600);
pinMode(7, OUTPUT);
pinMode(2, OUTPUT);
lcd.init(); // initialize the lcd
lcd.init();
// Print a message to the LCD.
lcd.backlight();
}
void loop() {
const float BETA = 3950; // should match the Beta Coefficient of the thermistor
int analogValue = analogRead(A0);
float celsius = 1 / (log(1 / (1023. / analogValue - 1)) / BETA + 1.0 / 298.15) - 273.15;
if (celsius > 30) {
digitalWrite(7, HIGH);
digitalWrite(2, LOW);
}
else {
digitalWrite(7, LOW);
digitalWrite(2, HIGH);
}
// Print the temperature in the lcd:
lcd.setCursor(0, 0);
lcd.print("temp: ");
lcd.print(celsius);
lcd.print("\337C");
delay(1000);
}