Relay module 5v deenergizing

I'm new to hardware field and currently working with my project.
I'm using esp32 as dev board with temp sensor dht11 and a moisture sensor as input to the board and relay module with will signal to 5v dc motor for on or off. I'm facing issue that once the relay module receives signal it triggers and sounds tick; but when the data signal is cut off it not stop working instead it continuously on's the motor;
can anyone help me with this issue ;
here is the code that i'm using:

#include <DHT.h>  // DHT sensor library

// Define pins
#define RELAY_PIN 26        // Relay connected to GPIO26
#define DHTPIN 4            // DHT11 sensor data pin
#define DHTTYPE DHT11       // Change to DHT22 if using that sensor
#define MOISTURE_SENSOR 34  // Soil moisture sensor analog pin

// Initialize DHT sensor
DHT dht(DHTPIN, DHTTYPE);

void setup() {
    Serial.begin(115200);
    delay(2000); // Allow system to stabilize
 
    pinMode(RELAY_PIN, OUTPUT);
    digitalWrite(RELAY_PIN, LOW); // Ensure pump is OFF initially

    dht.begin(); // Start DHT sensor
    Serial.println("Smart Irrigation System Initialized..."); 
}

void loop() {
    // Read temperature and humidity
    float temperature = dht.readTemperature();
    float humidity = dht.readHumidity();

    // Read soil moisture sensor value
    int moistureValue = analogRead(MOISTURE_SENSOR);
    int moisturePercent = map(moistureValue, 4095, 0, 0, 100); // Convert to percentage

    // Display sensor readings88
    Serial.print("Temperature: ");
    Serial.print(temperature);
    Serial.print("°C | Humidity: ");
    Serial.print(humidity);
    Serial.print("% | Soil Moisture: ");
    Serial.print(moisturePercent);
    Serial.println("%");

    // Watering Logic
    if (moisturePercent < 30) { // If soil is dry
        Serial.println("Soil dry! Turning ON the water pump for 5 minutes."); 
        digitalWrite(RELAY_PIN, HIGH); // Turn ON pump
        delay(5000); // Keep the pump ON for 5 minutes (300,000 ms)
    } else {
        Serial.println("Soil moisture sufficient. Pump remains OFF.");
        digitalWrite(RELAY_PIN, LOW); // Keep pump OFF
    }

    delay(5000); // Wait 5 seconds before checking again
}

I've used the LED in parallel with the relay while it's working properly stops when threshold meets and on's as well

The majority of relay modules are active LOW, ie they turn on when a LOW signal is applied to their input. Check that the relay is actually turning on when you set RELAY_PIN HIGH

If your relay is 5V or more, you should not connect it directly to an ESP32.
The ESP I/O is only 3.3V and you may damage it.

It's not working due to 3.3 V?
I've to use Arduino instead if yes which?

First post a link to the relay module so we can make the best decision

I'm using 5v from vin pin for the vcc in relay. Isn't it okay
Here is the link similar to my relay
https://images.app.goo.gl/Pd8UjZ353ta9yyQeA

Does the Led switch on and off but the relay stays on?

'm using 5v from vin pin for the vcc in relay. Isn't it okay

For that relay it is OK.
Where do you have this LED connected? Is it on the NO/NC pins?
Do you have a resistor in series with the LED?

I don't have any resistor in series the led is connected in parallel to the relay

Exactly the led is working correctly but the relay stays on continuously.

Is the pump connected to NC or NO contact?

The Led will burn and burn the transistor on the relay board , you must use a resistor in series with the led.

Maye be the transistor is already short.

Can't do that. Remove the LED. You may have damage your ESP32

The board already has two LEDs on it

I've used led for testing purpose only that the signal is working or not .
The issue is the relay is not de-energizing.

I've removed the led,
My current issue is that the relay is on continuously and doesn't cut's off the signal after 5 sec delay as in code

How does the relay behave if you run the Blink example and use the relay instead of an LED ?

Do the code print:
"Soil moisture sufficient. Pump remains OFF."

Put the probe in water and power up your project does the relay operate?

Hi, @3farhan

Write some test code that JUST turns the relay ON and OFF, once a second, to prove that the ESP32 and that module work.

If you wrote your code in stages you should already have this piece of test code.

Tom.... :smiley: :+1: :coffee: :australia:

Yes I've tested that piece of code for relay module only but relay wasn't not functioning