#include <LiquidCrystal_I2C.h>
#define I2C_ADDR 0x27
#define LCD_COLUMNS 16
#define LCD_LINES 2
LiquidCrystal_I2C lcd(I2C_ADDR, LCD_COLUMNS, LCD_LINES);
/*
About the BETA Coefficient:
// write later
*/
#define BETA 3950 // Beta Coefficient of the thermistor
#define TIME 1000 // Time for delay in microseconds
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
lcd.init();
lcd.backlight();
lcd.setCursor(2, 0);
lcd.print("Temperture:");
}
void loop() {
float temp = ir_sensor_read();
output_temp(temp);
delay(TIME);
}
void output_temp(float temp) {
Serial.println(temp);
lcd.setCursor(5, 1);
lcd.print(temp);
}
// You can change the temperture in digram.json at line 12 for simulation
float ir_sensor_read() {
// put your main code here, to run repeatedly:
int analogValue = analogRead(A0); // the analog port reads having the value of 0~255
// which presents the input signal strength from 0~Vcc
// to celsius code from https://wokwi.com/arduino/projects/299330254810382858 example.
float celsius = 1 / (log(1 / (1023. / analogValue - 1)) / BETA + 1.0 / 298.15) - 273.15;
return celsius;
}