add YF-S201 Water Flow sensor
This commit is contained in:
parent
c90e106ba6
commit
f1b4a26338
36
src/main.cpp
36
src/main.cpp
|
@ -55,10 +55,23 @@ float waterlevelMean[WATERLEVELMEAN_SIZE];
|
||||||
uint16_t waterlevelMean_pos=0;
|
uint16_t waterlevelMean_pos=0;
|
||||||
|
|
||||||
|
|
||||||
|
// ######## Flow Rate
|
||||||
|
#define FLOW_PIN 19
|
||||||
|
uint16_t flow_counter=0; //maximum counts/s measured with Eden 128 Pump was 171
|
||||||
|
void IRAM_ATTR isr_flow();
|
||||||
|
unsigned long last_read_flow=0;
|
||||||
|
#define READINTERVAL_FLOW 1000
|
||||||
|
float flow_factor=7.5; //F=7.5*flowrate[L/min]
|
||||||
|
float flow;
|
||||||
|
|
||||||
|
uint32_t flow_counter_sum=0;
|
||||||
|
|
||||||
|
|
||||||
unsigned long last_print=0;
|
unsigned long last_print=0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
float getMean(uint16_t *parray,uint16_t psize);
|
float getMean(uint16_t *parray,uint16_t psize);
|
||||||
float getMeanf(float *parray,uint16_t psize);
|
float getMeanf(float *parray,uint16_t psize);
|
||||||
uint16_t getMin(uint16_t *parray, uint16_t psize);
|
uint16_t getMin(uint16_t *parray, uint16_t psize);
|
||||||
|
@ -127,6 +140,9 @@ void setup() {
|
||||||
sensors.setResolution(thermometerAir, TEMPERATURE_PRECISION);
|
sensors.setResolution(thermometerAir, TEMPERATURE_PRECISION);
|
||||||
|
|
||||||
|
|
||||||
|
pinMode(FLOW_PIN, INPUT_PULLUP);
|
||||||
|
attachInterrupt(FLOW_PIN, isr_flow, CHANGE);
|
||||||
|
|
||||||
Serial.println("Setup finished");
|
Serial.println("Setup finished");
|
||||||
delay(500);
|
delay(500);
|
||||||
}
|
}
|
||||||
|
@ -205,6 +221,17 @@ void loop() {
|
||||||
waterlevelMean_pos%=WATERLEVELMEAN_SIZE;
|
waterlevelMean_pos%=WATERLEVELMEAN_SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static uint16_t _last_flowconter; //for debugging
|
||||||
|
if (loopmillis>=last_read_flow+READINTERVAL_FLOW) {
|
||||||
|
flow=flow_counter*1000.0/(loopmillis-last_read_flow)/2.0; //Frequency [Hz]
|
||||||
|
flow/=flow_factor; //[L/min]
|
||||||
|
_last_flowconter=flow_counter; //for debugging
|
||||||
|
|
||||||
|
flow_counter=0;
|
||||||
|
last_read_flow=loopmillis;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (loopmillis>last_print+500) {
|
if (loopmillis>last_print+500) {
|
||||||
last_print=loopmillis;
|
last_print=loopmillis;
|
||||||
|
@ -225,6 +252,9 @@ void loop() {
|
||||||
}else{
|
}else{
|
||||||
Serial.print("\t waiting for distance");
|
Serial.print("\t waiting for distance");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Serial.print("\t Flow="); Serial.print(flow,2); Serial.print(" ("); Serial.print(_last_flowconter); Serial.print(")");
|
||||||
|
Serial.print("\t Flowsum="); Serial.print(flow_counter_sum);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -305,3 +335,9 @@ void printAddress(DeviceAddress deviceAddress)
|
||||||
Serial.print(deviceAddress[i], HEX);
|
Serial.print(deviceAddress[i], HEX);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void IRAM_ATTR isr_flow() {
|
||||||
|
flow_counter++;
|
||||||
|
flow_counter_sum++;
|
||||||
|
}
|
Loading…
Reference in New Issue