Hello All.
I have a Particle Photon and my main idea is to be able to read my water consumption.
There have been some good threads here that i have read so i got it working but i need an additional variable
that stores the consumption.
var consumption = how much water have passed thru the last hour;
The idea is that every hour i want this variable to be sent out to the cloud so i can see how much water have been used the last hour or day etc.
Why want this is because i have a filter that cleans water but there is no way to tell when the filter is going bad.
I know for a fact that the filter can take 300k liter of water before its bad.
So i want to know approximately how much water i use a day and also when i am close to the tresshold of 300k i want an email,sms,warning.
So i started out with connecting a water flow meter (https://www.adafruit.com/products/828)
and by other threads here i use this code.
/*
Water flow sensor test sketch
*/
unsigned long oldTime;
volatile unsigned int WaterPulseCount = 0;
// conversion from pps to litres, plastic sensor (485 for metal)
const float pulsesPerLiter = 450;
// Spark Digial Pin D3 (D2 did not work)
#define WATER_SENSOR_PIN D3 // Water sensor digital pin
// Define Spark variable - not sure "float" type works so define as INT
// so decimal is shifted left with * 100 (so xx.yy becomes xxyy)
float liters = 0;
char liters_S[20];
//-----------------------------------------------------------------------------
// Water Sensor interrupts
//-----------------------------------------------------------------------------
void WaterPulseCounter(void)
{
// Increment the water pulse counter
//detachInterrupt (WATER_SENSOR_PIN) ;
WaterPulseCount++;
//attachInterrupt(WATER_SENSOR_PIN, WaterPulseCounter, FALLING) ;
}
void setup()
{
Serial.begin(9600);
Particle.variable("litersS", liters_S, STRING);
// Set Digital pin WATER_SENSOR_PINT to INPUT mode and set
// interrupt vector (water flow sensor) for FALLING edge interrupt
pinMode(WATER_SENSOR_PIN, INPUT);
attachInterrupt(WATER_SENSOR_PIN, WaterPulseCounter, FALLING) ;
oldTime = millis();
}
void loop()
{
unsigned long t;
static unsigned int pc;
t = (millis() - oldTime);
if(t >= 1000) // Only process counters once per second
{
//Read water sensor pulse count and process
if (WaterPulseCount != 0) // Do nothing if water is not flowing!
{
detachInterrupt (WATER_SENSOR_PIN); // Disable water flow interrupt to read value
//Calculate litres and adjust for 1 sec offset, if any
liters = (WaterPulseCount / pulsesPerLiter) * (t / 1000);
oldTime = millis(); // Reset base delay time
pc = WaterPulseCount;
WaterPulseCount = 0; // Reset the water pulse counter
attachInterrupt(WATER_SENSOR_PIN, WaterPulseCounter, FALLING);
sprintf(liters_S, "%4.3f", liters);
Serial.print("WaterPulseCount= ");
Serial.print(pc);
Serial.print(", liters= ");
Serial.print(liters,3);
Serial.print(", liters_S= ");
Serial.println(liters_S);
}
}
}
There are some part here that i dont understand but we can take that later on on a different thread.
I thought this function would do so sprintf(liters_S, "%4.3f", liters);
but it just print the value of the liters again.
So how do i do to not reset the value all the time so i can see how much water has been used for a whole day.
As it is now it prints the value every second but it goes back to “0” all the time.
Sorry for my beginner questions.
Many thanx
Emilkl