// Application to determine the condition of Room lighting
#define LDR_PIN_AO A0
// Arduino ADC parameters
const float VREF = 5.0;
const float ADC_resolution = 10;
void setup() {
Serial.begin(115200); // Configures baudrate of serial port as 115200
}
float get_ldr_voltage() {
int analog_value = analogRead(LDR_PIN_AO); // Reads the analog value from pin
// Voltage conversion formula
float voltage = (analog_value / pow(2,ADC_resolution)) * VREF;
return voltage;
}
void loop() {
float voltage_val = get_ldr_voltage();
Serial.print("Voltage : ");
Serial.println(voltage_val);
// Voltage value for office lighting is 1.37V and for Stairway lighting is 2.5V
// Hence choosing a value of 2V between this range.
// Any value greater than 2V can be assumed to be poor lighting.
if (voltage_val > 2.0) {
Serial.println("Poor room lighting !");
} else {
Serial.println("Good room lighting.");
}
delay(100);
}