#include <LiquidCrystal.h>
#include <math.h>
const int thermistor_output = A0;
const float BETA = 3950;
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
#include <Stepper.h>
const int stepsPerRevolution = 200;
Stepper stepper(stepsPerRevolution, 6, 7, 8, 9);
int stepCount = 0;
int maxTemp = 80;
int minTemp = -24;
void setup() {
lcd.begin(16, 2);
lcd.print("hello, world!");
pinMode(thermistor_output, INPUT);
}
void loop() {
float temperature = getTemperature();
int speed = map(round(temperature), minTemp, maxTemp, 1, 100);
stepper.setSpeed(speed);
stepper.step(2);
if (temperature < 15) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Its cold. fan slow");
lcd.setCursor(0, 1);
lcd.print(temperature);
} else if (temperature >= 15 && temperature < 25) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Nice Weather");
lcd.setCursor(0, 1);
lcd.print(temperature);
} else {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Its Hot. fan fast");
lcd.setCursor(0, 1);
lcd.print(temperature);
}
}
float getTemperature() {
int analogValue = analogRead(thermistor_output);
float celsius = 1 / (log(1 / (1023. / analogValue - 1)) / BETA + 1.0 / 298.15) - 273.15;
return celsius;
}