งานที่17
Water flow Sensor กับ Arduino วัดน้ำไหลในท่อ
Arduino Uno R3
volatile int flow_frequency; | |
unsigned int l_hour, f_val; | |
unsigned long ctTime, flow_val, cloopTime; | |
void flow () // Water flow Interrupt function | |
{ | |
flow_frequency++; f_val++; | |
} | |
void setup() { | |
Serial.begin(9600); | |
attachInterrupt(1, flow, RISING); sei(); ctTime = millis(); cloopTime = ctTime; // Water flow | |
} | |
void loop () { | |
ctTime = millis(); | |
if (ctTime >= (cloopTime + 1000)) { | |
cloopTime = ctTime; | |
l_hour = (flow_frequency * 60 / 7.5); | |
flow_frequency = 0; | |
Serial.print("Water Sensor : "); | |
Serial.print(l_hour, DEC); | |
Serial.print(" L/hour"); | |
} | |
if (f_val >= 450) { | |
flow_val++; | |
f_val = 0; | |
} | |
Serial.print("\t "); | |
Serial.print(flow_val); | |
Serial.println("L"); | |
} |
ความคิดเห็น
แสดงความคิดเห็น