A battery powered ESP32-C3 WiFi light pulse counter that facilitates energy monitoring via the LED on household electricity meters.
A custom board has been designed to allow a compact design.
An AAA battery is used to provide power which is boosted to 3.3V using a low quiescent current boost converter.
The ESP32-C3 was selected to provide WiFi connectivity, and is easily programmed via it's integrated USB JTAG/serial.
The ESP32 will be in deep sleep most of the time, a phototransistor monitoring the light is used to trigger an interrupt and wake the ESP from sleep on each LED blink of the electricity meter.
I received the PCBs from JLCPCB which look great, however I have found some issues with the board:
The TPS61023 boost converter IC I selected will operate down to 0.5V input, but I managed to overlook the point where it states that it requires 1.8V to startup. This means It won't turn on when an AAA cell is inserted. I have found a workaround to continue testing the rest of the board by briefly applying around 2V to the terminals of the cell to allow it to start up, after which it can be removed and the converter will continue to work properly. In a future board revision I will need to use a different IC.
The pin I selected for the pulse interrupt is not in the RTC domain, for now I will just bridge it to the adjacent GPIO pin which is in the correct domain.
There were 2 tracks unconnected in the PCB layout, somehow I missed the DRC error, fortunately they were an easy bodge with a blob of solder.
Otherwise the board seems to work, the USB connection for programming works properly.
I have not yet received the phototransistor so that part is not yet tested, but I have flashed an esphome config file and it seems to run as expected.
The PCB includes an NTC for temperature measurement, and also a connection for monitoring the battery voltage. Screenshots show the logging in home assistant of the sensor readings over a few hours. The board can also have applications as a battery powered temperature monitor, for locations without grid power such as the loft or greenhouse.
After testing if the ESP32-C3 could wake from a rising edge GPIO, it does not seem to work. The datasheet was a bit ambiguous, but after writing the RTC_CNTL_GPIO_WAKEUP_REG for edge trigger the MCU would not wake when a signal was applied to the GPIO pin.
void RTC_DATA_ATTR wake_stub_sleep_counter(void)
{
wakeup_cause = esp_wake_stub_get_wakeup_cause();
if(wakeup_cause & 0x04)
{
// Wakeup cause GPIO
++wake_count;
intr_type = intr_type == GPIO_INTR_HIGH_LEVEL ? GPIO_INTR_LOW_LEVEL : GPIO_INTR_HIGH_LEVEL;
gpio_ll_deepsleep_wakeup_enable(&GPIO, GPIO_NUM_4, intr_type);
// Go back to sleep
esp_wake_stub_sleep(&wake_stub_sleep_counter);
}
else
{
esp_default_wake_deep_sleep();
// Return from the wake stub function to continue// booting the firmware.return;
}
}
0.8*1.2=0.96Wh
3.3*8.4e-3=0.0277W
0.97/0.277=34.63H (ifon continuously)
34.6/(12.4e-3*2)=1395Hours (if one pulse per second on average)
The ESP32 has an pulse counting peripheral which would ideal for counting the LED pulses on a electricity meter, unfortunately it does not operate in deep sleep so will consume to much energy to allow for a decent battery life.
Instead I plan to configure an input pin to wake the CPU, which can then increment a variable before going back to sleep. The ESP32 normally executes code from an SPI flash, but can keep a small amount of code in the RTC RAM that can be executed after waking from sleep without powering up the flash, which I plan to use for the variable incrementing code. This means the CPU can be awake for less time saving power.
The ESP32-C3 reference manual indicates that it supports wake on rising edge which would be the best option, however the esp-idf library seems to indicate that it is not supported so I will have to test this.
You may be pleasantly surprised on the average / total energy consumption. One pulse per second is very high for an average - it equates to 3.6Kw. Sustained 24/7 that would be a daily consumption of nearly 90kWh - much more than the UK average of 7kWh / day (OFGEM). That 7kWh averages (I think!) a pulse every 12ish seconds, so nearly 2 years (again ignoring wifi calls)?
Your approach to using an input pin to wake the ESP32, coupled with executing a small code segment from RTC RAM to increment a variable, is a smart workaround for the energy consumption challenge during pulse counting. Leveraging the ESP32's ability to keep code in RTC RAM for post-wake execution is an efficient way to minimize power usage and extend battery life. While the discrepancy between the ESP32-C3 reference manual and esp-idf library regarding wake on rising edge is a concern, thorough testing will provide clarity on its support. Best of luck with your project!
You may be pleasantly surprised on the average / total energy consumption. One pulse per second is very high for an average - it equates to 3.6Kw. Sustained 24/7 that would be a daily consumption of nearly 90kWh - much more than the UK average of 7kWh / day (OFGEM). That 7kWh averages (I think!) a pulse every 12ish seconds, so nearly 2 years (again ignoring wifi calls)?