Interrupt is not fired when use with battery

Hi,
I have a strange behavior with interrupt on my MCU.
Its interrupt is working fine when I connect with laptop USB.

But when I run on battery, the interrupt is not firing unless I set pulldown resistor, which waste a lot of energy.

Here's my setup.

A1->(floating switch)->VCC: Interrupt is fired when the floating switch is either on/off

To save power consumption, I set the interrupt pin as INPUT when the switch is ON and as INPUT_PULLDOWN if the switch is OFF to avoid floating.

Here's what I already done:
1-voltage is enough
2-capacitor is added.

-but current might be too low
-and enough might bee too much

Post your schematic and links to specs of major components.

the MCU consumes 0.5ma when it's active and capacitor is added

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 don't think you are avoiding floating.

Luck?

Please see post #3. We can only guess what is wrong without that.

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.

Please do not do that. It makes responses to your post make no sense to others reading the topic.

Updating to correct spelling errors or broken links is ok, but when adding new information, always make a new post.

Where is the capacitor you mentioned in post #1?

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.

2 capacitors(100nf and 10uf) between the battery and the MCU.

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.

1 Like

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.

1 Like

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?

1 Like

@PaulRB, thanks for your explanation of the PULLDOWN, I misunderstood its working.

@Paul_KD7HB thanks for your idea on this issue. I agree with you on this.