In the recent video about low power modes with ESP32, I understand how to conserve power on the processor using the various sleep modes. But what if you have peripherals? For example, if I have a BME280 taking temperature, humidity, and barometric pressure readings, how do I turn off the sensor so it won't take power while the processor is sleeping?
You can power some external devices using esp32 pins as the source if the current draw of those devices are within the current spec of the esp32. The BME280 can be powered by a pin for example or the chip can go into deep sleep itself. You can also use a regulator with an enable pin, and use the regulator to power all your external devices if they can take the save source voltage. Regulators do draw current even when disabled.
Hi @markvanhorne,
To supplement @noweare's helpful answer, if the current requirement oa chosen peripheral exceeds the ESP32's GPIO output current capability, then you could try using an ESP32 GPIO to drive the gate of a MOSFET to switch the power to the external device.
NB I haven't tried this with an ESP32, so whilst it should be fine, an unexpected gotcha could appear.
---
In the particular case of the BM280, a 5 second glance at the data sheet suggested its current consumption is modest, especially in 'sleep mode', so it might not even be necessary to switch the incoming power, depending upon your requirements:
from https://www.bosch-sensortec.com/media/boschsensortec/downloads/datasheets/bst-bme280-ds002.pdf
BME280
Digital humidity, pressure and temperature sensor
Key features ....Current consumption 1.8 μA @ 1 Hz humidity and temperature
2.8 μA @ 1 Hz pressure and temperature
3.6 μA @ 1 Hz humidity, pressure and temperature
0.1 μA in sleep mode
Once again, I'll leave it to you to check out thoroughly. I don't know if the BM280 has been cloned, but be aware that many clones of parts may work reasonably well, but may not meet all of the specs, such as power consumption. This may be a case to ensure you have a 'genuine' product.
Good luck with your project.
I have done this on my remote projects and it does work well. Just need to use timers to ensure your sensors are back up to snuff and measuring correctly. I just use counters/timers to set flags to do this in my code. Measurable battery savings. I use a 2n2222 transistors to turn power on to the sensors once the MCU is woken from light sleep and turns it back off just before going back to sleep. I control small 30mm pi fans the same way in the remotes.
Discussion with Gemini regarding powering down BME280; in sleep mode, including example code.
Williiam
Hi, don't know if it helps, but I just stumbled across this video:
I've only ever powered one via a GPIO pin and assumed (maybe incorrectly) that when the ESP32 goes to sleep, it would just shut off the power to the sensor. I suppose you could explicitly turn the GPIO pin off as part of your sleep routine.
For the BME280, you usually do not need to cut power completely. Configure it for forced mode. Let it take one measurement, read the data, then let it return to sleep mode automatically. This reduces current to a tiny fraction of normal operation. If a peripheral lacks a low-power mode, use its enable pin or switch its power with a MOSFET or load switch.