jmdjac:
Can you specify more on this two? I'm really a rookie in Arduino and can't quickly decipher what is said
Your MQTT messages could look like this
topic: "sensor001/water"
value: 80
topic: "sensor002/water"
value: 50
Right now you you cannot tell the difference between the sensors.
attachInterrupt(34, flow, RISING); // this says if voltage at pin 34 rises run the function named flow
// This function increases all three variables by one every time any of the three sensor signal goes HIGH
// If water flows through sensor2 only you still measure water flow in 1 & 3
void flow () { // Interrupt function
flow_frequency1++;
flow_frequency2++;
flow_frequency3++;
}
// It should look like this
attachInterrupt(34, flow1, RISING);
void flow1 () { // Interrupt function
flow_frequency1++;
}
I also just realized, the following statement is executed only half the time.
if (digitalRead(flowsensor1) == HIGH) {}
This pin toggles between HIGH and LOW and you only read it when it is HIGH. If the pin is low every 5 seconds you will not get any result.
Also these lines should not be necessary and might even be bad.
digitalWrite(flowsensor1, HIGH); // Optional Internal Pull-Up
digitalWrite(flowsensor2, HIGH); // Optional Internal Pull-Up
digitalWrite(flowsensor3, HIGH); // Optional Internal Pull-Up
If the sensor drives the input LOW it will need to drive the voltage to ground against the internal pull-up.
Additionally, I recommend you do not send the water flow per hour but send the water value and never reset the value to zero. The reason is if you loose a MQTT message you will loose accuracy, but if you send the total value you will be able to recover. e.g.
1 + 1 + 1 + 1 = 4 if you loose any message the result is wrong
1,2, missing value, 4 the total value will be correct
Because you are using a wireless connection you will loose messages at some point.