Hi
I'm developing a smart lock via bluetooth, but I'm having a hard time lowering power consumption.
So far I managed to reduce the consumption to 3ma by cutting the 3.3v jumper, feeding the arduino through the 3v3 port and running this code:
#include <mbed.h>
#include <rtos.h>
#include <ArduinoBLE.h>
#include <nrf_power.h>
int count = 0;
int isConnected = 0;
BLEService ledService("9eea8d70-6891-48c1-a4b4-c4b7177f6c37");
BLEStringCharacteristic switchCharacteristic("6e2d2a65-9484-4608-823e-0ab076adefe6", BLENotify | BLEWrite, 100);
void setup() {
nrf_uarte_task_trigger(NRF_UARTE0, NRF_UARTE_TASK_STOPRX);
while (!nrf_uarte_event_check(NRF_UARTE0, NRF_UARTE_EVENT_RXTO)) ;
NRF_UARTE0->ENABLE = 0;
NRF_UART0->ENABLE = 0;
nrf_power_dcdcen_set(true);
digitalWrite(LED_BUILTIN, LOW);
digitalWrite(LED_PWR, LOW);
digitalWrite(PIN_ENABLE_SENSORS_3V3, LOW);
digitalWrite(PIN_ENABLE_I2C_PULLUP, LOW);
startBle();
}
void loop() {
while (count < 500) {
BLE.poll();
count++;
}
if (isConnected == 0) {
rtos::ThisThread::sleep_for(1000);
}
count = 0;
}
void startBle() {
BLE.begin();
BLE.setLocalName("low-power-device");
BLE.setAdvertisedService(ledService);
ledService.addCharacteristic(switchCharacteristic);
BLE.addService(ledService);
BLE.setEventHandler(BLEConnected, blePeripheralConnectHandler);
BLE.setEventHandler(BLEDisconnected, blePeripheralDisconnectHandler);
switchCharacteristic.setEventHandler(BLEWritten, switchCharacteristicWritten);
switchCharacteristic.setValue("");
BLE.advertise();
}
void blePeripheralConnectHandler(BLEDevice central) {
isConnected = 1;
}
void blePeripheralDisconnectHandler(BLEDevice central) {
isConnected = 0;
}
void switchCharacteristicWritten(BLEDevice central, BLECharacteristic characteristic) {
//verify data and open door
}
But I need the arduino to have the minimum consumption because the lock works with AAA batteries.
The only alternative I've found so far is to use the command:
NRF_POWER->SYSTEMOFF = 1;
and give a physical pulse on the Arduino reset.
The theoretical idea would be to have the BLE module work independently from the main processor in a advertising mode and when it receives a connection start the rest of the board to run the code.