74. Sleep Mode with Button Press Wake-Up

Objective

We have to build a low-power system that minimizes energy consumption by using the microcontroller’s power-saving features. The system must remain in power-saving mode until triggered by a user input (push button), at which point it wakes up, performs an ADC measurement, transmits the result, and returns to low-power mode.

Functional Requirements

  1. Low-Power Operation
    • The microcontroller operates in a designated power-saving mode to reduce power draw when idle.
    • Core clock and peripheral clocks are suspended as per the selected power saving mode configuration.
  2. Wake-Up Trigger
    • Push button connected to a dedicated external interrupt pin (e.g., EXTI on STM32, INTx on AVR, GPIO interrupt on ESP32).
    • A falling-edge or rising-edge interrupt detection is used to minimize false triggers due to switch bounce (debounce handled in software).
  3. ADC Measurement
    • Upon wake-up, the system reads the ADC value from a potentiometer connected to an analog input pin.
    • ADC resolution is configured according to the MCU’s capability (e.g., 10-bit for AVR, 12-bit for STM32).
    • Sampling time is optimized for both accuracy and speed.
  4. Data Transmission
    • The ADC reading is transmitted via a serial interface (e.g., UART to PuTTY, Arduino Serial Monitor).
    • Baud rate and framing parameters are preconfigured to ensure compatibility with the terminal software.
  5. Return to Sleep
    • After ADC reading and data transmission, the system automatically re-enters low-power mode without additional user intervention.

High-Level Workflow

  1. System Initialization
    • Configure GPIOs for push button (input with interrupt) and potentiometer (analog input).
    • Initialize ADC and UART peripherals.
    • Enable global interrupts.
  2. Enter Low-Power Mode
    • MCU enters sleep/stop mode awaiting interrupt from push button.
  3. Wake-Up Event
    • Button press generates an external interrupt signal.
    • MCU resumes operation from the interrupt handler.
  4. Read and Transmit ADC Value
    • Perform ADC conversion on the potentiometer input.
    • Format and send the ADC value to the serial terminal.
  5. Re-Enter Low-Power Mode
    • Resume power saving mode immediately after transmission.

Key Implementation Notes

  • Debounce Handling:
     Software-based delay or state-check mechanism to avoid multiple false wake-ups from mechanical switch bounce.
  • Interrupt Configuration:
     External interrupt set to edge-sensitive mode for optimal wake-up latency.
  • Power Mode Selection:
    • STM32: STOP or STANDBY mode with EXTI wake-up.
    • AVR: POWER-DOWN mode with INT0/INT1 wake-up.
    • ESP32: Deep Sleep mode with GPIO wake-up.
  • Peripheral Wake-Up:
     Ensure ADC and UART clocks are re-enabled after wake-up before measurement and transmission.
     

So, by considering the above points, we can implement the task.

Below are the solutions to the given task using different microcontrollers

  1. STM32
  2. ESP32
  3. Arduino UNO

Submit Your Solution

Note: Once submitted, your solution goes public, helping others learn from your approach!