#define NTC A0
#define led1 8
#define led2 9
#define led3 10
#define led4 11
#define led5 12
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup() {
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
pinMode(led5, OUTPUT);
lcd.init();
lcd.backlight();
lcd.print("Rachaporn");
lcd.setCursor(0, 1);
lcd.print("Temp: ");
}
void loop() {
float tempC = 1 / (log(1 / (1023. / analogRead(NTC) - 1)) / 3950 + 1.0 / 298.15) - 273.15;
lcd.setCursor(6, 1);
lcd.print(tempC, 1);
lcd.print((char)223);
lcd.print("c ");
if (tempC > 11.0 && tempC < 13.9)
{
digitalWrite(led1, 1);
digitalWrite(led2, 0);
digitalWrite(led3, 0);
digitalWrite(led4, 0);
digitalWrite(led5, 0);
}
else if (tempC > 14.0 && tempC < 19.9)
{
digitalWrite(led1, 1);
digitalWrite(led2, 1);
digitalWrite(led3, 0);
digitalWrite(led4, 0);
digitalWrite(led5, 0);
}
else if (tempC > 20.0 && tempC < 24.9)
{
digitalWrite(led1, 1);
digitalWrite(led2, 1);
digitalWrite(led3, 1);
digitalWrite(led4, 0);
digitalWrite(led5, 0);
}
else if (tempC > 25.0 && tempC < 29.9)
{
digitalWrite(led1, 1);
digitalWrite(led2, 1);
digitalWrite(led3, 1);
digitalWrite(led4, 1);
digitalWrite(led5, 0);
}
else if (tempC > 30.0 && tempC < 35.0)
{
digitalWrite(led1, 1);
digitalWrite(led2, 1);
digitalWrite(led3, 1);
digitalWrite(led4, 1);
digitalWrite(led5, 1);
}
delay(1000);
}