Hello, I am new to arduino. I want to drain the water of tank to a given level "FCE_VYPOUSTENI" at preset time. I have two water level sensors (UPPER and LOWER). The sensors are SEN0368. When I run the code than PUMP and SOLENOID work properly but when the condition is reached "while (VYMENA_VODY_LOWER_senzor_inPIN == 0);" the pump and solenoid still working....
The sensors works well (when I run serial monitor the 0/1 appears as expected). I am lost. Anyone have any ideas?
Correction: when I use digitalWrite nothing gonna happen (when pinMode then PUMP and SOLENOID works but still the condition WHILE not quit PUMP an SOLENOID)
I tried this (with inserted "Serial.print(digitalRead(VYMENA_VODY_LOWER_senzor_inPIN) );" and when serial monitor is running the expected 0/1 is displayed depending on whether the sensor detects water...
It is because you are not reading the state of the pin. You are reading the state of VYMENA_VODY_LOWER_senzor_inPIN == 0 which will always be false, ie LOW or 0
Are you seen a digitalRead() insude of your print statement? - it read the state of the sensor.
And if we return to the while condition - there is no digitalRead()
Thank you for your time and I appreciate your help. When i use DigitalWrite nothing gonna happen. When I use pinMode then PUMP works but the WHILE condition will not stop the PUMP. Maybe the question is why DigitalWrite does not work...
I dont know if it can help but there is sketch for the sen0368 I used:
I also control the PUMP and SOLENOID (both 12V) by relay but I think it has no impact on the issue.
You set the mode of the pin (INPUT or OUTPUT) not whether the pin is HIGH or LOW
If you use digitalWrite() to set the state of the pin, ie whether it is HIGH or LOW but only if it has been set to a mode of OUTPUT using pinMode() which is usually done in setup()
Please write a sentence explaining what the do loop should actually do
If the preset time occurs, then the pump and solenoid valve are switched on. The water tank is emptied until the liquid sensor detects liquid (changes its state).
The problem is that the pump and solenoid valve do not turn off, so the tank empties further.... which is undesirable.
The sensor responds correctly over the serial line, even the signal light on the sensor turns on/off.