A smart home power control system based on microcontroller

Publisher:信息巫师Latest update time:2015-04-23 Source: 21ic Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
 In recent years, the Internet of Things technology has developed rapidly, and the information level of the whole society has been continuously improved. Smart home is one of the main applications of the Internet of Things. It has become a hot research field and the development direction of future home life. It can provide users with a comfortable and convenient living environment. However, since most related products on the market are expensive, the penetration rate is still low. Previous exploration and development often stayed on the transformation of electrical equipment itself. This attempt made smart home products a luxury. This article introduces an electric energy control system. As an important part of smart home, it realizes remote automatic control function without changing the original electrical equipment.

1 System Structure

The power control system consists of a remote control and a socket node, and its working principle is shown in Figure 1. When the user is at home, the socket is controlled by the remote control in a radio frequency manner. After the socket node receives the signal, the microcontroller decodes it and, based on the result, powers on and off the socket with a specific number, so that the connected electrical appliances are started or turned off. When the user is far away from his residence, he can send a text message to the remote control through the GSM network. After the microcontroller reads the information, it transmits the information to the indoor wireless network through the radio frequency chip, so that the socket at the corresponding address is controlled. It can be seen that the remote control belongs to the gateway node in the entire smart home system. On the one hand, it forms an indoor radio frequency local area network with the socket node, and on the other hand, it is connected to the GSM network, extending the remote control distance. The internal structure of the remote control is shown in Figure 2, including temperature and humidity detection circuit, clock module, nRF905 radio frequency transceiver module, GSM module and other functional circuits, all of which are connected to the control core LM3S811. The microcontroller adopts the ARM Coaex-M3 architecture. Relying on the high-density Thumb-2 instruction set, the memory overhead is greatly reduced and the operating system porting is also more convenient.

Figure 1 Working principle of remote control socket

Figure 2 Remote control structure diagram

The socket node mainly realizes RF communication with the remote control and on/off control of the relay. Its structural block diagram is shown in Figure 3. The smoke sensor in the socket is used to prevent fire hazards. Once smoke or flammable gas is detected, the corresponding relay on the socket will be disconnected and report to the remote control through the RF transceiver module. After the remote control receives the information, it will promptly remind the user to take corresponding measures through the SMS function of the GSM module to prevent the occurrence of danger or further expansion of property losses. Due to the small workload on the socket end, considering both cost and performance, this system uses the STC12C5620AD microcontroller as the main control chip on the socket end.

Figure 3 Socket node structure diagram

2 Hardware Circuit Design

2.1 Temperature and humidity detection circuit

This system uses temperature sensor LM35 and humidity measurement module CHM-02 for environmental monitoring. The voltage output of LM35 is linearly related to Celsius temperature, and can achieve a measurement accuracy of ±1/4℃ at room temperature without calibration. The CHM-02 module can detect humidity in the range of 20~95%RH at 0~70℃, and the measurement accuracy at room temperature is 5%RH. The interface diagram of the temperature and humidity sensor and MCU is shown in Figure 4. Since the analog signals output by the two sensors are within the detection range of the A/D sampling circuit on the MCU chip, the output ends of the two sensors are directly connected to the two ADC pins of the MCU. The use of analog sensors not only makes full use of the on-chip resources of the controller, but also improves the utilization rate of subroutines.

Figure 4 Schematic diagram of the interface between the temperature and humidity sensor and the MCU

2.2 Smoke Detection Circuit

The smoke sensor MQ-2 is based on the electrochemical properties of SnO: and has good detection sensitivity for combustible gases and smoke. The schematic diagram of the smoke detection circuit is shown in Figure 5. Before normal operation, MQ.2 needs to energize and preheat the Hh poles of the internal heating wire. In order to prevent the internal signal line temperature from being too high due to excessive heating current, the heating wire is connected in series with a 100 Ω resistor. When the smoke or combustible gas in the environment exceeds the warning threshold, the conductivity between the AB poles of the sensor increases rapidly, and the voltage obtained by the load resistor m in series with it also increases accordingly. After the voltage signal is amplified by the low-power op amp TLC27M2, an analog output corresponding to the smoke or combustible gas concentration is obtained, which is finally connected to the ADC module of the controller for quantization. [page]

Figure 5 Schematic diagram of smoke detection circuit

2.3 Clock Module

In addition to displaying the system time, the clock module can also time the power on and off of a single socket. The schematic diagram of the clock circuit is shown in Figure 6. The DS1302 communicates with the MCU in serial mode. To ensure the stability of signal transmission, the interface has been pulled up. The chip is powered by dual power supplies. When the main power supply is working normally, the backup power supply can be charged with a trickle current; when the power is off, the backup power supply is started to avoid clock stagnation caused by sudden power outages. Considering the convenience of use, the remote control is powered by a lithium battery. The main power pin VCC2 of the DS1302 is connected to the 3.3 V output of the integrated regulator, while the backup power pin VCC1 is connected in series with a 4700 μF capacitor, and the two power pins are isolated by a diode. Since the chip consumes very little power, the discharge of the capacitor can temporarily maintain the operation of the chip during the battery replacement process.

Figure 6 Clock circuit schematic

2.4 RF transceiver module nRF905

The RF transceiver module is the bridge connecting the socket and the remote control. The nRF905 integrated transceiver can be configured and used in three ISM bands with very low power consumption. All nodes in this system are set to work in the 433 MHz band. The schematic diagram of the RF transceiver circuit is shown in Figure 7. The SMA interface is used to connect a single-ended antenna with a characteristic impedance of 50 Ω, which is conducive to the omnidirectional radiation of the signal. The single-ended antenna is also called an unbalanced antenna. Its main reference point is the signal ground, and the antenna interface of the nRF905 (pins ANT1 and ANT2) is a differential RF output port. In order to maintain signal balance and ensure impedance matching of the two ports, a balun circuit is added between the two to adjust the characteristics of the chip output end.

Figure 7 RF transceiver circuit
 

2.5 GSM Communication Module

Combining the short-range RF network with GSM technology not only takes advantage of the flexible configuration of the short-range RF network, but also takes advantage of the communication distance of GSM technology. The core of the GSM communication circuit is the SIM300 module, and its peripheral circuit is shown in Figure 8.

Figure 8 GSM communication circuit schematic

Schematic diagram SIM300 communicates with MCU through the serial port, and the 22 Ω resistor connected in series between the module and the SIM card is used for impedance matching. To ensure the transmission quality of the signal, the SIM card data line is pulled up, and the SMF05C type electrostatic suppressor connected in parallel with the pin is used for electrostatic protection. The 100 μF tantalum capacitor and 1 μF ceramic capacitor connected in parallel between the power supply and the ground are used to remove low-frequency burrs, and to a certain extent, take into account the high-frequency characteristics. Pressing the button S1 will lower the potential of the PWRKEY pin for about 2 s, which can complete the power-on and power-off of the module. The current state is indicated by the light-emitting diode connected in series with the VDD_EXT pin. In order to facilitate program control, a triode switch circuit is added on the basis of the original button. When the module works abnormally, the state of the PWR port can be rewritten by software to achieve automatic reset of SIM300.

3 Software Design

The remote control and the socket are both nodes in the entire RF wireless network, but the difference in hardware structure determines the difference in their functions and status, and also makes the two different in software design. [page]

3.1 Remote Control Node Programming

The remote control is the control core of the system and the link between the user and the socket. Therefore, there are many concurrent modules in the program and the tasks are heavy. Considering that the ARM processor used in the remote control can provide comprehensive support for the operating system, the use of the μC/OS-Ⅱ operating system to schedule multiple tasks in the node can effectively ensure the real-time and stability of the system and is also conducive to the expansion of functions. Before the operating system is transplanted, the tasks need to be divided, and each function corresponds to a system task. At the same time, the problem of frequent scheduling caused by excessive division should be avoided. The program flow of the remote control node is shown in Figure 9, which contains 7 tasks. The tasks are synchronized and communicated through semaphores, message queues, message mailboxes, etc. From the user's point of view, these tasks are executed concurrently.

Figure 9 Remote control node program flow chart

The priority of the key scanning task is the highest among all user tasks. The key values ​​entered by the user are read through the interrupt method, and the data is stored in the message mailbox KeyMbox. If the number keys 1-6 are pressed, the RF sending task is notified to process; if the clock setting button is pressed, the clock is adjusted or the timer is set. The clock timing task is used to obtain the clock output value of DS1302. After the timing time is reached, a message is sent to notify the RF sending task to process, and it is automatically suspended after completion. The RF sending task is to send the power on and off control signal to the corresponding numbered socket in the RF mode according to the control code obtained in other tasks, and then wait for the socket end to return the action information. If there is no feedback after the timeout, it will be resent once, and the task will be suspended after resending 3 times. The danger alarm task needs to undergo the same frequency carrier detection and address matching confirmation before it starts to receive the RF signal, and then send the information to the mailbox. After decoding and confirming the danger alarm mark, it will notify the user in the form of a short message through the GSM module. The SMS receiving task is responsible for receiving user text messages and storing them in the message mailbox GSMMbox. Through the AT command "AT+CMGR=I", only the short message with serial number 1 is read each time. After successfully extracting the control code (including the socket ID number and the switch action code), the message is deleted and the message is transmitted to the RF task. The environmental monitoring task is responsible for cyclic sampling of indoor temperature and humidity information. Although the linearity of the temperature sensor is good, the external environment has a greater impact on the humidity sensor, and its output voltage value needs to be piecewise linearized. The data is stored in the message queue, and the final result is the arithmetic mean of the three measured values. The LCD display task has the lowest priority. After the above tasks are completed, it is responsible for displaying the final status of each socket, clock information, and indoor temperature and humidity measurement results.

3.2 Socket Node Programming

The program flow of the socket node is shown in Figure 10, where the most important work is to realize the reception and transmission of RF signals. When there is no smoke alarm, nRF905 enters the receiving mode and listens to the channel at the same time; if the same frequency carrier is detected and the data packet address is valid, the reception is started; when the CRC check result is correct, the hardware will automatically remove the preamble, check code and address code of the data packet, and notify the MCU that the data is ready, and then the MCU reads the received information through the SPI serial bus.

Figure 10 Socket node program flow chart

The transmission of RF signals is essentially the reverse process of reception. When nRF905 enters standby mode, the MCU transmits the address and data information to the transmission register of the RF chip, and starts the chip to enter the RF transmission mode. Then the hardware on the chip automatically completes the data packaging, encoding, modulation and transmission tasks. After a frame of data is sent, the RF chip enters standby mode and waits for the next activation. Each reception or transmission process of the RF circuit is accompanied by the on or off action of the relay. Under default conditions, the smoke sensor is enabled. In order to prevent users from smoking indoors and causing system misjudgment, the smoke detection function can also be set to disabled.

4 Testing and Analysis

In the house shown in Figure 11, a field test was conducted. Six sockets and one remote control were placed in seven areas, A to G. In order to evaluate the anti-interference ability of the system, two interference sources with frequencies of 432 MHz and 434 MHz were placed at the junction of each area. The position of the remote control was changed, and each of the six sockets was remotely controlled 200 times, and the feedback signal from the socket was recorded. If an error message was returned or no feedback was given, it was recorded as a packet loss.

Figure 11 Network node distribution diagram at the test site

The results show that the average bit error rate of the remote control in areas C and E is slightly higher than that in other areas; when the remote control is in area G, the average bit error rate is the lowest and the effect is the best.

5 Conclusion

This system realizes intelligent wireless control of household sockets. Without changing the internal structure of the original household appliances, users can control the power-on and power-off status of the sockets through radio frequency, SMS, timing, etc. When a fire or combustible gas leak occurs indoors, the socket can automatically cut off the power. The entire system has no special requirements for the control object and has strong adaptability. It is a cheap smart home solution.

Reference address:A smart home power control system based on microcontroller

Previous article:Transplantation of μC/OS-Ⅱ on ARM Series MCU S3C44B0x
Next article:MiniGUI transplantation based on OMAP5912 development board

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号