Using analogRead() with multiple buttons, different resistors & interrupts?

I'm trying to use an existing button panel. The buttons are connected to 3.3V in series with different resistors. Now, when I connect this to an analog input I can use analogRead() and see different values for the different buttons. Like expected.

The problem is that I also need interrupts. But when using interrupts on a pin, and then using analogRead() after an interrupt happend, everything stops working.

I assume this is because analogRead() messes with the pins.

Is there a way to fix this?

Why ?

2 Likes

Hi @AKnuts,

I assume this is because analogRead() messes with the pins.

analogRead() usually does not mess with pins, it is more likely that a specific code messes with interrupts :wink:

Is there a way to fix this?

The general answer would be: Yes.

If you would post your code and a drawing of your application the members of this forum might have a chance to find out how ... :slight_smile:

1 Like

I cannot tell you why "everything" stops working. But have you considered, if the resistor of the buttons are in a way that you will get a logic "high" with every button? Otherwise the interrupt won't work (or: you would need an extra circuit to trigger the interrupt)

Also consider connecting the button output to 2 arduino inputs in parallel - analog and digital in. Then you won't have to switch the pin mode in operation.

It's a battery operated device so I need it to be in lowpower sleep mode and use interrupts to wake it.

2 pins sounds like a good option :wink:

Amen :+1:

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