/*
Exercise
Step 1: Using https://wokwi.com/projects/new/arduino-uno, connect an LCD 16x2 (I2C) display to the board and print "Hello, World!".
Step 2: Connect a temperature sensor and print the ambient temperature on the display.
*/
#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);
int num = 100;
void setup() {
// put your setup code here, to run once:
lcd.init();
lcd.backlight();
lcd.print("Hello World");
}
void loop() {
// put your main code here, to run repeatedly:
delay(1000);
lcd.clear();
lcd.print(readTemp());
}
float readTemp() {
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;
return celsius;
}