Error : Why my Pump cant turn off?

My pump always turn on, need help.

#include <EEPROM.h>
#include "GravityTDS.h"

#define TdsSensorPin 34
#define RELAY_PIN 35 
#define EEPROM_SIZE 512
#define limittds 560
GravityTDS gravityTds;

float temperature = 28, tdsValue;
float a;
void setup()
{
    Serial.begin(9600);
    
    EEPROM.begin(EEPROM_SIZE);  //Initialize EEPROM
    
    gravityTds.setPin(TdsSensorPin);
    gravityTds.setAref(3.3);  //reference voltage on ADC, default 5.0V on Arduino UNO
    gravityTds.setAdcRange(4096);  //1024 for 10bit ADC;4096 for 12bit ADC
    gravityTds.begin();  //initialization
    pinMode (RELAY_PIN, OUTPUT);
}

void loop()
{
    //temperature = readTemperature();  //add your temperature sensor and read it
    gravityTds.setTemperature(temperature);  // set the temperature and execute temperature compensation
    gravityTds.update();  //sample and calculate
    tdsValue = gravityTds.getTdsValue();  // then get the value
    Serial.print(tdsValue,0);
    Serial.println("ppm");
      if(tdsValue < limittds)  // Nilai Minimal PPM
{
  Serial.println("Not Enough, Pump Turn On");
  digitalWrite(RELAY_PIN,HIGH);  
}
  else if (tdsValue>limittds&&tdsValue<limittds)    
{
  Serial.println("Enough, Pump Turn Off");
  digitalWrite(RELAY_PIN,LOW);
}
  else if(tdsValue > limittds) //
{
  Serial.println("Enough, Pump Turn Off");
  digitalWrite(RELAY_PIN,LOW);  // high percent water high signal to relay to turn on pump
}
    delay(1000);
} 


This is my skecth
Im using
Node MCU ESP32
TDS Sensor Dfrobot (Cant find the sketch on fritzing so I using Ph meter as replacement)
3,3 v Relay
5 v pump
9v battery

Welcome to the forum

Most relay modules are active LOW, ie they turn on when a LOW signal is applied to their control pin

In your code you have this

    Serial.println("Enough, Pump Turn Off");
    digitalWrite(RELAY_PIN, LOW); // high percent water high signal to relay to turn on pump

Are you sure that LOW turns off your relay ?

post a copy of the serial monitor output?
does it show the pump switch on/off messages?


Thats what the serial monitor show, but the pump is still on

I'm following code from google and they use LOW to turns off their relay. So should I still include LOW in my code or maybe LOW should change into another commands?

Write a small sketch to determine whether LOW turns the relay on or off

If you are using a 9V battery like this.


Don't.

Is the relay an opto isolated relay that works on 3V3?

Can you please give an example of that sketch

Is the relay activation pin on GPIO_NUM_35 an AD input only GPIO?

EEPROM on a ESP32 has been depreciated.

Use the Blink example and add prints so that you know the state of the relay input

Yeah im using that 9V battery, so if I cant use that kind of battery should I use these?
image
then changing the battery from 9V to 3,7 V?

how to differentiate relay and optocoupler relay?

Was just wondering if the OP is trying to send an outtie to the innie door?

The info should have been in the relay sales material and or spec sheet.

Yeah my bad I should have use an input and output pin in ESP32, already change it to Pin Number 16, but the pump still cant turn off

when I checked again, thats a relay without optocoupler , will it have any effect if its not an optocoupler relay?

Most likely the ESP32's GPIO_NUM_35, which is an INPUT pin ONLY did not suffer damage.

On a GPIO pin that is capable of output the relay coil current will damage the esp32.

Add a led to pin 35 where relay is connected and see if led is turning off and on

ON A ESP32 GPIO_NUM_35 is an INPUT only pin.

Yeah you are right I checked it.

He should use another pin

And they should use a relay that is opto isolated and compatible with 3V3.