![]() ![]() Meanwhile in the main loop, we access the flow rate of each Flow Meter every 2 seconds, printing them to the Serial Monitor. While we “interrupt” and check sensor statuses every millisecond, the flow rate variables are constantly and rapidly updating in the background. But the flow rate variable remains until the next activation. Since this cycle is complete, we can now calculate the flow rate (i.e., frequency of the pinwheel) at this point, which equals the reciprocal of the cycle time length, multiplied by 1,000 (1 second equals 1,000 milliseconds). The next time, the sensor gets “LOW” again.If not – if the sensor returns “HIGH” – then it means that this cycle is at its end.This means that the deactivated period of this cycle adds one millisecond (since we check every millisecond). Every millisecond, we check if the meter returns the same deactivated state (“LOW”) as the last time we checked.We also have a variable to record what the sensor’s state the last time we checked and a variable to record the accumulate number of pulses. We have a timer and a counter for each sensor.The code basically does this (and the process repeats itself for both meters): then lastFlowRateTimer1 and lastFlowRateTimer2 are reset. and flow rate is the reciprocal of the accumulated time then the accumulation of lastFlowRateTimer1 and lastFlowRateTimer2 stops (because the gap has ended), If this pin state differs from the last one, namely activated as HIGH, ![]() If a cycle is longer than 3 seconds, it means that the water has stopped. lastFlowRateTimer1 and lastFlowRateTimer2, which are used to record the gap between two pulses, accumulate on themselves. If this pin state is the same as the last one, it means that a cycle has not finished. Uint8_t x2 = digitalRead(flowSensorPin2) ![]() Uint8_t x1 = digitalRead(flowSensorPin1) The program tests whether the flow pins return the same state as the previous one. Note that each group contains two variables, one for each Flow Meter. It might look confusing at first, but it will clear up once you read through the rest of the tutorial. The Code Setting variablesįirst, we set up the necessary variables. The 5V pin powers the sensor, and the digital pin collects signals from the sensor and feeds them to the Arduino. The red wire connects to 5V, the yellow wire connects to a digital pin (e.g., pin 2), and the black wire connects to GND. The Liquid Flow Meter has three wires to be connected. Circuit Circuit diagram made with Frizing When the difference shrinks down to lower than 500 Hz, the LED goes off. In this case, I set the threshold at 500 Hz – namely, if the flow rate (or spinning frequency) of the Flow Meter 1 is 500 Hz more than Flow Meter 2 or more, an LED lights up. Here, we are comparing the flow rates from two meters. Then, we can calculate the water volume by a linear conversion from the number of completed cycles. Each time the pinwheel completes another cycle, the sensor generates a “HIGH” signal and feeds it back to the Arduino. Flow rate is represented by the frequency of the pinwheel’s spinning. The Liquid Flow Meter measures flow rate using a pinwheel.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |