#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
int thermistor = A2;
int relay_peltier = A1;
int relay_fan = A0;
float control_temperature = 6.0;
const float BETA = 3950; // should match the Beta Coefficient of the thermistor
void setup() {
Serial.begin(9600);
pinMode(thermistor, INPUT);
pinMode(relay_peltier, OUTPUT);
pinMode(relay_fan, OUTPUT);
lcd.init();
lcd.backlight();
}
void loop() {
int analogValue = analogRead(thermistor);
float celsius = 1 / (log(1 / (1023. / analogValue - 1)) / BETA + 1.0 / 298.15) - 273.15;
Serial.println(celsius);
lcd.setCursor(0, 0);
lcd.print("Temperature:");
lcd.setCursor(0, 1);
lcd.print(celsius);
lcd.setCursor(6, 1);
lcd.print(char(223));
lcd.setCursor(7, 1);
lcd.print("C");
delay(1000);
if (celsius > control_temperature) {
digitalWrite(relay_peltier, LOW);
digitalWrite(relay_fan, LOW);
} else if (celsius < control_temperature) {
digitalWrite(relay_peltier, HIGH);
digitalWrite(relay_fan, HIGH);
}
}