A photoresistor is an electronic component designed to measure light intensity. This is a resistor whose value varies depending on the amount of light it receives.
The photoresistor is commonly used in projects involving light detection, such as a dark detector, which could turn on an LED as soon as a certain brightness threshold is reached, or in a solar tracker to optimize the orientation of photovoltaic panels.
Other types of sensors can also detect light and convert it into electrical signals, such as photodiode or phototransistor. Here is the diagram on the ESP32 to operate the photoresistor:
// Set GPIO0 pin as analog input
const int photoresistorPin = 0;

void setup() {
  // Initialize serial communication to display the read values
  Serial.begin(115200);
}

void loop() {
  // Read the analog value of the photoresistor (0-4095 for ESP32)
  int sensorValue = analogRead(photoresistorPin);

  // Afficher la valeur lue sur le moniteur série
  Serial.print("Photoresistor value: ");
  if (sensorValue < 3000){
    Serial.println("It's daytime");
  }
  else {
    Serial.println("It's night");
  }

  //Serial.println(sensorValue);

  // Wait a little before the next reading
  delay(1000); // 1 second
}