ET-SW01 – A very low consumption mailbox sensor
Table of Contents
With the amount of online shopping happening, which only became more during the Covid-19 pandemic, it would be handy to know when you receive something in your mailbox. Monitoring your mailbox with a remote switch using Home Assistant will come in handy. There are several ways of doing this, but since we want to use ESPhome, there is a requirement to use an ESP8266 o ESP32 based solution. This design, the ET-SW01 is what we came up with.
The requirements were:
- Multiple switches need to be able to be connected. (One detection and one reset as a minimum)
- Battery powered, with very low power consumption, to extend battery life
- It needs to be small enough to fit in a mailbox
- Possibility to connect external antenna (optional)
- Based on an ESP8266 or ESP32 module to allow easy use with ESPhome
- Enclosure must be readily available or 3D printable
ESP modules have a deep-sleep mode available which will lower the power consumption considerable. Reading the various articles online, the current can drop to approx. 20µA while in deep-sleep. This approach was considered, but after reading the ESPhome Deep Sleep component manual page, it became clear that the only way to use it was by using an ESP32 based module. Since these modules are in general much larger than an ESP8266 based module, an alternative approach was taken.
The main principle of the circuit is based on the fact that the ESP module is normally powered down completely. This will eliminate all possible power consumption of the ESP module. Therefore we need a power switch which will power the module up when there is mail detected.
This power switch is created using a CMOS logic gate chip, the 4001, which has a quiescent current of under 1µA. (At least 20x power saving over the deep-sleep of the ESP modules!) The logic gates are wired in as a so-called flip-flop. There are two of these flip-flops, one made up by IC2A & IC2D and the other one made up by IC2B & IC2C.
Each flip-flop has 2 inputs, one connected to the switch (the “Set” input of the flip-flop), and the other one (the “Reset” input of the flip-flop) connected to the ESP module. The output of the flip-flop is connected to an OR gate (IC1). The output of this gate becomes active the moment one of its inputs is active. This OR gate output is directly powering up the ESP module through MOSFET T1.
The outputs of the flip-flops are also connected to the ESP module, so the ESP module can detect which input was the one switching on the ESP module, so once the module is powered up, this information can be transmitted to Home Assistant.
Once Home Assistant has processed the information, it can then switch on GPIO14, which is the reset signal to the flip-flops. This will result in the ESP module to power off, ensuring that Home Assistant is “aware” of the input status of the switch module.
The ESP module picked for this project is the ESP-07 module in the variant with 1MB (8Mbit) of memory. Older ESP-07 modules had only 512kB (4Mbit) memory, which will work too, but in that case it will be 100% impossible to use OTA updates, even with a brand new battery. Optionally an ESP-12 module can be used, just make sure that the additional connections on the “short side” of the module are not touching any component mounted next to the module.
The switch inputs
Imagine that there is a piece of mail blocking your sensor / keeping your switch activated. That might result in Home Assistant not being able to switch off the module, draining the battery without any reason. To prevent this from happening C7 / R12 have been added to the circuit. These two components will ensure that the flip-flop is only reacting on a rising edge on input 1. So it will detect the switch closing, but it will “ignore” / “filter” the signal if it remains active. It needs to be inactive for a number of milliseconds to allow a re-trigger. To allow flexibility, input #2 does not have this capacitor, so you have a choice in your application. If you connect here a pushbutton “mailbox emptied”, then Home Assistant can change the internal flag indicating mail in the mailbox.
The power supply section of the design is very important, since in this section a lot of power can be wasted. Since the decision was made to use a non-rechargeable battery, specifically a CR123A lithium battery, which meant no charging control / monitoring was required. Another great benefit of this type of battery is that the nominal voltage of this type of battery is 2.85 – 2.90V, which eliminates any possible voltage regulation requirement for the ESP module:
In the above curve it is clear that for the majority of the discharge time under normal temperatures (between -20C and +23C) the voltage is pretty stable. To check if this theoretical curve is also achievable in practice, one of the finished modules was switched on, and left, reporting every minute the Wifi signal strength and the battery voltage. This curve was achieved:
In this curve the tail end of the first test can be observed, and a full discharge curve of the second test. Besides the stable voltage for the majority of the discharge, also something else can be observed. The module was working until the voltage dropped under 1.50V! This reading can be skewed because of the internal construction of the ESP onboard ADC, which might become (very) inaccurate at lower supply voltages. But it looks like the module did work with a supply voltage of < 2.0V.
The total running time is > 20 hours, but this is for sure a bit skewed, since every time the module starts up, and connects to the WiFi network, it will use more current than when the module is already connected to the WiFi network. Therefore for the calculations of how many months the battery will last, a total discharge time of 10 hours (36000 seconds) is used.
All our experiments have shown that the module requires less than 10 seconds to start up, connect to Home Assistant, and then afterwards Home Assistant to switch off the module. If the calculation is done with a battery life of (at least) 10 hours and a connection cycle of (max) 10 seconds, a total of 3600 cycles can be achieved. Each time the sensor is activated or when the “mailbox emptied” button is pressed, counts like a cycle. If as an average 4 cycles are performed per day, the lifetime of the battery should be at least 3600 / 4 = 900 days, or in other words > 2.5 years! This was considered as more than sufficient to achieve the energy efficiency we are looking for. We do not know what the real life battery life is going to be. Depending on the number of cycles per day, temperature, battery quality / capacity, it would not surprise us if the actual lifetime of the battery is far exceeding 2.5 years.
To program the module, the design has an USB <–> serial bridge mounted. When the USB cable is plugged in, it is very important to remove the battery, since otherwise the USB power will start to charge the lithium battery, which can result in damage to the circuit or the battery to get damaged. A low quiescent current 3.3V regulator has been used to feed the module during USB connection. The diodes in the circuit ensure that the USB converter chip is only powered when the USB cable is connected, this to prevent the quiescent current of the USB chip to discharge the battery.
Programming the module has to be done using the USB connection. this due to the OTA programming working very unreliable on this module. This is caused by high current consumption during the flash programming which the battery has issues with delivering when it is not a brand new. The only times we succeeded to do OTA programming was with a very fresh battery installed, and then the chance was only 1 in 5 that it would work… Therefore the only way to program, which we know for sure works absolutely fine and reliable, is using the USB cable. To flash the module, close the “Flash” jumper pads on the module, and afterwards start the flash program on your computer.
Warning! DO NOT USE ANY RECHARGEABLE BATTERY TO SUPPLY THE MODULE!!!!
The voltage of the rechargeable batteries is too high and will cause catastrophic damage to the ESP module!!!!
The goal was to have the circuit as small as possible. The idea was to make sure the circuit would fit on a PCB roughly the same size as the battery holder. This is the final result:
As you can see, the full design is an SMD design. If we would have made it with conventional components, the PCB would be at least 2-3x larger.
For people with some experience in building projects with SMD parts, it might be very doable to build this. There are not many components, and the design is not “tiny”.
See below the list with the components you will need to build the SW01 module by yourself. Remember that a number of the SMD components are not available to purchase in single quantities. You will most likely have a good number of components left after building a module!
We would really appreciate it if you will use the links below to buy the components, since it will give a little bit of commission to us without any additional cost for yourself. These commissions will be used to cover some of the costs involved in the development of the design.
|C1, C2, C4, C5, C6, C7||0.1µF||0603||0.1µF / 50V capacitor||Link||6|
|R1, R2, R3, R4, R5, R8, R9, R10, R11, R12||10kΩ||0603||10kΩ resistor||Link||10|
|D1, D2||B0520LW||SOD123||Schottky diode||Link||2|
|IC1||74AHC1G02||SOT23-5||Single 2 input NOR gate||Link||1|
|IC2||CD4001||SO14||Quad 2 input NOR gate||Link||1|
|IC3||ESP07||ESP 8266 module||Link||1|
|IC4||CH330N**||SO08||USB to Serial bridge||Link||1|
|IC5||HT7333A||SOT89R||3.3V voltage regulator||Link||1|
|X1||µUSB||Micro USB socket||Link||1|
** The CH330N and CH340N are pin compatible. Both can be used.
There are a number of sellers at AliExpress which sell complete kits of 0603 resistors and/or capacitors. In general these are very good deals looking at the price each. Therefore we have selected one of these kits for all resistors.
Putting it together
Unlike with our other projects, this design uses SMD components. These are a lot more difficult to mount for inexperienced hobbyists. If you are going to build it by hand, start with the resistors, followed by the capacitors and the MOSFET. Then mount the USB connector, this to ensure you have enough space to solder the connector without IC4 blocking the pads. The ICs together with the diodes and voltage regulator are next. The final step is mounting the ESP module. Note; You can order the solder paste stencil for this PCB from PCBway as well. Just use the PCB-link above.
A lot of mailboxes are made from metal which is very effective in blocking the RF signals coming from the ESP module. In that case a simple external antenna could be beneficial. Depending on the type you use, you might want to coat the antenna with “conformal coating” (preferred) or acrylic lacquer, which will prevent corrosion of the antenna.
To use the antenna, a small modification needs to be made to the module. The component marked in the below photo needs to be removed. To do so put a small blob of solder on the soldering iron tip, and touch the component. Within a few seconds the component should come loose and stick to the soldering iron.
If this component is not removed, the antenna on the module and the external antenna will be connected at the same time. This will make the total performance extremely poor! Therefore it is required to be removed if an external antenna is used!
To mount the PCB in the mailbox, we have designed a 3D printable enclosure. It is a “tight” fit, and uses a snap-fit lid. If the enclosure is mounted outside the mailbox, then print it in PETG or ABS, and use some silicone to closeup the connection opening. It is recommended to place the box somewhere inside the mailbox, and if needed bring an external antenna to the outside of the mailbox.
The software configuration is a bit different than normal. Where for other designs the wifi configuration was dynamic, using DHCP, but for this particular situation it is advisable to use static / manual configuration instead. The DHCP handshake / setup will take time and more power to perform. Making it static with “fast_connect” set to true, will save a lot of additional power consumption, and therefore battery life. See below the YAML for this project with a number of comments in it to guide you how to configure it for your setup.
substitutions: devicename: espthings-sw01-01 upper_devicename: espthings SW01 01 esphome: name: $devicename comment: Mailbox sensor platform: ESP8266 # Use for the ESP-07 module with 1MB of memory, the "esp01_1m" board. board: esp01_1m board_flash_mode: dout # The below configuration lines create a "safety net", in case the module is unable # to contact Home Assistant, and therefore is not switched off by Home Assistant. # In that case, there is a possibility that the module will remain powered on, draining # the battery. With the below settings, the module will shutdown after 30 seconds, # saving the battery energy. on_boot: - priority: 200.0 then: - delay: 30s - switch.turn_on: resetinput logger: api: password: !secret esphome_api_password ota: password: !secret esphome_ota_password web_server: port: 80 wifi: ssid: !secret esphome_wifi_ssid password: !secret esphome_wifi_password # Ensure you set the IP address to an available address! # An option is to use the DHCP option first, and then # record the settings your router issues to the module. # Then copy those settings below. # To use the automatic DHCP settings comment out the below lines manual_ip: static_ip: 192.168.1.100 gateway: 192.168.1.1 subnet: 255.255.255.0 fast_connect: true #power_save_mode: light # End of network config. sensor: - platform: wifi_signal name: "$upper_devicename - RSSI" update_interval: 9s - platform: adc # This is the sensor to track the battery voltage, the internal option of "pin: VCC" # has shown to be less accurate than this solution. pin: A0 filters: - multiply: 10 # The offset was applicable to our prototypes. Please confirm the offset with your # multimeter, and replace "-0.15" with the correct offset. - offset: -0.15 name: "$upper_devicename - Battery Voltage" update_interval: 9s binary_sensor: - platform: gpio pin: number: GPIO13 name: "$upper_devicename - Input 1 - Edge" filters: - delayed_on: 20ms - platform: gpio pin: number: GPIO12 name: "$upper_devicename - Input 2 - Level" filters: - delayed_on: 20ms button: - platform: template name: "$upper_devicename - Reset" icon: "mdi:emoticon-outline" on_press: - switch.turn_on: resetinput switch: platform: gpio disabled_by_default: true pin: GPIO14 id: resetinput # Saving some energy by disabling the status LED. During testing # you might want to keep the LED enabled. #status_led: # pin: # number: GPIO2 # inverted: true
The goal was to design a simple power efficient module to detect mailbox activity. The big problem with WiFi power consumption we tried to solve in a creative manner, which has proven to be very efficient. It is not clear yet how long the battery will last, but what we have seen so far it looks like it will be for a very long time.
Please let us know in the comments what you think.
If you enjoy our designs, please leave a comment and subscribe to our youtube channel, to help us grow the website and channel!