A battery powered WiFi light pulse counter for household energy monitoring.
To make the experience fit your profile, pick a username and tell us what interests you.
We found and based on your interests.
I received the PCBs from JLCPCB which look great, however I have found some issues with the board:
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.
esphome:
name: aaa
friendly_name: aaa
on_boot:
priority: 600
then:
- repeat:
count: 100
then:
- output.turn_on: led_output
- delay: 0.2s
- output.turn_off: led_output
- delay: 1s
esp32:
board: adafruit_qtpy_esp32c3
framework:
type: arduino
output:
- platform: gpio
pin: 10
id: led_output
sensor:
- platform: ntc
sensor: resistance_sensor
calibration:
b_constant: 4419
reference_temperature: 25°C
reference_resistance: 100kOhm
name: NTC Temperature
- platform: resistance
id: resistance_sensor
sensor: source_sensor
configuration: DOWNSTREAM
resistor: 100kOhm
- platform: adc
id: source_sensor
pin: 3
attenuation: 11dB
update_interval: 10s
- platform: adc
pin: 2
name: "Battery Voltage"
update_interval: 10s
unit_of_measurement: "V"
attenuation: 11dB
deep_sleep:
run_duration: 30s
sleep_duration: 10min
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 (if on 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.
Create an account to leave a comment. Already have an account? Log In.
I will definitely watch progress on this one! There are ready to use designs available but AFAIK none battery powered.
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!
Become a member to follow this project and never miss any updates
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)?