// LCD1602 to Arduino Uno connection example
#include <LiquidCrystal_I2C.h>
#define I2C_ADDR 0x27
#define LCD_COLUMNS 20
#define LCD_LINES 4
LiquidCrystal_I2C lcd(I2C_ADDR, LCD_COLUMNS, LCD_LINES);
const float BETA = 3950; // should match the Beta Coefficient of the thermistor
int analogValue;
float celsius;
void setup() {
// setup pinmodes
pinMode(A0, INPUT);
for(int i=3; i<=6; i++){
pinMode(i, OUTPUT);
}
// setup lcd
lcd.init();
lcd.backlight();
// update lcd temp
lcd.setCursor(0,0) ;
lcd.print("Temp: ");
lcd.setCursor(12, 0) ;
lcd.print(" C");
lcd.setCursor(0, 3) ;
lcd.print("Amir Hasan Aref Asl");
}
void loop() {
// read analog value
analogValue = analogRead(A0);
// calculate celsius degree
celsius = 1 / (log(1 / (1023. / analogValue - 1)) / BETA + 1.0 / 298.15) - 273.15;
// setup lcd
// clear line 1 temp
lcd.setCursor(6, 0) ;
lcd.print(" ");
lcd.setCursor(6, 0) ;
lcd.print(celsius);
// clear line 1 temp
lcd.setCursor(0,1);
lcd.print(" ");
lcd.setCursor(0,1);
if(celsius < 0){
// too cold
digitalWrite(3, HIGH);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
digitalWrite(6, LOW);
// message
lcd.print("Too Cold");
}
else if(celsius < 20){
// cold
digitalWrite(3, LOW);
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
digitalWrite(6, LOW);
// message
lcd.print("Cold");
}
else if(celsius < 40){
// warm
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, HIGH);
digitalWrite(6, LOW);
// message
lcd.print("Warm");
}
else {
// hot
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
digitalWrite(6, HIGH);
// message
lcd.print("Hot");
}
delay(80);
}