#define LDR_PIN_digital 2
#define LDR_PIN_analog A0
void read_photoresistor();
void setup()
{
Serial.begin(115200);
pinMode(LDR_PIN_digital, INPUT);
}
void loop()
{
read_photoresistor();
}
void read_photoresistor()
{
if (digitalRead(LDR_PIN_digital) == LOW)
{
Serial.println(" Light ");
}
else
{
Serial.println(" Dark ");
}
delay(100);
const float GAMMA = 0.7;
const float RL10 = 50;
// Convert the analog value into lux value:
int analogValue = analogRead(LDR_PIN_analog);
float voltage = analogValue / 1024. * 5;
float resistance = 2000 * voltage / (1 - voltage / 5);
float lux = pow(RL10 * 1e3 * pow(10, GAMMA) / resistance, (1 / GAMMA));
Serial.print(" Light intensity: ");
Serial.println(lux);
}