B-SoM Stop Sleep with VL53L1 Interrupt for Power Savings

I'm working on a power-saving feature for my B-SoM project using a VL53L1 ToF distance sensor. My goal is to reduce power consumption by entering Stop Sleep mode every 5 seconds. The process involves taking a measurement, entering Stop Sleep for 5 seconds, clearing any pending interrupts, and checking the interrupt state before going back to sleep. Here's the current approach:

distanceSensor.begin();
distanceSensor.init();
distanceSensor.setInterruptPolarityLow();
distanceSensor.setDistanceModeLong();
distanceSensor.startRanging();
distanceSensor.setDistanceThreshold(50, 1000, 3);

const long SLEEP_TIMEOUT = 5000; // 5 seconds
long lastWakeTime = 0;
bool sleepFlag = true;

void loop() {
    // Poll sensor every 5s and handle sleep
    if (sleepFlag) {
        if (distanceSensor.checkForDataReady()) {
            distanceSensor.clearInterrupt(); // Clear before entering sleep
        }

        // Prepare for sleep
        Log.info("Going to sleep...");
        SystemSleepConfiguration config;
        config.mode(SystemSleepMode::STOP)
              .network(NETWORK_INTERFACE_CELLULAR)
              .duration(5000ms);
        SystemSleepResult result = System.sleep(config);
        sleepFlag = true; // Set flag after waking up
    }

    // Handle interrupt events - this will wake the device
    if (TOF_INTERRUPT_FLAG) {
        setTemporaryLEDColor("g");
        TOF_INTERRUPT_FLAG = false;
        sleepFlag = false;

        int distance = distanceSensor.getDistance();
        byte rangeStatus = distanceSensor.getRangeStatus();
        Log.info("Interrupt Distance: %d mm, Status: %d", distance, rangeStatus);

        distanceSensor.startRanging(); // Restart ranging
        distanceSensor.setDistanceThreshold(50, 1000, 3);
        lastWakeTime = millis(); // Reset wake time after handling interrupt
        delay(100); // Small delay for stability
    }
}

Does this approach for Stop Sleep every 5 seconds with the B-SoM seem effective for power savings while maintaining sensor functionality? Would going back into Stop mode this frequently cause any issues? Any insights on improving this pattern, particularly with interrupts and power efficiency, would be appreciated!

That short of a sleep duration will have minimal effect on power consumption, especially since you have to have cellular on (NETWORK_INTERFACE_CELLULAR) when using short sleep durations.

The nRF52 MCU does use less power in STOP sleep mode (around 5 mA running vs. 500 uA sleep), however the cellular modem uses 50mA, dwarfing the amount saved by the MCU.

1 Like


The docs say the Boron (B-SoM) only uses 12.1 ma in stop mode with network-wake.

I ideally would like the benefits of receiving cloud-side messages while the sensor is searching, and the lower power usage of the network-wake mode.

Let me know your thoughts, thanks as always.