Esp32wroom and relay

Hello, could someone help me solve this problem? I have a 38-pin ESP32 Wroom and I want to connect a relay to turn a light on and off with a light sensor, but the problem is that the relay is activated but no longer deactivated. I leave you my diagram and my code.

#define LIGHT_SENSOR_PIN  4  // ESP32 pin GIOP4 (ADC10) connected to light sensor
#define RELAY_PIN         27 // ESP32 pin GIOP27 connected to Relay
#define ANALOG_THRESHOLD  500

void setup() {
  pinMode(RELAY_PIN, OUTPUT); // set ESP32 pin to output mode
}

void loop() {
  int analogValue = analogRead(LIGHT_SENSOR_PIN); // read the value on analog pin

  if (analogValue < ANALOG_THRESHOLD)
    digitalWrite(RELAY_PIN, HIGH); // turn on Relay
  else
    digitalWrite(RELAY_PIN, LOW);  // turn off Relay
}

Your topic has been moved. Please do not post in "Uncategorized"; see the sticky topics in Uncategorized - Arduino Forum.

I would guess the 220 ohm resistor is too low a value.
Add a Serial.println(analogValue); in loop() to check what value you are reading.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.