# 0x00 Introduction
## Statement: Please pay attention to safety when using this module because it involves strong electricity. I am not a professional PCB designer, so the board may have safety defects. I am not responsible for any consequences caused by the use of this project. Please be informed! Do not touch any part of the board after it is connected to the mains!
### I have only been exposed to PCB drawing board soldering for a month or two. If there is anything wrong with the project, please feel free to enlighten me. Thank you! The circuit principle part refers to the socket module of alei643 [https://bbs.hassbian.com/thread-14523-1-1.html](https://bbs.hassbian.com/thread-14523-1-1.html ), I would like to thank the original author!
Module features:
* Use `ESP-01M` to control one or two magnetic latching relays
* Use Hongfa dual coils and a set of conversion relays, which can maintain the original state when the power is turned off, and can be controlled together with the physical double control switch combination Electrical appliances
* Relays only need short-term pulses to activate, and do not need to maintain voltage, so they have low power consumption and less heat generation
* One relay (secondary board) can be plugged in, the main and secondary boards are connected using XH2.54 terminals, and the high-voltage part uses screw terminals Connection, convenient wiring
* Comes with electrical switch detection circuit, which can detect the switch status of the controlled electrical appliance and display it on the webpage
* The software environment is `Arduino IDE`, supporting OTA
The overall power consumption of the upgrade module is about 0.6W (if the controlled electrical appliance If open, an additional 0.2W power consumption of the detection circuit must be added)
![Module power]
![Front]
![Back]
Module size: Main board A: 51mm×35mm, sub-board B: 28mm×26mm, heights are all About 2cm, it can be stuffed into the 86 panel. Currently, two boards have been produced, one to control the socket and one with a sub-board to control two lights, both of which are currently running well.
# 0x01 Prepare components
1. `ESP-01M`, the 2M FLASH notebook used here, [https://m.tb.cn/h.UY3GZep?sm=6b1799](https://m.tb. cn/h.UY3GZep?sm=6b1799)
2. For magnetic latching relay, select `HF3F-L-05-1ZL2T (10A6 pin)` [https://m.tb.cn/h.U10HxJG?sm=62a410]( https://m.tb.cn/h.U10HxJG?sm=62a410)
3. 220V to 5V power module, [https://m.tb.cn/h.U1BrL6V?sm=be1bb5](https:// m.tb.cn/h.U1BrL6V?sm=be1bb5)
4. (Optional) Co-directional XH2.54 cable, used to connect the main and secondary boards, select `5P`, `double-head`, [https:/ /m.tb.cn/h.UczQRHb?sm=0bbc6c](https://m.tb.cn/h.UczQRHb?sm=0bbc6c)
5. Please purchase DuPont cable and USB to TTL by yourself
6. Other components It is easy to buy directly at Lichuang Mall. Please refer to the BOM for details. You
will also need soldering tools such as electric soldering iron, solder wire, and washing water.
# 0x02 Welding
! [FLASH]
The small button used to enter the burning mode does not need to be soldered. If If you are not soldering, you can use tweezers (the handheld part needs to be insulated) against the two pads and then power on to enter the burning mode. After entering, you can release the tweezers
! [TXRX]
Solder 3 Dupont wires here
# 0x03 wiring
relay The back-end wiring can refer to the picture below
! [Relay wiring reference.png]
# 0x04 After flashing the firmware
and soldering, use Dupont wire to connect the PCB to USB TO TTL. Press and hold the burning button and then power on. The computer is configured for Arduino IDE development. Environment writing code, the code in the attachment is for reference only, please develop it yourself if necessary.
Note that when the controlled electrical appliance is on, pin 4 of the optocoupler used for continuity detection will generate a pulse with a frequency of 100Hz and a pulse width of about 1ms (duty cycle 10%)
! [Untitled.png]
Arduino IDE partial parameter selection :
![Development Board.png]
![FLASH.png]
After the firmware is successfully uploaded, the three DuPont wires can be soldered. At this point, the module production has been completed, and subsequent code updates can be completed via OTA.
# 0x05 Use
the module to automatically connect to the preset wifi after powering on. You can log in to the router backend to view the IP address of ESP8266, and log in to the web page to control it. You can also install WG on the router to remotely control home devices under the 4/5G network