Hi community,
as a newbie and more or less non-coder
I am trying to set up a Photon @ home (for future an Electron in field) as water flow observing device for a breeding fish-tank for fertiled salmonid-eggs.
I am using a common flow-sensor (turbine, hall-effect) and getting pulses out of it. Checked with a LED, works well so far.
The problem(s): Console writes “0” Data : /
My simple code is, …
volatile int flow_frequency; // Measures flow meter pulses
unsigned int l_hour; // Calculated litres/hour
unsigned char flowmeter = D2; // Flow Meter Pin number
unsigned long currentTime;
unsigned long cloopTime;
char l_hour_chars[8];
String l_hour_str;
void flow () { // Interrupt function
flow_frequency++;
}
void setup() {
pinMode(flowmeter, INPUT);
Serial.begin(9600);
attachInterrupt(D0, flow, RISING); // Setup Interrupt
// see [...]; // Enable interrupts
currentTime = millis();
cloopTime = currentTime;
}
void loop () {
currentTime = millis();
// Every second, calculate and print litres/hour
if(currentTime >= (cloopTime + 1000)) {
cloopTime = currentTime; // Updates cloopTime
//Pulse frequency (Hz) = 7.5Q, Q is flow rate in L/min. (Results in +/- 3% range)
l_hour = (flow_frequency * 60 / 7.5); // (Pulse frequency x 60 min) / 7.5Q = flow rate in L/hour
flow_frequency = 0; // Reset Counter
Serial.print(l_hour, DEC); // Print litres/hour
Serial.println(" L/hour");
l_hour_str = String(l_hour);
l_hour_str.toCharArray(l_hour_chars, 8);
Particle.publish("L/hour", l_hour_chars, PRIVATE);
delay(5000);
}
}
Has anyone an idea, why Photon resp. the code sends Data as a zero?
Pinconnections and wiring check trice.
Thank you in advance.
btw, if anybody has a code of different style/idea, I would appreciate to try it , )