-
Notifications
You must be signed in to change notification settings - Fork 1
Schematics

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, which allows 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 on-board connector 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. It is important to note that no latching for RST line has been implemented. With generous transmission and sleep preparation delays it takes about two seconds from door closure for the module to go to sleep. If the door gets opened again in less than two seconds, the controller will execute a cold restart instead of waking up from sleep. The event would be still delivered to the user, but along with a "reboot" message. This situation has been rarely observed in practice, so it is considered a minor issue.
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 SMA connector to the case and, inside the case, with a SMA-to-IPX coaxial cable to the HC-12 antenna socket. See Antennas for more details.
The whole circuit is powered with one LS12450 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.
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):

Soldered backplane:

Front view is show below. The photo is taken from an earlier version, which does not include the resistor R3.

Same with controllers and peripherals inserted:

Fully assembled (with a simple piece of foam rubber used to hold the board in place):

In the latest version of enclosure a soldered whip antenna is replaced with an SMA connector and an external antenna. See Antennas for more details.

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 SMA connector to the case and, inside the case, with a 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):

Soldered backplane:

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.
Front view with controllers and peripherals inserted:

Thin micro-USB connections are quite difficult to solder, so I opted for a pre-soldered connector 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.
Fully assembled:

Again, in the final version an external hand-made antenna is used instead of the industrial helical antenna shown. See Antennas for more details.
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 ESP01, 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.

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 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 (see "rfconf" sketch in this project). 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.
Development setup with breadboards:

Here the third board (connected to the laptop) is Arduino Uno R3 with an ESP8266 programming shield on top. 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.