I am in the software direction, not an electronic hardware major, just an amateur. Therefore, you may not know a lot of basic hardware knowledge. If there is anything wrong with the circuit diagram, I hope you will enlighten me and thank you.
This project is improved from: [Under Second Test] Smart WiFi IoT Socket https://oshwhub.com/liyichuangeda/ji-yu-ESP12-de-shuang-lu-wu-xian-wu-lian-wang-kai- guan
Thanks to the original author @misaka0x1BF52.
1. Replace the relay with a magnetic latching relay: HF3F-L-05-1HL1T (standard polarity/1 set of normally open/single coil/5V/4 pins). The advantage is that it saves power and only needs to be started or closed at the moment of the relay. power, no power is needed to maintain the status in the future. Therefore, this socket has excellent power-saving performance, the overall power consumption is only about 0.65W, and long-term use will not cause the relay coil to heat up. At the same time, when the socket is powered off and on again, the magnetic latching relay will not engage or release additionally (which cannot be avoided with ordinary relays), and the socket will maintain the state before the power was lost.
2. Using ESP12S (ESP12F can also be used), the LED display and relay control are separated, and the LED can display more states. The original solution used ESP01S, because there is no extra IO port for LED display, and the LED and relay can only share the IO2 port. Moreover, the FLASH capacity of ESP01S is only 1M, which is too small. The capacity of ESP12S is 4M, making OTA online firmware upgrade possible.
3. A new board was drawn for double-sided direct plug installation of ESP12S. After welding the ESP01S in the original plan, the pins will occupy the space at the bottom of the male-female integrated socket, and the socket cannot be laid flat. The ESP12S project for direct plug-in installation is located at: https://oshwhub.com/oldfox126/esp12s-li-zhuang-mo-kuai. So this project actually requires 2 PCBs to be printed (the thickness of both PCBs is 1mm).
4. The overall socket has been moved upward by about 0.5mm. In the original plan, the socket easily occupied the lower relay space.
5. The available space of this socket housing is very small, and the size of the power module must be small enough to fit in. In the comments, brothers often say that the module "AC220V TO DC5V switching power supply module" has poor performance indicators and is very pitiful. But I haven't found a decently sized ( with better performance parameters ) replacement yet .
6. In the comment area, someone asked about the maximum power supported by this socket. I don’t know how to test the maximum power, but judging from the component parameters, it is 250V10A .
7. If during the PCB layout process, the manufacturer prompts: The middle milling slot connection position is too small and the board may break, etc., please reply: I am aware of and accept the risks caused by this reason. Please directly produce according to the Gerber file. Thanks!
1. Instead of using the Blinker library, use the MQTT solution. The main reason is that the Blinker APP can only create 5 devices, which is not enough for me.
2. The programming environment has been changed from Arduino to vscode+PlatformIO+C++. The programming environment of vscode is very friendly. As for the Arduino IDE... I won’t comment anymore.
3. In fact, the software used microPython in the early stage (it is indeed simpler), but later I found that microPython still had too few resources. Halfway through the project, I found that I couldn't find the code for smartConfig, so I had to overthrow it and start over with C++.
A brother commented under the project: " It is best to go to the cloud or not only use it on the LAN ", so I will explain the MQTT solution a little bit, see the model diagram below.
As can be seen from the figure, this solution needs to be supported by an MQTT server, so it is originally on the cloud and can be used as long as there is WIFI, not limited to LAN.
Here comes the best part: the MQTT protocol itself is open source, and there are many free MQTT servers on the Internet. Baidu keywords: free MQTT server , public MQTT server.
We can get one without limiting the number of devices and usage period without spending a penny. Cloud server, I believe this is an advantage that many third-party private protocols cannot match.
There are often very cheap smart sockets for sale on Xianyu. I asked the seller why they are so cheap? The answer is that when the manufacturer goes bankrupt, the APP is disabled, and the socket can no longer be controlled, the smart socket is basically useless and can only be used as an ordinary socket .
There is no such worry at all for open source MQTT services. Is the MQTT server down? I'll just change it. The MQTT server can originally be replaced through web configuration and APP settings.
Therefore, the MQTT solution is my preferred IoT control solution.
1. Supports web page network configuration
2. Supports WeChat scan code configuration
3. Supports network time synchronization NTP
4. Supports MQTT , which helps to have a more thorough understanding of the working mechanism of the Internet of Things. Use the switch, countdown timer, timer, etc. on the MQTT mobile APP to turn on or off the socket.
5. The timer program is implemented locally in the socket, not in the cloud . As long as the parameters are submitted and saved, even if the network is disconnected later, the socket can still be turned on or off regularly. Therefore, it is possible to use this socket to physically restart the optical modem or router.
6. Support OTA online firmware upgrade , and the firmware can be upgraded through the network. No more painful removal of the board to re-flash the firmware.
7. Supports LittleFS file system and can save various parameters when power is turned off. Even if the socket is powered off and restarted, the original parameters are still there.
1. The socket casing (including the 220V10A male and female integrated socket inside) was originally purchased here -> but the owner of this store is too lazy and is often not online. Later -> Go to Alibaba and buy more than 2 pieces at a time , which is cheaper.
2. AC220V TO DC5V switching power supply module. I have bought both of the 2 links on the right ( note: you need to buy the 5V one with pins ), you can use -> Link 1 Link 2
3. Side buttons ( note: you need to buy H=5MM ) -> Purchase link
4. ESP-12S module You need to purchase an ordinary ESP12S, and then make the board and weld it yourself: [Verified] ESP12S direct plug-in installation module https://oshwhub.com/oldfox126/esp12s-li-zhuang-mo-kuai
5. Magnetic latching relay K1 ( note: you need to buy HF3F-L-05-1HL1T (10A4 pins) ) -> Purchase link
6. Magnetic latching relay driver chip MD7620A SOT23-6 -> Purchase link
7. In addition to this , I basically bought other components (including resistors, capacitors, AMS1117, ESP12S, light-emitting diodes, LEDs, etc.) from Uxin Electronics -> Uxin Electronics Taobao store
8. ESP8266 development test rack/burner (only required for beginners) , I bought this one -> Purchase link
1. First flash the firmware of ESP12S https://oshwhub.com/article/ci-bao-chi-WIFIzhi-neng-cha-zuo-ruan-jian-gong-cheng-dao-ru-VSCODE-yi-ji- bian-yi-shuo-ming
2. Configure the network for ESP12S and set MQTT parameters, etc. https://oshwhub.com/article/ci-bao-chi-WIFIzhi-neng-cha-zuo-ruan-jian-diao-shi-shuo-ming
3. Install MQTT APP on your mobile phone and set server and other parameters. https://oshwhub.com/article/ci-bao-chi-WIFIzhi-neng-cha-zuo-pei-tao-de-shou-ji-APPan-zhuang-ji-she-zhi-shuo-ming
4. Solder ESP12S to the module, solder on the PCB_socket body , and install the components. Solder the ESP12S module to the main PCB.
It is enough to solder to this level. Do not solder the male-female integrated socket (the part circled in red) yet. In addition, at the position indicated by the blue arrow, weld 2 male Dupont wires to 5V (red)/GND (black) respectively.
5. Take power from the ESP8266 development test rack/writer , plug in 2 female Dupont wires to 5V (red)/GND (black) respectively, and plug in the 2 male connectors from the previous step.
Turn on the power and test to see if the MQTT APP can display the beating time normally (it means that the ESP12S module is welded well, the WIFI connection is normal, and the MQTT server is connected);
whether the switch responds normally (the LED will turn on and off with the switch);
use a multimeter Measure whether the output of the relay can be controlled by the switch of MQTT APP and can be turned on and off normally.
6. After the above tests are passed, it means that the socket software and hardware function normally. You can turn off the power and solder off the two DuPont wires and solder the male and female integrated socket.
7. Everything is welded and ready for shelling. It is recommended to use cobbler glue between the plastic shell and the back cover -> the link is very strong and does not dry out too quickly like 502.
8. The installed finished product is as follows. You have to wait 24 hours for the glue to dry before you can use it.
(Software and hardware installation completed)
Thank you to Mr. @工科nansun on Station B ( https://space.bilibili.com/43584648 ). I am interested in electronic hardware but never know how to get started. After watching his video, he suggested starting with a microcontroller project.
Thanks to @江科大automatic association on station B ( https://space.bilibili.com/383400717 ). His 51 microcontroller tutorial is clear, easy to understand, and can be a god. Later, I could no longer find instructional videos of such good quality.
Thanks to @Electronic Studio ( https://space.bilibili.com/414349573 ) on Station B, I followed his tutorials and learned to use Lichuang EDA.
Thanks again to the boss of this site @MISaka0x1BF52, I learned from his project ([Under Second Test] Smart WiFi IoT Socket https://oshwhub.com/liyichuangeda/ji-yu-ESP12-de-shuang- lu-wu-xian-wu-lian-wang-kai-guan ). After completing this project, I feel that I have basically gotten started with electronic hardware.
Finally, I would like to thank Jialichuang yyds, who has to help me make PCB boards every month.
2022/7/19
1. Based on feedback from the comment area, the spacing of the milled grooves in the middle of the PCB has been changed to 0.8mm.
2022/8/19
1. The LED lighting logic has been redesigned. The previous program would cause the LED to stay on due to some unknown reasons. It is expected that the LED will only be on for a maximum of 100 seconds (to reduce light pollution).
2022/6/27
1. Fixed a bug in which the relay does not close normally when the online upgrade is completed and restarted. In normal conditions, power failure does not affect the opening and closing status of the relay.
2022/6/26
1. Fixed a bug where using a timer to turn on the socket would cause the LED to stay on. Under normal conditions, the LED would only stay on for a maximum of 100 seconds (to reduce light pollution).
2022/6/24
1. Enhanced the ability to reconnect after WIFI is disconnected. When the MQTT service connection is interrupted, the WIFI will be reconnected and the network will be initialized.
2. Fixed a logical error in web configuration: after changing the WIFI SSID, the device restarts directly, causing the WIFI SSID to not be saved successfully.
2022/6/20
1. Replaced the timeLIB time library, because the library has a potential BUG. When running the hour() function (getting the current hour value), there is a certain probability that the software will crash and the hardware will restart.
2. Changed the WIFI connection strategy. The WIFI connection should now be more stable than before. If the WIFI cannot be connected, or the Baidu website cannot be accessed , or the network synchronization NTP fails, the WIFI will try to reconnect.
3. Fixed the problem of incorrect return value type of WIFI initialization function.
All reference designs on this site are sourced from major semiconductor manufacturers or collected online for learning and research. The copyright belongs to the semiconductor manufacturer or the original author. If you believe that the reference design of this site infringes upon your relevant rights and interests, please send us a rights notice. As a neutral platform service provider, we will take measures to delete the relevant content in accordance with relevant laws after receiving the relevant notice from the rights holder. Please send relevant notifications to email: bbs_service@eeworld.com.cn.
It is your responsibility to test the circuit yourself and determine its suitability for you. EEWorld will not be liable for direct, indirect, special, incidental, consequential or punitive damages arising from any cause or anything connected to any reference design used.
Supported by EEWorld Datasheet