Hi. I'm new on Arduino coding and want to use the board for monitoring the flow rate with Mega board. I use following code to read the flow sensor and convert in to meaningful result. But the problem is this code works only for 1 sensor. I was wondering is there any way to use interrupt for reading 4 sensor at the same time? I mean I have four path on my setup and need to monitor the flow rate all of them and the same time. How can I use interrupt for calculate 4 flow rates simultaneously?
volatile int flow_frequency; // Measures flow sensor pulses
unsigned int l_hour; // Calculated litres/hour
unsigned char flowsensor = 2; // Sensor Input
unsigned long currentTime;
unsigned long cloopTime;
void flow () // Interrupt function
{
flow_frequency++;
}
void setup()
{
Before any further, please tell us how many hindred times per second the flow sensor creates an interrupt? This is the only reason for using an interrupt.
I am guessing you can watch for a low to high change on any pin connected to your flow sensors by reading the pin in the loop() code.
How long is each interrupting puls?
I think about using 4 diodes that triggers the interrupt whenever there is a pulse. Inside the ISR, check which sensor was pulsing and update the data for that sensor.
Using interrupts for a flow sensor that might be giving less than 10 pulses per second is like using an expensive stopwatch for a turtle-race. Polling (pin change) would be much easier.
Leo..
My neighbor had a pet turtle, she went away to college and her parents took over care for the pet. I would see them out in the backyard walking the turtle (really). One day there were out in the yard sitting on lawn chairs with the turtle nearby. The lost track of time a little and the turtle was off !! They never found the turtle. So maybe when we are not looking turtles are faster than we think.
You should find that Mega has six. Unfortunately I recall, the extras share with serial and I2C, but this may not be a problem for OP. I'm sure multiple flow meters has has been addressed before.