/*
* This ESP32 code is created by esp32io.com
*
* This ESP32 code is released in the public domain
*
* For more detail (instruction and wiring diagram), visit https://esp32io.com/tutorials/esp32-light-sensor
*/
#define LIGHT_SENSOR_PIN 35// ESP32 pin GIOP36 (ADC0)
int led=33;
void setup() {
// initialize serial communication at 9600 bits per second:
pinMode(led, OUTPUT);
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 < 40) {
Serial.println(" => Dark");
digitalWrite(led, HIGH);
} else if (analogValue < 800) {
Serial.println(" => Dim");
digitalWrite(led, HIGH);
} else if (analogValue < 2000) {
Serial.println(" => Light");
digitalWrite(led, LOW);
} else if (analogValue < 3200) {
Serial.println(" => Bright");
digitalWrite(led, LOW);
} else {
Serial.println(" => Very bright");
digitalWrite(led, LOW);
}
delay(500);
}