Skip to content

Schematics

Denis Stepanov edited this page Apr 18, 2024 · 42 revisions

Mailbox Schematics

Remote Module (Transmitter, Mailbox)

Remote Module Schematic

(click to enlarge)

The main components of the schema are ESP-01S controller U2 and HC-12 controller U1. Both controllers are mounted on sockets J4, J5, J7, allowing their removal for reprogramming. ESP-01S TX is connected to HC-12 RX for data transmission. ESP's RX is not used for serial communications, and is reconfigured to serve as digital input to read the door sensor status. Similarly, since HC-12 is used only to transmit data, its TX output line is not connected.

Door sensor is implemented with a reed switch. Switch SW1 is connected via a ~40 cm two-wire cable ending with JST-XH connector J14, J15. A small internal cable is then used to connect the external port to an internal socket J1, J2. A switch needs to be "normally closed" (NC), so it stays open when mailbox door is closed (this is the state shown on the schematic: two switch halves side by side, switch magnetized). I have got an NC, type "B" reed switch, with both "normally open" (NO) and NC contacts. Quite counter-intuitively, the wire has to be connected to the NO contact in order to make it work as intended; you might need to experiment a bit. To allow proper reading, the switch is pulled up by resistor R1; consequently, it reads LOW when mailbox door is opened (switch is closed). The switch may (and does) bounce, but it is not essential for the application, so no specific protection from this was made.

ESP's GPIO2 is configured as a secondary serial line, and serves to transmit diagnostic log information via an on-board connector J9 (you can drop the connector safely, if logging is of no interest). Resistor R3 is used to pull up GPIO2 when diagnostic port is not connected. Without it, the ESP might not boot reliably (this was actually observed). Since GPIO2 also controls ESP's built-in LED, the (nice) side effect is that controller blinks blue shortly after the mailbox door was opened and before going to sleep.

ESP's GPIO0 is connected to the HC-12 SET line, and is used to send a wake up LOW pulse to HC-12 when coming out from deep sleep. Resistor R2 is recommended by HC-12 data sheet in order to protect controller pin from over-current. If this is not a concern, R2 can be removed (i.e., short-circuited).

Capacitor C2 serves to form a LOW impulse on ESP's reset line (RST). RST in ESP8266 is internally pulled up with a 12k resistor. When mailbox door is closed (switch SW1 is open), both poles of C2 stay pulled up, so no current flows, and nothing happens. When mailbox door opens (switch closes), the negative pole of C2 gets grounded, which, for a short moment, makes ESP's RST grounded too. As the capacitor charges, it stops conducting, and LOW potential on RST disappears. This forms a dirty, but reliable enough pulse to wake up ESP from deep sleep when mailbox door is opened.

A small capacitor C1 is used to protect HC-12 SET line from parasite noise. It was observed that when ESP goes to sleep, it causes some unwanted change of GPIO0 level (what it is, exactly, is difficult to tell without an oscilloscope). This noise causes HC-12 to wake up from its own deep sleep prematurely. The capacitor C1 "eats up" this noise.

Antenna AE1 is a 435.8 MHz monopole with a short coaxial feed connected via RP-SMA connector to the case and, inside the case, with a RP-SMA-to-IPX coaxial cable to the HC-12 antenna socket. See Antennas for more details.

The whole circuit is powered with one LS14250 battery BT1, inserted in a battery holder J10, J13. A large capacitor C3 is used to stabilize battery voltage during consumption peaks (on boot and during HC-12 data transmission). See Battery section for more details.

The following time diagram explains how the circuit works, taking as example a door opening for 3 seconds. Note that it is not a true oscillogramme, but rather my view of the process. Short events might not be drawn to scale.

Remote Module Time Diagram

(click to enlarge)

When mailbox door opens, the reed switch goes to LOW level. C2 capacitor converts this step into an ESP8266 reset pulse, which wakes ESP from deep sleep. ESP-01S power consumption goes from nearly zero to ≈ 15 mA. It takes about 200 ms for the main program to take control. The program then forms a short pulse on HC-12 SET line, which wakes HC-12 from its own deep sleep. HC-12 idling consumption in FU4 mode is also about 15 mA. 400 ms are provided to HC-12 to become reliably operational. After that, ESP sends the first 8 bytes message to HC-12 with a speed of 1200 bod, which takes about 50 ms to arrive. HC-12 retransmits the same 8 bytes message on the air with a lower speed of 500 bod, spending about 130 ms. Its power consumption during transmission grows to ≈ 50 mA. Summing up the times, we can say that the message leaves transmitter within 0.7 s from the door opening moment. Then the circuit enters wait loop for the door closure, or 30 s timeout, whichever comes first. In this example, the door is closed after 3 seconds. The reed switch bounces, but is it not important, because the programs stops switch processing on the first HIGH level received. As soon as the door is closed, the program forms and sends the second, door closure message. Then the transmitter HC-12 is put into sleep mode. This is quite a lengthy process (≈ 500 ms), consisting of switching the serial channel from transmission into HC-12 command mode and sending it a command AT+SLEEP. Once HC-12 falls asleep, ESP puts itself in the deep sleep. At this point, the module is ready to receive the next door opening event.

It is important to note that no latching for ESP8266 RST line was implemented. It takes about 0.7 s from door closure for the module to go to sleep. If the door gets opened again in less than a second from closure, the controller will likely execute a cold restart instead of waking up from sleep. The opening event would be still delivered to a user, but along with a "reboot" message. This situation has been rarely observed in practice, so it is considered a minor issue.

PCB layout using 4x6 cm perfboard (facing parts; blue — backplane connections; orange — jumper wires; solid black — soldered parts; dashed black — removable parts' footprints; hexagons — nylon supports for elevated parts):

Remote Module PCB

(click to enlarge)

Soldered backplane:

Remote Module Backplane

(click to enlarge)

Front view, corresponding to PCB layout view, is shown below.

Remote Module Front

(click to enlarge)

Same with controllers and peripherals inserted (with test antenna connected):

Remote Module Front with Components

(click to enlarge)

It is recommended to connect some antenna (test or final one) before inserting the battery, as the module will send messages right away on boot, and emitting without antenna might damage HC-12 circuits.

Fully assembled in Tictac case:

Remote Module Assembled

(click to enlarge)

A simple piece of foam rubber is used to hold the board in place. Green bottle caps serve as legs to raise the module above mailbox bottom level where flakes of water might form.

One can test powered module by shorting sensor contacts with tweezers for 2-3 seconds (this will emulate door opening). The ESP blue LED shoud blink at the beginning and at the end of shorting, signalling two messages sent. If you have local module running at that time, it should record messages received. Remember to keep antenna connected during the test.

Remote module accessories — antenna and reed switch — are shown below.

Remote Module Accessories

(click to enlarge)

Installed:

Remote Module Installed

(click to enlarge)

I have got a collective mailbox with double walls. This allows fitting most of the parts behind the walls; the only visible part is a reed switch.

Here's an example of another mailbox equipped. This model is single-wall painted steel, so the setup is mounted along the inner walls, except for the antenna which has to be outside of a metal cage. Wires, sensor and antenna are hot-glued, and the transmitter unit is fixed to the ceiling with a pair of magnets.

Remote Module 2 Installed

(click to enlarge)

Local Module (Receiver, House)

Local Module Schematic

(click to enlarge)

The receiver schema is extremely simple. Like for the remote module, the main components of the local module are ESP-01 controller U3 and HC-12 controller U1, mounted on sockets J4, J7, J9. Here, HC-12 is used only to receive data, so its TX pin is connected to ESP's RX. Conversely, HC-12's RX and ESP's TX (GPIO1) are not connected. In ESP-01, TX controls a built-in blue LED; this is used for LED-based notifications.

Similarly to the remote module, ESP's GPIO2 is used for a diagnostic serial line J10. In ESP-01 case, however, no specific boot problems have been observed, so no pull-up resistor was added.

ESP's GPIO0 is connected to a push button SW1. An internal pull-up is used (INPUT_PULLUP), so no external resistor was needed. Button short press is used to acknowledge a mailbox event, and long press is used to enter Wi-Fi configuration mode. Since GPIO0 has a special role in ESP8266, the button shall not be pressed during power up, otherwise the controller will not boot.

Since local module is constantly powered, sleep mode is not used; consequently, ESP's RST and HC-12's SET pins are not connected.

Antenna AE1 is a 435.8 MHz dipole with a very long coaxial feed connected via RP-SMA connector to the case and, inside the case, with a RP-SMA-to-IPX coaxial cable to the HC-12 antenna socket. See Antennas for more details.

The circuit is powered from a micro-USB connector J1 using an AMS1117-based 5V to 3.3V converter. Some capacitors, probably, would not hurt in this schematic, but no particular issue with power was observed. The converter is also mounted on a socket, J2; however, it could have been soldered to PCB directly.

PCB layout using 3x7 cm perfboard (facing parts; blue — backplane connections; orange — jumper wires; solid black — soldered parts; dashed black — removable parts' footprints; hexagons — nylon supports for elevated parts):

Local Module PCB

(click to enlarge)

Soldered backplane:

Local Module Backplane

(click to enlarge)

Front view, matching the PCB layout view:

Local Module Front

(click to enlarge)

Thin micro-USB connections are quite difficult to solder, so I opted for a pre-soldered adapter with connection holes compatible with a perfboard. To make the button stand out of the enclosure, a model with a tall lever is used, and the button itself is further elevated with the help of a nylon support. Voltage converter is inserted into a header with long legs, bent at 90 degrees.

Same front view with controllers and peripherals inserted:

Local Module Front with Components

(click to enlarge)

Fully assembled (with a test antenna):

Local Module Assembled

(click to enlarge)

Because inserting a micro-USB cable exerts quite a strong force on the board, the latter is fixed to the enclosure with four nylon bolts.

Installed (for optional Raspberry Pi addon see Google Home):

Local Module Installed

(click to enlarge)

Here we take advantage of Pi presence to power the receiver module from it and spare one power supply. A small caveat with this scheme is that if Pi reboots for whatever reason, it will power off its USB ports for a moment, which will result in receiver module restart. If you do not want that, or if you do not have Pi next to the module, you need to add a small 5 V 500 mA power supply (1 €).

Antenna part:

Local Module Installed

(click to enlarge)

Bill of Materials

Schematic Ref Description Quantity Price (2020 €)
Remote Module
R:U1 HC-12 SI4463 MCU 1 2.13
R:J4 HC-12 Socket (2.5 mm Header Male-Female) 5 pins 0.05
R:U2 ESP-01S MCU 1 1.30
R:J5+J7 ESP-01 Socket 2x4p 1 0.06
R:BT1 Saft LS14250 3.6 V Battery 1 1.50
R:J10+J13 14250 Battery Holder 1 0.28
R:SW1 HWP BS-31B Reed Switch 1 1.78
Ribbon Cable 2p 50 cm 0.06
Ferrule 0.5 mm² AWG22 2 0.01
R:AE1 435.8 MHz Monopole Antenna: Copper Install Wire 2.5 mm² 155 mm 0.10
R:AE1 435.8 MHz Monopole Antenna: RG316 Coaxial Cable 411 mm 0.29
R:AE1 435.8 MHz Monopole Antenna: RP-SMA Male Connector 1 0.22
R:AE1 435.8 MHz Monopole Antenna: Heat Shrink Tube ⌀5 mm 8 cm 0.15
U.FL IPX Female to RP-SMA Female Cable 215 mm 1 1.08
R:R1,R3 Resistor 10k Ohms 2 0.02
R:R2 Resistor 330 Ohms 1 0.01
R:C1 Electrolytic Capacitor 0.47 µF 1 0.01
R:C2 Electrolytic Capacitor 10 µF 1 0.01
R:C3 Electrolytic Capacitor 470 µF 1 0.01
R:J1,J14 JST-XH Male Connector 2p 2 0.04
R:J2,J15 JST-XH Female Connector 2p 2 0.04
R:J9 Diagnostic Port Connector (2.5 mm Header Male-Male) 2 pins 0.02
4x6 cm Prototype PCB 1 0.20
Nylon Hex Spacer M2 2 0.06
Nylon Nut M2 4 0.12
24AWG Wire 30 cm 0.07
Tictac Case 1 2.40
Foam Rubber 6 cm ~0
Bottle cap (thin) 2 ~0
Superglue ~0
Solder & Flux ~0
Subtotal Remote Module 12.02
Remote Installation
Screw 2 0.06
Bolt M2.5 2 0.06
Nut M2.5 2 0.06
Cable Tie 1 0.03
Hot Glue ⅒ stick 0.01
Subtotal Remote Installation 0.22
Subtotal Remote 12.24
Local Module
L:U1 HC-12 SI4463 MCU 1 2.13
L:J4 HC-12 Socket (2.5 mm Header Male-Female) 5 pins 0.05
L:U3 ESP-01 MCU 1 1.30
L:J7+J9 ESP-01 Socket 2x4p 1 0.06
L:U2 AMS1117 5 V to 3.3 V Converter 1 0.17
L:J2 Converter Socket (2.5 mm Header Male-Female Long Needle) 3 pins 0.03
L:AE1 435.8 MHz Dipole Antenna: Copper Install Wire 2.5 mm² 310 mm 0.20
L:AE1 435.8 MHz Dipole Antenna: RG316 Coaxial Cable 9 m 6.56
L:AE1 435.8 MHz Dipole Antenna: RP-SMA Male Connector 1 0.22
L:AE1 435.8 MHz Dipole Antenna: Heat Shrink Tube ⌀5 mm 2 cm 0.04
L:AE1 435.8 MHz Dipole Antenna: Cable Trunking 50 cm 0.25
L:AE1 435.8 MHz Dipole Antenna: Cable Trunking Cap 1 0.75
L:AE1 435.8 MHz Dipole Antenna: Hot Glue ⅒ stick 0.01
L:AE1 435.8 MHz Dipole Antenna: Plastic Bottle Cap 1 ~0
U.FL IPX Female to RP-SMA Female Cable 215 mm 1 1.08
L:SW1 Push Button 1 0.05
L:J1 MicroUSB B Female to DIP Adapter 1 0.08
L:J10 Diagnostic Port Connector (2.5 mm Header Male-Male) 2 pins 0.02
3x7 cm Prototype PCB 1 0.20
Nylon Hex Spacer M2 3 0.09
Nylon Bolt M2 4 0.12
Nylon Nut M2 7 0.21
24AWG Wire 20 cm 0.05
Tictac Case 1 2.40
USB A Male to microUSB Male Cable 1 1.00
Solder & Flux ~0
Subtotal Local Module 17.07
Local Installation
Tubing Wire Conduit ⌀16 mm 7 m 4.47
Round Cable Clips ⌀16 mm with Steel Nails 10 1.20
Screw 4 0.12
Subtotal Local Installation 5.79
Subtotal Local 22.86
Google Home Support
Raspberry Pi 4B 4 MB 1 56.06
Raspberry Pi Case with Fan and Heat Sinks 1 3.33
USB A Male to USB C Male Cable 1 1.50
230 V USB A Power Supply 3 A 1 2.82
Subtotal Google Home Support 63.71
Google Home Support Installation
Screw 2 0.06
Subtotal Google Home Support Installation 0.06
Subtotal Google 63.77
TOTAL 98.87

Prices are VAT included, without delivery cost (delivery may easily double the price). They are based on not very optimized costs from online sellers, mostly AliExpress.

98 euros looks like a lot, but the largest part of it goes to the optional Raspberry Pi component. You might likely get your project much cheaper:

  • if this is not your first DIY project, it is very likely that half of the parts you would already have;
  • if you chase the prices (I was not), you can easily get 30–40% off the listed price. Also, buying from the same shop and grouping deliveries can help saving on delivery;
  • you might already have a Raspberry Pi running around (−64 €); it can also be replaced by any existing computer running during mail service hours (or dropped altogether if you do not need Google Home notifications);
  • your setup might be quite different; e.g., no need for a 9 m conduited coax cable (−12 €), less expensive cases (−5 €), etc.

Programming

There are many ways of programming ESP-01 and HC-12 controllers, and, I am sure, this section will not teach you much. If you have got your own programming adapter for ESP-01, it will surely do. I historically use Arduino Uno for such tasks, so the schematics are made for Arduino. Schematic for programming ESP-01 and ESP-01S is the same.

ESP-01 / ESP-01S

ESP-01 Programming Schematic

(click to enlarge)

In this schematic, Uno serves just as a transparent USB-to-serial converter, so it is important that its own program does not intervene. To achieve this, first program Uno with a "BareMinimum" sketch (part of Arduino IDE distribution), then switch the board support to ESP8266 and program the ESP sketch. You can repeat ESP programming many times as long as you do not modify the Uno program.

Because Uno acts as a repeater, its connection scheme is a bit counter-intuitive. Uno TX is connected to ESP TX; Uno RX is connected to ESP RX. Because Uno uses TTL (5V) signalling, and ESP runs on lower 3.3V voltage, a voltage divider R1, R2 is needed on RX line. It will work without a divider too, but the chances of damaging the ESP are somewhat higher. In principle, a reverse conversion 3.3V to 5V would be needed on TX line, but Uno's TX is sensitive enough to work fine with 3.3V input.

There are many warnings in Internet that one should not power — not to say — program, ESP8266 from Arduino, because its 3.3V power line is too weak for that. In practice, I never observed an issue with my Uno and ESP-01, but if you run into a trouble, power ESP-01 from a separate 3.3V power supply.

This schematic is designed solely for programming, you cannot run a program in place, because ESP's GPIO0 is grounded. If this is needed, you have to add a push button or a switch onto the GPIO0 line. In practice, I also have a switch on ESP's VCC line, in order to conveniently power cycle ESP without removing from the socket; however, this is not strictly required.

HC-12

HC-12 Programming Schematic

(click to enlarge)

HC-12 supports wide range of voltages, in mailbox schemas above it works with 3.3V; in programming schematic here it is connected to 5V, which is Arduino Uno's native voltage.

Unlike with ESP-01 programming, here Uno has to be preloaded with a HC-12 configuration sketch. Grounding HC-12's SET is needed to ensure communication speed of 9600 bod; otherwise HC-12 will respond with speed which was previously configured. Uno pins D8, D9 are arbitrarily selected; you can use other pins and update the "rfconf" sketch. Since the configuration sketch does its job in setup() function, order of powering up matters. Make sure HC-12 is connected and powered by the time you load the sketch into Uno; if not, power up HC-12 and reset Uno to run the program again. If you are connecting HC-12 pins one by one, make sure VCC is connected the last.

Diagnostic Port

Diagnostic port is indispensable during programming or debugging. Using it, applications can log important actions or status information. This information is often more detailed than what can be found in application log, and it does not need network to operate. To access the log, one has to connect to the diagnostic port with any serial-to-USB converter. Using Arduino Uno, it will look as follows:

Diagnostic Port Schematic

(click to enlarge)

Note that diagnostic port cannot be used to program ESP-01 in place. Again, like in the case of ESP-01 programming, Uno has to be programmed with "BareMinimum" (empty) sketch. Arduino IDE's serial monitor can then be used to access the log. Note that the difference with programming is that ESP and Uno will be powered using their own power supplies; the port connector serves just to transmit information.

Port configuration is 115200/8-N-1 (115200 bod, 8 bits, no parity, 1 stop bit).

In most ESP8266 applications, default TX (TX0, GPIO1) would used for these purposes. In this application TX is taken for other functions, like communicating with HC-12; consequently, a secondary TX (TX1, GPIO2) is configured for the log. This confiuration is done programmatically on startup; consequently, ESP bootloader trace will not be visible this way.

Development Environment

Development setup with breadboards:

Development Setup

(click to enlarge)

Here the third board (connected to the laptop) is an Arduino Uno R3 with an ESP8266 programming shield. Remote module breadboard is fit with a 18650 rechargeable battery (different from what is used in final setup). Breadboard wiring also includes some auxiliary circuitry allowing reprogramming the controllers without taking them out from their sockets.