const float GAMMA = 0.7;
const float RL10 = 50;
#include <LiquidCrystal.h>
#include <Servo.h>
int i = 0;
Servo myservo;
LiquidCrystal lcd(12, 11, 10, 9, 8, 7);
const float BETA = 3950;
void setup() {
Serial.begin(9600);
pinMode(5, OUTPUT);
myservo.attach(6);
lcd.begin(16, 2);
}
void loop() {
int analogValue = analogRead(A0);
float voltage = analogValue / 1024. * 5;
float resistance = 2000 * voltage / (1 - voltage / 5);
float lux = pow(RL10 * 1e3 * pow(10, GAMMA) / resistance, (1 / GAMMA));
float celsius = 1 / (log(1 / (1023. / analogValue - 1)) / BETA + 1.0 / 298.15) - 273.15;
if (celsius <= 25 ) {
digitalWrite(5, LOW);
delay(20);
}
if (celsius > 25 ) {
digitalWrite(5, HIGH);
delay(20);
}
lcd.setCursor(0, 0);
lcd.print("Temperate: ");
lcd.print(celsius);
if (lux >= 50) {
if (myservo.read() != 0) {
myservo.write(0);
delay(500);
}
} else {
if (myservo.read() != 180) {
myservo.write(180);
delay(500);
}
}
lcd.setCursor(0, 1);
lcd.print("lux:");
lcd.print(lux);
delay(100);
}