ET-SW01 – A very low consumption mailbox sensor
Table of Contents
Introduction
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.
Design parameters
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
Practical design
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.
Our design:
.
The circuit
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.
Power supply
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.
Battery life
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.
USB Connection
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!!!!
PCB design
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”.
Build it!
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.
Part | Value | Package | Description | Link | Qty |
C1, C2, C4, C5, C6, C7 | 0.1ยตF | 0603 | 0.1ยตF / 50V capacitor | Link | 6 |
C3 | 470ยตF | 7343 | Link | 1 | |
R1, R2, R3, R4, R5, R8, R9, R10, R11, R12 | 10kฮฉ | 0603 | 10kฮฉ resistor | Link | 10 |
R6 | 180kฮฉ | 0603 | 180kฮฉ resistor | Link | 1 |
R7 | 20kฮฉ | 0603 | 20kฮฉ resistor | Link | 1 |
T1 | AO3401A | SOT23 | AO3401A Mosfet | Link | 1 |
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 | |
B1 | CR123A | Battery holder | Link | 1 | |
PCB | ET-SW01 | PCB | ย 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.
External antenna
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!
Enclosure
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.
Software configuration
ESPHome configuration
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
Final thoughts
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!
Please subscribe to our newsletter!
Can I buy one of these from you?
We have none available sorry.
You could probably make a few bucks selling them!
We will think about it. ๐
Are the component sizes (0603/7343) metric or inches?
https://letmegooglethat.com/?q=0603+size ๐
https://www.topline.tv/sizechart.html
May seem obvious, but in my eyes it’s not that clear ๐
Metric 0603 corresponds to 0201 Imperical, while
Imperical 0603 corresponds to 1608 metric.
For 7343 i can only find reference to metric size, which corresponds to 2917 imperical.
My guess is that the resistors are imperical size 0603 and the capacitor is metric, but I’d very much like it confirmed.
Thank you
You might want to check the links provided in the BOM. As far as I know those are all standard packages.
Hi Anders,
All parts, except for the capacitor, are 0603 (imperial). The capacitor is a 7343 metric / 2917 imperial size. For some reason the moment you start looking for capacitors, they are easier to find in the metric sizes than when looking for the imperial sizes.
Good luck with the build!
Hi, Is it possible to have the “pick and place”-file published? PCBWay needs it for the assembly process
No sorry. We are about DIY, not for ordering ready made products.
R11 is nowhere to be found on the schematic. Can you please clarify? I only see 9 10k resistors not 10 as the BOM suggests.
Well spotted! R11 is a left over of the previous revision. We will remove that from the BOM. Luckily they are sub 1 cent components…. ๐
Also, C6 is 1uf not 0.1uf? Schematic and PCB screen says 1uf but the bom is listed as 0.1uf
You are correct. That is a mistake in the BOM.
How many do you need? I might have one left, need to confirm, which I can ship to you, so you do not have to build it yourself. It will come without the battery holder though!
You may use the contact form if you need to contact me.
I have already damaged 3 esp units, I noticed that there is 5V on the RX/TX outputs of the CH330N system when the module is connected to USB!!!
Hello Dariusz,
That is strange, since the ESP chip GPIO pins are 5V tolerant. (within reason)
I have personally built at least 5 of these units, and have not run into any issues. Also, I have used exactly the same setup in other projects for many many times, and not run into issues with the 5V signal levels on between the CH330N and ESP modules.
But to prevent possible issues, I will include a few components to prevent damage at all times, by clamping the signal. In a new revision I will include that.
Can you please confirm that you have used the PCB design as posted?
Question: When triggering IN1 or IN2 with ground I cannot get the device to wake up. Am I missing something? Everything seems to work, firmware loaded and events logged in HomeAssistant. If I remove the battery and re-insert the device wakes up but afterwards I cannot trigger the device to power on. I plan on using a reed switch.
Hello Tony,
That is correct. The inputs are triggered by a 3.3V pulse, not ground. The 3.3V is available on the header with the two inputs.
This is done for power saving reasons.
Please let us know if you are running into other issues .
I can trigger input 2 but not input 1. I tried pulsing IN1 but to no avail. I can power on the device on IN2 if I leave 3v3 on.
Hello Tony,
That sounds like your reset input of the flip-flop is always active. Check R10 for proper mounting, and make sure that pin 1 and pin 8 of IC2 have 0V on it, when the inputs are not triggered.
The moment the module is on, the unit should switch on and remain on until GPIO14 is made active by the controller.
It seems that I have figured out IN2 but not sure how to trigger IN1. When I apply 3v3 to IN2 I can trigger power on but IN1 I does not seem to be working for me.
See my comment on your earlier post.
Can you confirm that you have used the configuration as posted here on the page? GPIO14 needs to remain inactive during startup.The posted config will make sure that this is the case.
Hi, I would like to use this board to replace a trigboardv8 that was stolen from my mailbox recently. I have a standard normally-open (NO) reed switch installed in my mailbox which is in closed state when the mailbox is closed (magnet against reed switch).
But reading through above I have the impression that the ET-SW1 is designed to work with a switch that is only closed when the mailbox is opened? Could I make it work with my NO reed switch? Or am I misunderstanding something?
Thanks,
Tom.
Hi Tom,
Yes, that is a correct observation. The contact needs to close when mailbox opens. I looked at designing it for the opposite behavior, but that will increase the standby current unfortunately. This design was created to minimize the standby current.
Would it be possible to replace the reed contact for a different model? There are contacts available which have both types of contacts, so you can use the contact configuration required…
Thanks Paul, I have already procured a couple of 3-wire reed switches which indeed can do both NO/NC. Should be easy to replace my existing one, no worries! Looking forward to build this project ๐
Built it! My new mailbox sensor is up and running and working reliably! I am using MQTT instead of the API though as it’s client initiated. Secured it properly against theft now as well ๐ I am curious if it can beat the battery life of the trigboardv8! And I have four more pcb’s left which I can put to other uses ๐ Awesome job, Paul!
Can you share the MQTT code?