#define LIGHT_SENSOR_PIN 36 // ESP32 pin GIOP36 (ADC0)
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
}
void loop() {
// reads the input on analog pin (value between 0 and 4095)
int analogValue = analogRead(LIGHT_SENSOR_PIN);
Serial.print("Analog Value = ");
Serial.print(analogValue); // the raw analog reading
// We'll have a few threshholds, qualitatively determined
if (analogValue <= 8) {
Serial.println(" => Direct Sunlight");
} else if (analogValue <= 39) {
Serial.println(" => Full Daylight");
} else if (analogValue <= 170) {
Serial.println(" => Overcast Day");
} else if (analogValue <= 281) {
Serial.println(" => Office Lighting");
}else if (analogValue <= 511) {
Serial.println(" => Stairway Lighting");
}else if (analogValue <= 633) {
Serial.println(" => Computer Monitor");
}else if (analogValue <= 853) {
Serial.println(" => Twilight");
}else if (analogValue <= 985) {
Serial.println(" => Deep Twilight");
}
else {
Serial.println(" => Full Moon");
}
delay(500);
}