#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
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?