Smart ways to detect a button (less power consuming)
A low-current method I used once was to connected a switch between two microcontroller I/O pins.

One I/O was configured as an output (SWO). The second was configured as an input (SWI) with its programmable internal pull-up enabled.

The switch state was sampled infrequently (every 10 ms) by a software interrupt routine. The reading sequence was: drive SWO low, read SWI, drive SWO high.

This meant that a pressed switch only drew the SWI pull-down current through itself and SWO for less than 1 us during scanning, while an unpressed switch drew no current. This current draw for &lt;1 us every 10 ms resulted in a tiny average average current consumption.