#include <LiquidCrystal_I2C.h>
#define I2C_ADDR 0x27
#define LCD_COLS 16
#define LCD_ROWS 2
LiquidCrystal_I2C lcd(I2C_ADDR, LCD_COLS, LCD_ROWS);
const int ledRedPin = 27;
const int ledGreenPin = 26;
const int ledBluePin = 25;
const int lm35Pin = 23;
const int sliderPin = 13;
const int relayPin = 4;
String relayState = "Off";
int sliderValue = 0;
const float BETA = 3950; // should match the Beta Coefficient of the thermistor
void drawProgressBar(int progress, int maxProgress) {
int progressBarWidth = LCD_COLS - 2; // Leave space for borders
int filledBarWidth = progressBarWidth * progress / maxProgress;
lcd.setCursor(0, 1);
lcd.print("[");
for (int i = 0; i < progressBarWidth; i++) {
if (i < filledBarWidth) {
lcd.print("#");
} else {
lcd.print(" ");
}
}
lcd.print("]");
}
void setColor(int redValue, int greenValue, int blueValue) {
analogWrite(ledRedPin, redValue);
analogWrite(ledGreenPin, greenValue);
analogWrite(ledBluePin, blueValue);
}
void setup() {
analogReadResolution(10);
pinMode(ledRedPin, OUTPUT);
pinMode(ledGreenPin, OUTPUT);
pinMode(ledBluePin, OUTPUT);
pinMode(lm35Pin, INPUT);
pinMode(relayPin, OUTPUT);
lcd.init();
lcd.backlight();
lcd.clear();
Serial.begin(9600);
}
void loop() {
int analogValue = analogRead(lm35Pin);
float celsius = 1 / (log(1 / (1023. / analogValue - 1)) / BETA + 1.0 / 298.15) - 273.15;
sliderValue = analogRead(sliderPin) / 4; // Adjust the division factor based on the range of your slider
int desiredTemp = map(sliderValue, 0, 255, 0, 80);
lcd.setCursor(0, 0);
lcd.print("Temp:");
lcd.print(celsius);
lcd.print(" C");
drawProgressBar(desiredTemp, 80);
if (temperature <= desiredTemp) {
setColor(255, 0, 0);
} else if (temperature >= desiredTemp) {
setColor(0, 255, 0);
}
Serial.println(analogValue);
Serial.println(desiredTemp);
Serial.println(temperature);
Serial.println(relayState);
delay(1000);
}