Water flow sensor and LED condition . Help please

hello everyone ! I would like to ask you guys if someone could help me compiling this code to be able to use a LED when the flow meter's signal is null .. in other words, when there is no water passing through .
Also What boot should i use? I have arduino one r3 and i need to make it run without PC .
More detailed explanation:
A led should turn ON when the signal is null or 0
THe same led should turn OFF when the signal is >0
Should it be a signal dipendency or calculation based result - no importance here . But I think it would be more realible using the final result ( ex 0lt/h or 5lt/h)
So guys, could you please modify this code for me ?
If it was possible creating a blinking stage between 0 and >0 it would be even better !Like two blinks on LOW and three blinks before going HIGH

byte statusLed    = 13;
byte sensorInterrupt = 0;  // 0 = digital pin 2
byte sensorPin       = 2;
float calibrationFactor = 4.5;
volatile byte pulseCount;  
float flowRate;
unsigned int flowMilliLitres;
unsigned long totalMilliLitres;
unsigned long oldTime;
void setup()
{
  Serial.begin(9600);
  pinMode(statusLed, OUTPUT);
  digitalWrite(statusLed, HIGH); 
  
  pinMode(sensorPin, INPUT);
  digitalWrite(sensorPin, HIGH);

  pulseCount        = 0;
  flowRate          = 0.0;
  flowMilliLitres   = 0;
  totalMilliLitres  = 0;
  oldTime           = 0;
  attachInterrupt(sensorInterrupt, pulseCounter, FALLING);
}
void loop()
{
   if((millis() - oldTime) > 1000)   
  { 
    detachInterrupt(sensorInterrupt);
    flowRate = ((1000.0 / (millis() - oldTime)) 
    oldTime = millis();
    flowMilliLitres = (flowRate / 60) * 1000;
    totalMilliLitres += flowMilliLitres;
    unsigned int frac;
    Serial.print("Flow rate: ");
    Serial.print(int(flowRate));  
    Serial.print("L/min");
    Serial.print("\t");     
    Serial.print("Output Liquid Quantity: ");        
    Serial.print(totalMilliLitres);
    Serial.println("mL"); 
    Serial.print("\t");       
  Serial.print(totalMilliLitres/1000);
  Serial.print("L");
    pulseCount = 0;
 attachInterrupt(sensorInterrupt, pulseCounter, FALLING);
  }
}
void pulseCounter()
{
 pulseCount++;
}

:o

A pulse-based sensor can't measure zero. One pulse per 5 minutes is still some flow but you don't know that it's flowing until 5 minutes has passed.

Just determine what the minimum flow is that you want to measure. One pulse per second, for example. If one second has passed without a pulse, then you can say that the flow is less than your minimum and the light must go on.

Hi,
Add to your code.

if (flowrate = 0.0)
   { digitalWrite(statusLED,HIGH);
    }
 else 
   { digitalWrite(statusLED,LOW);
    }

Use flowrate variable to control the LED.

Note that the flowrate will need to be exactly zero, as MorganS has said, it may very rarely be 0.

You may have to use < 0.5 or somethng like that in the if statement instead of = 0.0.
In other words use a minimum flow rate as your trigger.

Tom... :slight_smile:

if (flowrate == 0.0)

CrossRoads:
if (flowrate == 0.0)

Thanks.. just need a caffeine kick.. :o :o :o

CrossRoads:
if (flowrate == 0.0)

As if that would work... well, maybe it would, as it's zero.
Still, equality tests and floats are not the best combination - or so I've been told over and over again :slight_smile: