// LDR & Thermistor Characteristics
const float GAMMA = 0.7; // GAMMA Coefficient for the LDR
const float RL10 = 50; // RL10 Coefficient for the LDR
const float BETA = 3950; // BETA Coefficient for the thermistor
void setup() {
Serial.begin(9600);
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(LED_BUILTIN, digitalRead((3)));
int Switch_Value=digitalRead((3));
if (Switch_Value>0) { // Switch ON/OFF decision
Serial.print("Switch ON ");
// the loop function for Light Reading
int analogValue_Light = analogRead(A8);
float voltage = analogValue_Light / 1024. * 5;
float resistance = 2000 * voltage / (1 - voltage / 5);
float lux = pow(RL10 * 1e3 * pow(10, GAMMA) / resistance, (1 / GAMMA));
Serial.print("Light Status: ");
if (lux > 50) { // 50 lux considered triggering point for Day/Night decision
Serial.print("Day | " + String(lux, 1) + " lux, ");
} else {
Serial.print("Night | " + String(lux, 1) + " lux, ");
}
// the loop function for Temperature Reading
int analogValue_Temp = analogRead(A9);
float celsius = 1 / (log(1 / (1023. / analogValue_Temp - 1)) / BETA + 1.0 / 298.15) - 273.15;
Serial.print("Temperature: ");
if (celsius > 24) { // 24℃ considered triggering point for Hot/Cold decision
Serial.println("Hot | " + String(celsius, 1) + " ℃");
} else {
Serial.println("Cold | " + String(celsius, 1)+ " ℃");
}
}
else {Serial.println("Switch OFF ");}
delay(1000); // wait for a second
}