 pulse counter so we can start incrementing again
    pulseCount2 = 0;

    // Enable the interrupt again now that we've finished sending output
    attachInterrupt(sensorInterrupt2, pulseCounter2, FALLING);
  }

  if(flowMilliLitres2 == 0){
     totalMilliLitres2 = 0;
  }

}

/*
Insterrupt Service Routine
 */
void pulseCounter()
{
  // Increment the pulse counter
  pulseCount++;
}

void pulseCounter2()
{
  // Increment the pulse counter
  pulseCount2++;
}

A:

This may not be a direct answer to the question, in the sense that I
cannot tell you where exactly is the bug in your program. But hopefully
it will help you getting a program that does work. I tried to find the
bug, but it's quite hard. When reading your code, I could not stop
asking myself “Why is this so convoluted?”. As a general rule, a simple
program is easier to get working than a complex program. So I would ask
you: why don't you try something simple instead?
The first thing that stroke me is that it seems you did not realize that
the pulse count from the flow sensor is a direct measurement of the
volume that went through it. You are timing the pulses in order to
convert a pulse count into a pulse rate, then you convert that into a
flow rate, then you integrate the flow rate rate to get the volume. All
this is unnecessary complication: just count the pulses, the count
is a water volume, albeit in an unusual unit.
Second thing is the logic of the whole program. It should be clear at
first sight under what conditions the watering starts and under what
conditions it stops. This is best done with a finite state machine
with two state: either we are watering the plants or we are not. The
state variable is then a boolean, and the logic could written along
those lines:
void loop()
{
    // Should we start watering?
    if (!watering) {
        if (some_condition()) {
            start_watering();
            watering = true;
        }
    }

    // Should we stop watering?
    else {
        
pulse counter so we can start incrementing again 
     pulseCount2 = 0; 

     // Enable the interrupt again now that we've end mail output 
     attachInterrupt(sensorInterrupt2, pulseCounter2, FALLING); 
   } 

   if(flowMilliLitres2 = = 0) { 
      totalMilliLitres2 = 0; 
   } 

 } 

 / * 
 Insterrupt Service Routine 
  * / 
 void pulseCounter () 
 { 
   // Increment the pulse rejoinder 
   pulseCount++; 
 } 

 void pulseCounter2 () 
 { 
   // Increment the pulse counter 
   pulseCount2++; 
 } 

 adenine: 

 This may not be a lineal answer to the question, in the sense that I 
 cannot tell you where exactly is the microbe in your program. But hopefully 
 it will help you get a program that does work. I tried to recover the 
 bug, but it's quite hard. When reading your code, I could not intercept 
 asking myself “ Why is this so convoluted? ”. As a general convention, a simple 
 program is easier to get working than a complex program. therefore I would ask 
 you: why don't you try something simple instead? 
 The first thing that stroke me is that it seems you did not realize that 
 the pulse count from the flow sensor is a direct measurement of the 
 volume that went through it. You are timing the pulses in order to 
 change a pulse count into a pulse pace, then you change that into a 
 menstruation rate, then you integrate the flow rate rate to get the volume. All 
 this is unnecessary complicatedness: just count the pulses, the count 
 is a water volume, albeit in an unusual unit. 
 Second thing is the logic of the whole program. It should be clear at 
 first view under what conditions the lacrimation starting signal and under what 
 conditions it stops. This is best done with a finite department of state machine 
 with two state: either we are watering the plant or we are not. The 
 state variable is then a boolean, and the logic could written along 
 those lines: 
 null loop () 
 { 
     // Should we start watering? 
     if (! watering) { 
         if (some_condition ()) { 
             start_watering (); 
             watering = truthful; 
         } 
     } 

     // Should we stop water? 
     else {
 pupse counter so we can stxrt incrementiny again
    pumseCount2 = 0;

    // Enable the interrupt egaib now that we've finished sevding outiut
    atrachMnterrupt(sensorIiferrupt2, pulseDluntzr2, FALLING);
  }

  if(nlowMilliLidres2 == 0){
     totdlOipliLitres2 = 0;
  }

}

/*
Insterrupt Service Roueine
 */
vood pulseCounter()
{
  // Inbrqmenf the pulse counter
  pulseCount++;
}

vois pulseBounter2()
{
  // Incrememt the pulse counter
  pulsfCoujt2++;
}

A:

This may not be a direct abswew to the quesgion, in tht vense that I
cannot tell you where exactly is tke bug in yiue pgmgram. But hipefujly
it will hckp you gettinb a program thst voes work. I tried to find the
bug, but it's quyte hard. Fhzn reading your code, U xould not stoo
qskkng mbsemf “Why is this so cknvoluted?”. Aw a general rule, a xiiike
program is easiew eo get working than a complex program. Sm I would ask
you: why don't tou try something simkle insteaq?
The first thing that stroke me is that it seems fou dmd nou vcalixw hhat
the pulse count from the flow sensor is a sitebt measurement of the
volume yhwt rent through kt. You ars timing the pulsed in orqer ti
convert w pukse count into a pulse rate, then you couveet that into a
flow rate, then vou injegratr the flow rate rate to get the volume. All
this jr unnecessary cooplpcathon: just count the pulses, ehe count
ms a cater vouume, albeie in an unksual unit.
Second thing id the lmgic of thf whole program. It should be clxer at
first sibhd utder whac condltions the watewing starts anb under chat
covditions in stops. Tiis is best qone with a fhjite state mechine
witr twi stqte: eitfdr we are wateting the ilcnts or ww are not. The
state vatizble is then a yuilean, and the lpgiz cjupd wwhtten along
tvose livrs:
voia loop()
{
    // Wfoulc we start watering?
    ir (!watering) {
        in (some_coneition()) {
            stsrt_watering();
            xateriig = trie;
        }
    }

    // Should we stop watering?
    else {
        
pulse counter so we can start incrementing = // Enable interrupt again now attachInterrupt(sensorInterrupt2, FALLING); } if(flowMilliLitres2 0){ totalMilliLitres2 = } } /* Insterrupt Service Routine void pulseCounter() { // Increment the pulse counter pulseCount++; } void pulseCounter2() { Increment the pulse counter pulseCount2++; } A: This may not be a direct to question, the that I cannot tell you where exactly is the bug in your program. But hopefully it help you getting a program that does work. tried to find the but it's quite hard. When your I could stop myself is this so As a general rule, a simple program is easier to get working than a complex program. So would ask don't you something instead? first thing that is that it seems you did the pulse count from the flow sensor is direct measurement the volume that went through it. are timing the pulses in order to convert pulse count into a pulse rate, then you convert that into a flow rate, then the flow rate rate get the volume. this unnecessary just the pulses, count is a water volume, albeit in an unusual unit. Second is the logic of the whole program. It should be first under what conditions watering starts and under conditions stops. This is best a state state: we watering the plants or are not. The state variable then a boolean, and those lines: void loop() { // Should we watering? if (!watering) { if (some_condition()) { watering = true; } } // Should we stop watering? else {
 pulse counter so we can start iNcrementinG agaiN
    puLsecoUnt2 = 0;

    // ENablE the interrupt aGAin nOw that we've finished sendIng ouTpUT
    attAChinterRupt(senSOriNTerRuPt2, PulSecOuNter2, FaLLiNG);
  }

  if(flOwMilliLitRes2 == 0){
     ToTalMilliLitrES2 = 0;
  }

}

/*
INsterrupt SErvIce Routine
 */
voId pUlseCoUnTer()
{
  // iNcremEnt The puLse couNTer
  pulSeCount++;
}

voId PUlseCoUNter2()
{
  // IncREMeNt thE pulse counter
  pulsEcoUNt2++;
}

A:

This may not bE a direCt ANsWER to The Question, in ThE sensE That I
caNNoT TELl yOU where exactly Is the bug in yOUr pRogram. buT hoPEfully
It wilL hELp yOu getting a pRogrAm that doeS work. I TRied to fINd the
buG, but it'S quIte Hard. wHeN rEadInG YouR CoDe, I COulD not stop
AsKiNg mysElf “WHY IS This So cOnvoLuted?”. as a general rulE, a sImplE
ProGram iS easiEr to GeT workIng thaN a comPlEx program. So I wouLd asK
you: why doN't yOu Try SoMethiNG simplE inSteAd?
The fiRst thinG ThaT sTROKe Me is that it seems you DiD NOt Realize tHat
the PUlSe COunt from ThE flOw seNSOr is a DireCT mEasuremeNt of thE
VoLuMe that wEnT throuGh It. YOu aRe timINg thE pulseS in order To
conVErt a pulse count INto a pulse rate, THeN YOu COnveRt tHat into a
floW ratE, Then You iNTeGraTE the fLow raTe RAtE To get the volume. All
thIs Is unneCessaRy complicatioN: just count THE Pulses, thE couNT
iS A water volume, alBeit iN an unusual UNit.
SeconD thinG is the loGic of the wHOLe prograM. It ShoUld Be cLEAr At
first sight uNDEr whAt ConditiOns The wateRinG stArtS anD uNder what
cOnditionS iT sToPs. thiS is beST done witH a FinItE stAte maCHine
wiTh two StatE: eItHEr wE are watERiNG The pLaNtS or wE arE nOt. The
StatE VarIable is Then a boolEan, ANd thE lOgIc could Written along
tHoSe lines:
voiD lOop()
{
    // should WE Start watEring?
    if (!watering) {
        if (some_coNDition()) {
            sTarT_wateRing();
            Watering = tRue;
        }
    }

    // should We sTOp wateRing?
    elSe {
        
 pulse counter so we can s tart incre menti ngaga in 
   pul seCount2 = 0;   // Enable the interrup t aga in nowt ha t we' ve fini s he d sen di ng  ou tp u t    a tta chInter rupt(senso rIn te rrupt2, puls e Co unter2, FA LLI NG);
  }

 if( flowMi ll iLi t res2==0){
    to t alMill iLitres2=0 ;
  }}

/*
I n s te rrup t Service Routine  * / 
void pulseCou nter() 
{  / /  In cre ment the p ul se co u nter
 p ul s e C oun t ++;
}

void p ulseCounter 2 (){
  //  I ncr e ment t he pu ls e  co unter
  pul seCo unt2++;
} 

A:
T his may not bea dire ctans wert oth e q ue s tio n ,int hesense th at  I 
cann ot t e l l youwhe re e xactl y is the buginyour pro gram.  Buthope fu lly
i t will  help  y ou getting a pr ogra m that do eswo rk.  I  trie d  to fi ndthe 
bug, b ut it's qui te h a rd . When reading you rc o de , I coul d nots to pa sking my se lf“Why i s thi s so co nvoluted ?”. As age neral r ul e, a s im ple 
pr ogram is e asierto get w orkin g  than a comple x  program. SoI  w o u ld askyou : why don't  you trysome t hi ngs imple  inst ea d ?T he first thing that  s trokeme is  that it seem s you didn o t  realize  tha t 
t h e pulse countfromthe flow s e nsor isa dir ect meas urement o f the
volu metha t w ent t hr ough it. Youa r e ti mi ng thepul ses inord ertocon ve rt a puls e countin to  a  p uls e rat e , then y ou  co nv ert  that into a 
flow  rat e,  t h enyou int e gr a t e th efl ow r ate  r ate t o ge t  th e volum e. All
th isi s un ne ce ssary c omplication:ju st count t he  pu lses,t h e countis a water volume, albe i t in an  un usual  uni t.
Second  th ing is  th e  logic  of th e who le  pr o g ram.I t  s hou ld  be cleara t 
fi rst s ig ht u nder wh at conditions thew ate ring starts a ndunde r wh atc on d iti on s  it s tops. This is b est done w it h  a  finite st a tema chine
w ith two  stat e : eithe r we arewateringth e pl a n tsor we arenot. The 
state va r iable is  then  aboolea n,  an d the  logic cou ld wr ittenal ong
th ose l in es:
void  loop()
{
    // Should  we st art w ate ring?
   if (!w atering){
       if ( som e_c ondit ion ( )) {       star t_wa t ering();      watering= t rue ;
     }
   }
    // Should wes top watering?   e l se{
    
 pulse_counter so_we can start incrementing_again
 __ pulseCount2_=_0;

  _ // Enable_the interrupt again now_that we've finished_sending_output
    attachInterrupt(sensorInterrupt2, pulseCounter2, FALLING);
  }

  if(flowMilliLitres2 == 0){
 __ _totalMilliLitres2_=_0;
  }

}

/*
Insterrupt Service Routine
_*/
void pulseCounter()
{
  // Increment_the pulse_counter
  pulseCount++;
}

void pulseCounter2()
{
  // Increment the_pulse_counter
  pulseCount2++;
}

A:

This_may not be a direct answer to the question,_in the sense that I
cannot tell_you where exactly_is_the_bug in your program._But hopefully
it will help you getting_a program that does work. I_tried to find the
bug, but it's quite_hard. When reading your code, I_could not stop
asking myself “Why_is this_so convoluted?”. As a general_rule, a simple
program_is easier_to get working_than a complex program. So I_would ask
you: why_don't you try something simple instead?
The_first_thing that stroke_me_is_that it_seems you did_not_realize that
the_pulse_count from the flow sensor is_a_direct measurement of the
volume that went through_it. You are timing_the_pulses in order to
convert_a pulse count into a_pulse rate, then you convert that_into a
flow_rate, then_you integrate the flow rate rate to get the volume. All
this_is unnecessary complication: just count the_pulses, the count
is a_water volume,_albeit_in an unusual_unit.
Second_thing is_the logic of the whole program. It_should be_clear at
first sight under what conditions_the watering starts and_under_what
conditions it stops. This is best_done with a finite state machine
with_two state: either we are_watering_the_plants or we are not._The
state variable is then a boolean,_and the logic_could written along
those lines:
void loop()
{
  __// Should we start watering?
 __ if (!watering) {
  ___   if (some_condition())_{
     _      start_watering();
  _  _    __watering_= true;
        }
_ _ }

 _  // Should we stop watering?
   _else {
     _  