How to read flow using flow meter without interrupts

Hey Guys, another question here

I'm trying to set up a flow meter on my Arduino and it's currently connected to D32. This pin is unable to be used for interrupts, but every solution to my problem on the internet that I've found has involved interrupts. Does anyone have any experience with flow meters and is able to help me to set it up without using interrupts?

Thanks for the help!

If you want to use interrupts on pins that are not the external interrupts ( pins 2,3,18,19,20,21) you need to use pin change interrupts.

Yeah that's what I've been trying to do, but no success so far. I'm using the PinChangeInterrupt library and am running attachPinChangeInterrupt(flowPin, test , RISING);
, where flowPin is 32 (where the flow meter is connected) and test is a function that just prints to the serial monitor. But no success

It is unwise to try to print from an ISR as interrupts are disabled in the ISR and print needs interrupts. In the ISR increment a volatile variable and set a flag. Then in loop, check the state of the flag. If the flag is set, print the count and clear the flag.

If you want more help, post your code. Read the forum guidelines to see how to properly post code.
Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in code tags.

Arduino Mega: 10, 11, 12, 13, 50, 51, 52, 53, A8 (62), A9 (63), A10 (64), A11 (65), A12 (66), A13 (67), A14 (68), A15 (69)

Not all pins on the Mega support pin change interrupts. D32 is one of the pins which can't have a pin change interrupt.

See the documentation here

1 Like

Thanks, I knew that there was something about the Mega having limited PCI pins but could not find the list.

OK Thanks for help!

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.