Abstract
The design uses STM32F103C8T6 as the hardware development environment and WIFI communication module as the peripheral chip. The software uses Keil4 as the hardware-driven development environment, and the underlying development language uses the C language. At the application layer, the Android smartphone app APP was designed in the MyEclipse development environment. The collaborative development of software and hardware realizes four functions of WIFI communication, socket switch control, electricity consumption statistics, and timing switch. The design and development of smart sockets make people’s lives more convenient, aiming at realizing the safety of electricity in life, promoting energy conservation and reducing waste of power resources.
Keywords
Introduction
With the development of economic globalization, intelligent manufacturing will gradually be identified as a new development trend of China’s manufacturing industry. At present, smart sockets on the market have WIFI remote control type, infrared remote control type, electricity consumption type, time switch type, temperature and humidity control type, etc., and the functions are relatively simple [1].
In recent years, due to the rapid development of Internet of Things industry in domestic, it has led to the technological innovation and widespread popularization of intelligent products [2]. Intelligent sockets that can connect with WiFi have become the mainstream of this kind of product design nowadays. Most of the designs in China are connected with mobile terminals such as smart phones and tablets through WiFi, so as to realize intelligent control of smart home robots, household appliances and other devices. However, there are still a large number of non-intelligent devices in Chinese households, and it is impossible to use intelligent appliances to replace traditional non-intelligent appliances in a short time. How to use smart phones to control traditional household appliances remotely has not been solved in China. The smart socket developed in this paper not only has the traditional power supply function, but also can control the non-smart household appliances remotely through smart phones.
Solve the embedded development program with a variety of options such as microcontroller, ARM [3]. According to the function to be realized by the smart socket designed this time, the microprocessor must have a variety of peripherals and communication interfaces, and at the same time, it needs to have faster event resilience and speed, and has stronger processing capability and better cost performance [4].
The single-chip microcomputer adopts VLSI technology to integrate random memory RAM, read-only memory ROM, various I/O ports, interrupt systems, timers and other functions. Embedded development is aimed at the intelligent control of objects and the embedded performance and reliable control capabilities closely related to the design object.
Because the ARM core’s product price is lower, and the product cores of different manufacturers are the same, it is very convenient to transplant on different platforms, so the design finally decided to adopt the ARM series. The smart socket designed in this paper is based on the STM32F103x embedded microprocessor and MDK embedded integrated development environment.
The STM32 microcontroller is also featured in the Cortex-M3 core with standard memory images, NVIC and 32-bit CPU [5]. Its control core is STM32F103x chip, and it integrates universal serial bus, controller LAN interface, 7 timers, 2 digital-to-analog converters and 9 communication interfaces.
The design of the smart socket designed in this paper, the smart socket development program applies embedded system application technology, WIFI wireless communication and other technologies [6]. This technology can be applied to the control system of smart homes. The user can use the smart terminal to communicate within the WIFI coverage area, that is, the smart socket in the home room can be controlled, thereby realizing the control of the electrical equipment connected on the smart socket [7].
Smart socket overall design
In order to make up for the shortcomings of the traditional socket, and the lack of the function of the current smart socket, this paper designs a smart socket with complete functions, which belongs to the WIFI type smart socket. When the power supply is started, the chip starts the WIFI communication module to send a wireless signal, and all the smart terminals can be connected to the WIFI, thereby performing data communication with the socket.
After extensive investigation and research, the designed smart socket has the following functions:
WIFI control. By using the WIFI communication module, the intelligent terminal establishes the data communication connection with the hardware development board. Control electrical switch. By using the relay module, the control relay is turned on and off to realize the switching operation of the electrical appliances on the socket. Electricity statistics function. A power metering chip is used, which is used to measure the amount of electricity and current RMS. The Value of electricity used will be displayed on the mobile terminal, which is convenient for the user to know the amount of value of electricity used in real time. Timing function. Timing is set by using a clock chip to set the timing.
According to the above-mentioned functions to be implemented, STM32F103C8T6 is selected as the main control chip. The main control chip is combined with the related circuit, and the code is written to realize the WIFI communication function.
The WIFI module uses the HF-LPT120, which is an ultra-low power embedded WIFI module. The module can smoothly connect to the wireless network by setting Socket, a configuration protocol, configuring a serial device, or by using an HF-LPT120 module, thereby implementing data communication with the intelligent terminal.
This design uses STM32 microcontroller to design the required functions according to the pins of the STM32F103 chip. It includes six main modules: main control module, power module, WIFI communication module, electricity statistics module, clock module and relay control module. Each module is connected to a corresponding function pin of the MCU to perform communication between the module and the chip. The Hardware framework diagram is shown in Fig. 1.
Hardware framework diagram.
Hardware entity.
The clock module uses the chip encapsulated DS1302 chip with clock counting function. The clock module uses the packaged DS1302 chip with clock counting. It can count the hours and minutes, and clear it after cutting off the power. According to the set timing time, the relay is activated to realize the on/off operation.
The chip used in the electricity statistics module is HLW8012, which can measure whether there is effective current passing, identify and count the power, and is widely used in smart home appliances and other applications.
The control module uses the relay to realize the original function of the socket and control the electrical switch.
Hardware entity diagram as shown in Fig. 2. The module description is shown in Table 1.
Serial number description table
The STM32F103 chip and related circuits form the main control module. The chip is a 32-bit microcontroller, which has obvious advantages in internal resources, on-chip peripherals and processing speed. Figure 3 is a schematic diagram of the STM32F103C8T6 chip [8]. The main functions of the pin are shown in Table 2.
STM32 chip pin diagram.
Main pin function introduction table
Power module schematic.
WIFI communication module.
The premise of the normal operation of the microcontroller is that the power supply is stable. At present, these three kinds of power supply are usually used by means of regulated power supply, USB power supply, J-LINK or ST-LINK power supply. The regulated power supply can flexibly select the output voltage and has better adaptability to the voltage requirements of different applications. These three power supply methods are generally selected by using a jumper method [9]. The supply voltage is converted to the voltage required by the chip through the DC-DC conversion chip. The schematic is shown in Fig. 4.
The DC-DC chip uses the ASM1117-3.3 three-terminal regulator chip, which uses a low-dropout regulator tube, which can make the output DC voltage more stable and protect the circuit.
WIFI communication module
The WIFI communication design based on STM32 is an application for embedded WIFI, which realizes WIFI communication between embedded devices and intelligent terminals. In hardware selection, HF-LPT120 low-power small-size series chips are selected. Figure 5 is a physical diagram of the WIFI module used in the design.
The pin usage of the data transmission between the WIFI communication module and the MCU is: the 30th pin of the 5th connection chip, and the 31st pin of the 6th connection chip, for transmitting and receiving communication data. Figure 6 is a schematic diagram of the WIFI module.
Schematic diagram of WIFI communication module.
Schematic diagram of the electricity statistics module.
When the appliance is plugged into the outlet, the outlet power supply begins. The electricity statistics chip starts to collect value of electricity used and starts to display on the mobile terminal to monitor the electricity consumption in real time [10]. The schematic diagram of the electricity statistics module is shown in Fig. 7.
Pin description table
Pin description table
DS1302 pin distribution map.
Clock module schematic.
The clock chip used is the DS1302 chip. The DS1302 package and pinout are designed in a chip package with eight pins, as shown in Fig. 8.
The pin descriptions are shown in Table 3.
The RST pin is reset at a low level, and the high level is working normally. The meaning of the low level can be understood as not counting and not working. The SCLK pin represents the serial clock pin [11].
The pin connection between the clock module and the MCU is: the No. 21 pin of the MCU is connected to the No. 7 on the clock chip, the No. 22 pin of the MCU is connected to the No. 6 on the clock chip, and the No. 25 pin of the MCU is connected to the No. 5 of the clock chip. The schematic diagram of the clock module is shown in Fig. 9.
Relay control module
The function of the relay control module is to control the on/off operation of the electrical appliances on the socket through the relay. The communication between the chip and this module is connected to the 26th pin of the MCU through the No. 2 interface of the relay [12]. The schematic is shown in Fig. 10.
Software function design and development
According to the analysis of the current market demand for smart home appliances and the development trend, the smart socket APP software designed in this experiment aims to realize remote control, so that people can still control the smart socket under long-distance conditions. In addition, this smart socket APP software can record the amount of electricity statistics used to achieve remote timing switch. Therefore, the function to be implemented according to the smart socket APP software is a Wi-Fi-based multifunctional smart socket APP.
The development of the smart socket APP software, the development language used is Java, and the implementation of Android programming in the Eclipse environment. The software design can be roughly divided into: socket switch module design, electricity statistics module design and timing module design. The working environment diagram of the smart socket APP software is shown in Fig. 11.
Introduction to peripherals
Introduction to peripherals
Schematic diagram of the relay control module.
Work environment diagram of smart socket APP software.
Design flow chart.
As a highly integrated chip, STM32F103C8T6 can minimize the occupied PCB space. It also has a built-in cache to help improve overall operational efficiency and reduce the need for memory [13]. At the same time, the powerful storage capacity of the STM32F103C8T6 also reduces the cost, while also ensuring efficient computing efficiency and capability.
Using Keil4 as the hardware development environment, the hardware driver is written according to the functions provided by the hardware, and the functions of WIFI communication, time switch, electricity consumption statistics, and control of electrical appliances are turned off and off. After the program is debugged, it is written into the chip, and finally realizes the implementation of various functions through the intelligent terminal [14]. The main job is to write the program code, compile the program, program the program, debug the program, and output the file in the specified format. The functions implemented by the smart socket set in this paper are three functions of electricity statistics, timing, and control of electrical switches. The following Fig. 12 is the main function flow chart.
The function of collecting electricity value
First, the value of electricity used collection is performed, and the collected the value is stored in the FLASH. When the development board receives the instruction sent by the mobile APP, the uploaded value of electricity used e is displayed on the mobile phone. When receiving the upload value of electricity used command, the value in the FLASH is read. After the timing function is implemented, the variables JDQ and Switch_runF are set, and the high level represents the current, that is, the relay is set to be turned on. When the appliance is used, set JDQ
STM32 series chips use standard peripheral library files. All source files and header files start with “stm32f10x_”, such as stm32f10x_adc.c. Table 4 is displayed in the code area of the KeiluVision 4 IDE.
WIFI module running function
The WIFI module calls four header files: WIFI, IO, delay, and wdg. There are two working modes: AP mode and STA mode.
AP mode settings First set the fixed bit, SSID, channel number, password of the module in the mode, set the address of the module UDP server: 10.10.100.254, port 8000, set the exit AT command format. Set the AT mode code as shown in Code 1.
STA mode setting First, perform STA network parameter query, then set the STA mode, set the address of the TCP server: 192.168.1.101, port number: 5000, set the router, and set the password. Set the STA mode code as shown in Code 2.
APP software structure.
This design uses Wi-Fi technology to achieve control through the mobile APP. The smart socket APP can realize functions such as remote control, timing and electricity consumption statistics, thus realizing automatic control of household appliances. The designed smart socket APP source program generates an apk installation package through the Eclipse development platform, and installs the installation package on the mobile phone, so that it can be used. It uses wireless transmission to achieve control, and it is still more convenient to use according to people’s original living habits. The functional structure of the APP software is shown in Fig. 13.
Realization of electricity statistics function
Electricity statistics is one of the core functions of APP software. It can count the electricity used and has the function of timing switch. The flow chart of the power statistics function of the intelligent socket APP software is shown in Fig. 14.
Electricity statistics chart.
Timing function is realized on the premise that intelligent socket has been successfully connected to Wi-Fi. The design can complete the functions of timing and remote control to turn on or off. The timing control flow chart of the intelligent socket APP software is shown in Fig. 15.
Setting time chart.
The timing control function code of intelligent socket APP software is shown in Code 3.
After the hardware program is written, you need to generate the .hex file from the function code contained in the project file. The connection between the development board and the computer is through the ST-LINK USB interface, which supplies power to the development board and writes files. The written hardware driver is written to the development board to complete the underlying development of the smart socket.
ST-LINK simulator
ST-LINK is a development tool designed to evaluate and develop the STM8 series and STM32 series. The STM32 series of chips used in this design connects the SWD interface to the ST-LINK V2. The ST-LINK V2 is connected to the computer via Hi-Speed USB 2.0. It supports all STM32 series microcontrollers with JTAG/SWD [15]. The ST-LINK V2 entity diagram and interface are shown in Fig. 16.
Emulator entity and pins.
ST-LINK V2 JTAG/SWD pin standard interface arrangement diagram, as shown in Fig. 17.
Interface pin annotation diagram.
The emulator is connected to the SWD interface on the MCU for debugging. Figure 18 is the interface schematic of the pin [16].
Interface schematic.
APP software interface.
Wi-Fi connection interface.
The connection between the ST-LINK V2 interface and the development board SWD interface is: SWD interface 1, 2, 3, and 4 interfaces are respectively connected to the 7 or 8, 4, 2, 5 or 6 interfaces on the emulator interface, each pair of interfaces use the DuPont line to connect between them. The SWD interface SWD is connected to the 34th pin of the MCU, and the SWC is connected to the 37th pin of the MCU [17].
According to the experimental scheme, the smart socket APP software with Wi-Fi remote control function was successfully designed. The software interface is shown in Fig. 19. After connecting the smart socket APP software to Wi-Fi, enter the control interface, and the Wi-Fi connection interface is shown in Fig. 20.
After connecting with the smart socket through the APP software, test whether the smart socket configuration function test passes according to the switch of the light on the development board. The test results are shown in Figs 21 and 22.
Smart socket off state.
Timing on state of smart socket.
There are two types of timing functions: timing on and timing off. Turn the hands in the virtual clock shown in Fig. 19 to select the time. Select the check box after the “Set Timed On Time” tab to complete the timed open operation. The check box after the “Set Timed Off Time” tab is selected to complete the timed off operation.
After testing, it can be known that after connecting the electrical appliances, the electricity consumption will be counted every two seconds. When the power is connected to the electrical outlet, the electricity consumption is collected and the initial value is “0000”. The collected electricity consumption value can be seen from Fig. 19.
The smart socket realizes four functions of WIFI communication, timing switch, electricity consumption statistics, and control of electrical appliances. The hardware function design of each module is completed by selecting the core chip and communication technology. Through the development of the software APP function, the functions of data collection, storage, reception, processing, and transmission are completed, and the remote data communication to the smart socket is effectively realized.
Footnotes
Acknowledgments
Design and realization of WiFi based adhoc smart power plug, the Science and Technology Research Project of Department of Science and Technology of Henan (Code: 172102210554); Development of ARM based embedded industrial smart real-time monitoring system, the Key University Scientific Research Project of Henan (Code: 15A520110).
