Dears I have program that allow me to fill a basin of 100m3 and then to give water to plant starting 18h07 and every hour trying to fill again the basin .
I am using 3 level sensor one to tell me that the basin is full second to tell me that there is water in the basin in order to give water and the third is in the well to assure that there is water in order to fill the basin.
after some days of using the program it's working well but sometimes i found that the basin is already full and water is still coming when i switch off and on the arduino uno the water stop coming from the well and back to normal . so i am assuming that it's not problem of level sensor but maybe arduino hang .
//#include <Wire.h>
#include "RTClib.h"
RTC_DS1307 RTC;
const int capteur_D = 12;
const int capteur_PUITS_BAS = 3;
const int capteur_JEBIA_BAS = 2;
boolean puits_en_marche = false;
int sensorReading;
double runtime = 0.0;
int time_h = 16;
int time_m = 0;
int time_puits_h = 2;
boolean van1 = false;
boolean van2 = false;
boolean van3 = false;
boolean van4 = false;
int lampe;
int lampe2;
unsigned long t = 60UL * 1000UL;
int temps_arrosage = 50;
int nb_jour = 1; // number of day
boolean puits = false;
boolean dayok = false;
int slaveAdd = 10;
//char recChar;
String data = "";
void setup () {
pinMode(5, OUTPUT); // moteur puits
pinMode(11, OUTPUT); // dappe
pinMode(7, OUTPUT); // vanne 1
pinMode(8, OUTPUT); // vanne 2
pinMode(9, OUTPUT); // vanne 3
pinMode(10, OUTPUT); // vanne 4
pinMode(6, OUTPUT); // Vanne zero
digitalWrite(5, LOW);
digitalWrite(6, HIGH);
digitalWrite(7, HIGH);
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
digitalWrite(10, HIGH);
digitalWrite(11, LOW);
pinMode(capteur_D, INPUT_PULLUP);
pinMode(capteur_PUITS_BAS, INPUT_PULLUP);
pinMode(capteur_JEBIA_BAS, INPUT_PULLUP);
Serial.begin(9600);
RTC.begin();
// RTC.adjust(DateTime(2023, 8, 14, 15, 35, 0));
if (! RTC.isrunning()) {
Serial.println(F("RTC is NOT running!"));
//RTC.adjust(DateTime(2023, 7, 5, 19, 14, 20));
}
}
void loop () {
Serial.println(F("debut cycle"));
DateTime now = RTC.now();
Serial.print(now.year(), DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.day(), DEC);
Serial.print(' ');
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println("day of week :");
Serial.print(now.dayOfWeek(), DEC);
Serial.println();
if (digitalRead(capteur_JEBIA_BAS) == HIGH) {
// 20h louta
if ( (now.hour() == 1 || now.hour() == 5 || now.hour() == 9 || now.hour() == 13 || now.hour() == 15) && now.minute() >= 7 && ( now.dayOfWeek() == 2 || now.dayOfWeek() == 4 || now.dayOfWeek() == 6 )) {
Serial.print(F("debut arrosage van 1"));
if (!van1) {
digitalWrite(7, LOW); // vanne 1 on
delay(3000);
digitalWrite(11, HIGH); // dappe on
van1=true;
}
}else {
//delay (t * temps_arrosage);
if (van1){
digitalWrite(11, LOW); // dappe off
delay(3000);
digitalWrite(7, HIGH); // vanne 1 off
van1=false;
}
}
// 21h anis
if ( (now.hour() == 3 || now.hour() == 7 || now.hour() == 11) && now.minute() >= 7 && (now.dayOfWeek() == 0 || now.dayOfWeek() == 2 || now.dayOfWeek() == 4 || now.dayOfWeek() == 6 ) ) {
Serial.print(F("debut arrosage van 2"));
if (!van2) {
digitalWrite(8, LOW); // vanne 2 on
delay(3000);
digitalWrite(11, HIGH); // dappe on
van2=true;
}
}else {
//delay (t * temps_arrosage);
if (van2){
digitalWrite(11, LOW); // dappe off
delay(3000);
digitalWrite(8, HIGH); // vanne 2 off
van2=false;
}
}
// 22h wra dar
if ( (now.hour() == 3 || now.hour() == 7 || now.hour() == 11) && now.minute() >= 7 && (now.dayOfWeek() == 1 || now.dayOfWeek() == 3 || now.dayOfWeek() == 5 )) {
Serial.print(F("debut arrosage van 3"));
if (!van3) {
digitalWrite(9, LOW); // vanne 3 on
digitalWrite(6, LOW); // vanne 0 on
delay(3000);
digitalWrite(11, HIGH); // dape on
van3=true;
}
}else {
//delay (t * temps_arrosage);
if (van3){
digitalWrite(11, LOW); // dappe off
delay(3000);
digitalWrite(9, HIGH); // vanne 3 off
digitalWrite(6, HIGH);
van3=false;
}
}
// 23h mtafla
if ( (now.hour() == 1 || now.hour() == 5 || now.hour() == 9 || now.hour() == 13 || now.hour() == 15) && now.minute() >= 7 && (now.dayOfWeek() == 0 || now.dayOfWeek() == 1 || now.dayOfWeek() == 3 || now.dayOfWeek() == 5 )) {
Serial.print(F("debut arrosage van 4"));
if (!van4) {
digitalWrite(10, LOW); // vanne 2 on
delay(3000);
digitalWrite(11, HIGH); // dappe on
van4=true;
}
}else {
//delay (t * temps_arrosage);
if (van4){
digitalWrite(11, LOW); // dappe off
delay(3000);
digitalWrite(10, HIGH); // vanne 2 off
van4=false;
}
}
}else{
digitalWrite(11, LOW);
delay(3000);
digitalWrite(7, HIGH);
digitalWrite(8, HIGH);
digitalWrite(9, HIGH); // vanne 3 off
digitalWrite(6, HIGH);
digitalWrite(10, HIGH);
delay(t*60);
}
if (now.hour() == 2 || now.hour() == 4 ||
now.hour() == 6 || now.hour() == 8 || now.hour() == 10 || now.hour() == 12 || now.hour() == 14 || now.hour() == 16
|| now.hour() == 18 || now.hour() == 19 || now.hour() == 20 || now.hour() == 21 || now.hour() == 22 || now.hour() == 23 || now.hour() == 0) {
//puits
Serial.println("Capuetr");
Serial.println(digitalRead(capteur_D));
if (digitalRead(capteur_D) == HIGH) // JEBIA FARI5
{
if (!puits_en_marche) {
// check if level puits OK
if (digitalRead(capteur_PUITS_BAS) == HIGH ){
digitalWrite(5, HIGH);
puits_en_marche = true;
}
}
if (puits_en_marche) {
// check if level puits OK
if (digitalRead(capteur_PUITS_BAS) == LOW ){
digitalWrite(5, LOW);
puits_en_marche = false;
delay (t * 6);
}
}
} else { // JEBIA M3EBI
// Serial.print(digitalRead(capteur_PUITS_BAS));
if (puits_en_marche) {
// wait some time to allow more than flotteur
delay (t * 5);
digitalWrite(5, LOW);
puits_en_marche = false;
}
}
} else {
if (puits_en_marche) {
digitalWrite(5, LOW);
puits_en_marche = false;
}
}
delay(1000);
}
can you please help me to find the issue.
regards