#define LDR_PIN 2
// LDR Characteristics
const float GAMMA = 0.7; // GAMMA Coefficient of the LDR
const float RL10 = 50; // RL10 Coefficient of the LDR
const float BETA = 3950; // BETA Coefficient of the thermistor
void setup() {
Serial.begin(9600);
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN, OUTPUT);
// initialize LDR
pinMode(LDR_PIN, INPUT);
// initialize Switch
pinMode(3, INPUT_PULLUP);
}
// 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) {
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) {
Serial.print("Day ");
} else {
Serial.print("Night ");
}
// 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: ");
Serial.print(String(celsius, 1));
Serial.println(" ℃");
}
else {Serial.println("Switch OFF ");}
delay(1000); // wait for a second
}