Switching nrf24l01 radio on/off manually
I am currently using an NRF24L01 radio to build my sensor with an HC-SR04 module. Because the HC-SR04 requires 5v, I am powering the sensor via 3 AAA batteries. I am using a 3.3v linear voltage regulator to supply power to the radio.
While the sensor is sleeping, I measured a 3mA draw, which is far too much. I've pinpointed my voltage regulator (AMS1117) as the source. I'd like to manually control power to the radio/regulator, but I am unable to since the mysensors library tries to initialize the radio before any other code runs (even setup). This means I never get the chance to supply power to the radio on startup so the radio initialization fails and blocks the rest of my code.
How can I control power to the radio/regulator? Can I turn it on before the MySensors library starts up? Is there a better way to save power?
@sterlingw I am not 100% sure but I think you can put the initialization code in
instead of setup()
This cannot be fixed by software as this is what the AMS1117 consumes when under no load.
You should change the regulator you use and select one with a low quiescent current, for example XC6206 which will use only a few µA.
Just for future reference, I was able to achieve this by calling
_beginafter waking up from sleep. After cutting power to the radio, it needs to be setup again. So my code looks something like this at the end of my loop:
powerDownRadio(); sleep(SLEEP_TIME); _begin();
Obviously a draw back is the added overhead of setting up the radio again, but if you're lacking the hardware, then this might be good enough. In the long term, though, I've decided to use 2 1.5v batteries, a DC-DC booster, and level shifter to avoid odd code like this.
Also, thanks @Nca78 for the regulator recommendations. I've picked up a few low quiescent current regulators to add to my collection.