Do you mean a switch that floats on water, closing if the water level falls below a certain level?
But then the A1 pin will be floating (in the electrical meaning) if the switch changes to OFF your circuit cannot tell if the switch remains ON or is now OFF. This will not work.
I suggest you keep the pin in INPUT mode, then once per second or once per minute, set it to INPUT_PULLDOWN, read the pin, then set mode back to INPUT. Do not read the pin when it is in INPUT mode.
Yes, water level switch. I already mentioned in my post that I set it to PULLDOWN when the pin is not connected to avoid floating and set to INPUT only when connected to minimize power usage. And I also mention that it worked normally when running on USB
I already update my original post with rough drawing.
Yes, the MCU can wakeup every 1 minute to check the status of the pin, but I try to save power as much as possible thus I choose to wakeup by interrupt instead.
Ok, I will give you the benefit of the doubt and assume my previous explanation was unclear and try to explain again.
Imagine the water level is low, and the switch is ON, and the pin is not floating and will read HIGH. Your code reads the switch and then changes mode to INPUT to save power.
Later, the water level increases and the switch changes to OFF. Now the MCU pin is floating and could read HIGH or LOW. There is a good probability that it will remain HIGH and no interrupt will occur to wake the MCU, so the pin mode will not change to INPUT_PULLDOWN.
When the water level increases and the switch changes to OFF, Interrupt will be fired because its state before the switch is off is 3V. Upon receiving this interrupt, the code will change to INPUT_PULLDOWN.
The interrupt will only fire if the state of the pin changes from 3V to 0V. That might happen. Or it might not. There is no certainty. The pin is floating.
If the pin was in INPUT_PULLDOWN mode, it would immediately change from 3V to 0V and the interrupt would fire. But it is in INPUT mode.
That, in the way you described it, would prevent the MCU from running. This is why schematic is important. English, or any other human language, is not suitable for describing how components in a circuit are wired.
I can't afford PULL_DOWN, it consumes 0.1ma, which is too much for 2 AAA batteries. I will need to go back to wake up the MCU every 1 minute instead of interrupt
I use Py32F002A thus my 0.1ma is based on this MCU.
Still for the purpose of this post is why the whole thing work when I use 3.3v from laptop USB and the MCU also work with battery except the interrupt.
Your laptop connection is changing the values seen by your floating pin. Add a long length of wire to the Arduino to simulate the connection to the laptop. Is the laptop running on battery or AC?