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++;
}