I am trying to make a simple water overflow protection system for my home. I have created it using BC547
and NodeMCU (ESP8266). I have a simple circuit like this:
The problem here is I have 2 wires going into the tank. Which suppose to complete the circuit as soon as water touch both the wires. But the problem here is its by default complete the circuit without even touching, this is happening only in my rooftop water tank. I tried this circuit locally on my desk first and it is working fine. I feel the problem can be humidity inside the tank? Can this be a reason for false trigger?
Here is how I have my code. #define RELAY_1 D1 #define TANK_CONNECTION D4
void setup() {
Serial.begin(115200);
delay(10);
Serial.println("Started");
secondsTick.attach(1, ISRwatchdog);
//Set relay pins to outputs
pinMode(RELAY_1, OUTPUT);
pinMode(TANK_CONNECTION, INPUT);
digitalWrite(RELAY_1, relay_on);
delay(100);
}
void loop() {
tankFull();
delay(100);
}
void tankFull(){
Serial.println(digitalRead(TANK_CONNECTION));
if(!digitalRead(TANK_CONNECTION) && relay_on == 0){
Serial.println(motorOnCount);
motorOnCount++;
motorOffCount = 0;
if(motorOnCount >= 10){
Serial.println("Motor Turn OFF");
digitalWrite(RELAY_1, HIGH);
if (client.connected()) {
client.publish(motor_status, "off", true);
client.publish(tank_full, "on", true);
}
motorOnCount=0;
relay_on = 1;
}
delay(100);
} else{
motorOffCount++;
if (client.connected()) {
client.publish(tank_full, "off", true);
}
//Serial.println(motorOffCount);
if(motorOffCount>=100){
motorOffCount=0;
motorOnCount = 0;
}
}
}
Obviously this is not the full code. I am just trying to share the pattern of its working for basic understanding of the setup I have.
Any one have idea about why its always shows circuit complete even without touching the wires. I have tried with 5v as well and 3.3v as well which are present on NodeMcu Board. But none of them worked properly.
pinMode(TANK_CONNECTION, INPUT_PULLUP);
since you need a pullup resistor with that circuit