Now please post your latest sketch that tries to do this so that the code can be compared to the requirement, even if you have posted it before
#include <Wire.h>
#include <DS3231.h>
#include <LiquidCrystal_I2C.h>
#define SOLENOID 3
#define PUMP 8
#define VYMENA_VODY_LOWER_senzor_inPIN 5
#define VYMENA_VODY_LOWER_senzor_modePIN 6
int den;
int hodina;
int minuta;
int sekunda;
bool VYMENA_VODY_LOWER_senzor = 1;
DS3231 rtc;
RTCDateTime datumCas;
LiquidCrystal_I2C lcd(0x27, 20, 4);
void setup () {
Serial.begin(9600);
Wire.begin();
rtc.begin();
//rtc.setDateTime(__DATE__, __TIME__);
//rtc.setDateTime(__DATE__, "12:34:56");
lcd.init();
lcd.backlight();
digitalWrite(SOLENOID, LOW);
digitalWrite(PUMP, LOW);
pinMode(VYMENA_VODY_LOWER_senzor_inPIN, INPUT);
pinMode(VYMENA_VODY_LOWER_senzor_modePIN, OUTPUT);
digitalWrite(VYMENA_VODY_LOWER_senzor_modePIN, VYMENA_VODY_LOWER_senzor);
}
void FCE_HODINY () {
datumCas = rtc.getDateTime();
den = datumCas.day;
hodina = datumCas.hour;
minuta = datumCas.minute;
sekunda = datumCas.second;
lcd.setCursor(0,0);
lcd.print("Cas: ");
lcd.setCursor(10, 0);
lcd.print(hodina); lcd.print(":");
if (minuta <10) {lcd.print(0); lcd.print(minuta);}
else {lcd.print(minuta);} lcd.print(":");
if (sekunda <10) {lcd.print(0); lcd.print(sekunda);}
else {lcd.print(sekunda);}
}
void FCE_VYPOUSTENI () {
if (minuta == 23 && sekunda == 0)
do {pinMode(SOLENOID, HIGH);
pinMode(PUMP, HIGH);}
while (VYMENA_VODY_LOWER_senzor_inPIN == 0);
}
void loop () {
FCE_HODINY ();
FCE_VYPOUSTENI ();
}
void FCE_VYPOUSTENI()
{
if (minuta == 23 && sekunda == 0)
do {
pinMode(SOLENOID, HIGH);
pinMode(PUMP, HIGH);
} while (VYMENA_VODY_LOWER_senzor_inPIN == 0);
}
You don't appear to have changed anything
pinMode() here should be digitalWrite(), assuming that writing HIGH to the SOLENOID and PUMP pins does what you want (does it ?), and the while should have a digitalRead() in it to test the state of the VYMENA_VODY_LOWER_senzor_inPIN pin
Both of these problems have been pointed out before and I even posted the code using the correct functions. See post #17
I have changed pinMode to digitalWrite but the pump and solenoid didn't even turn on. See post #18. When I use your code (post #17) then the pump and solenoid do not turn on, time stops on the display for about 5 seconds, and the output on the serial monitor is 0 (even if the sensor detects or does not detect water (changes the status).
Please post the code when you change it - trying to debug your (simple sounding) issue without it is really hard.
#include <Wire.h>
#include <DS3231.h>
#include <LiquidCrystal_I2C.h>
#define SOLENOID 3
#define PUMP 8
#define VYMENA_VODY_LOWER_senzor_inPIN 5
#define VYMENA_VODY_LOWER_senzor_modePIN 6
int den;
int hodina;
int minuta;
int sekunda;
bool VYMENA_VODY_LOWER_senzor = 1;
DS3231 rtc;
RTCDateTime datumCas;
LiquidCrystal_I2C lcd(0x27, 20, 4);
void setup () {
Serial.begin(9600);
Wire.begin();
rtc.begin();
//rtc.setDateTime(__DATE__, __TIME__);
//rtc.setDateTime(__DATE__, "12:34:56");
lcd.init();
lcd.backlight();
digitalWrite(SOLENOID, LOW);
digitalWrite(PUMP, LOW);
pinMode(VYMENA_VODY_LOWER_senzor_inPIN, INPUT);
pinMode(VYMENA_VODY_LOWER_senzor_modePIN, OUTPUT);
digitalWrite(VYMENA_VODY_LOWER_senzor_modePIN, VYMENA_VODY_LOWER_senzor);
}
void FCE_HODINY () {
datumCas = rtc.getDateTime();
den = datumCas.day;
hodina = datumCas.hour;
minuta = datumCas.minute;
sekunda = datumCas.second;
lcd.setCursor(0,0);
lcd.print("Cas: ");
lcd.setCursor(10, 0);
lcd.print(hodina); lcd.print(":");
if (minuta <10) {lcd.print(0); lcd.print(minuta);}
else {lcd.print(minuta);} lcd.print(":");
if (sekunda <10) {lcd.print(0); lcd.print(sekunda);}
else {lcd.print(sekunda);}
}
void FCE_VYPOUSTENI () {
if (minuta == 10 && sekunda == 30)
do {
digitalWrite(SOLENOID, HIGH);
digitalWrite(PUMP, HIGH);
Serial.print(digitalRead(VYMENA_VODY_LOWER_senzor_inPIN));
Serial.println();
} while (digitalRead(VYMENA_VODY_LOWER_senzor_inPIN) == 0);
}
void loop () {
FCE_HODINY ();
FCE_VYPOUSTENI ();
}
What exactly are the pump and solenoid that you are trying to control ? Can you please post links to them ?
How are the solenoid and pump connected to the Arduino and how are they powered ? How is the Arduino powered ?
If you run a simple sketch that writes HIGH to the solenoid and pump pins in setup() with nothing in loop() do they turn on ?
That looks like a curse for testing; what time is it (minutes and seconds anyway ) now?
This code will only work correctly in one case - if emptying the tank takes no more than a second. If the process lasts longer, the first condition
if (minuta == 10 && sekunda == 30)
ceases to be true and the entire procedure stop testing the water sensor, but the solenoid and pump remain on.
@kilix , judging by the lengthy and fruitless discussion, you absolutely do not feel the logic of the program. You need to read something about state machines
Are you sure ?
if (minuta == 10 && sekunda == 30)
That test initiates the do/while loop but SOLENOID and PUMP will remain HIGH until the VYMENA_VODY_LOWER_senzor_inPIN pin (presumably the low level sensor pin) goes LOW.
...it also remain HIGH after that... because there is nothing in the code that could turn it off.
True
But you were right in your remark - the time condition does not in any way affect the shutdown of the pump.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.