1 Introduction
With the acceleration of the pace of life and the improvement of living standards, people have put forward higher requirements for the safety, intelligence, comfort and convenience of modern homes. Smart home control systems are new things that have emerged to meet this demand. They are developing in the direction of intelligence, remoteness, miniaturization and low cost. Nowadays, mobile phones are very popular. How can ordinary people remotely control their home electrical appliances and remotely check the status of equipment or security systems through mobile phones with only a small amount of investment? At the same time, once a safety accident such as gas leakage, fire, theft, etc. occurs at home, the alarm can be immediately notified and handled in time. For this reason, this paper proposes a smart home remote monitoring system based on SMS and Atmega128.
2 System structure and working principle
The smart home remote monitoring system designed in this paper consists of CPU module, SMS transceiver module, power module, clock module, LCD display module, keyboard module, driver module, wireless transceiver module, detection module and other modules, as shown in Figure 1. The working principle of the system is as follows: the user sends the control or query command to the SMS transceiver module in the form of SMS through the GSM network through the mobile phone, and the CPU reads the SMS into the memory through the serial port, and then responds to the command after analysis and processing, and controls the opening or closing of the corresponding electrical appliances, thus realizing the remote control of home appliances. The CPU regularly detects the signals of smoke sensors, CO sensors, and access control systems. Once there is a gas leak, fire, theft or other dangerous situations at home, the system immediately cuts off the power supply, buzzer alarms and sends alarm SMS to the designated mobile phone, thus realizing remote monitoring of the home. In order to achieve a more humanized design, when the user is at home, he can control the on and off of each home appliance through a handheld wireless remote control, and set the authorized mobile phone number, authority and precise time of the system through the built-in small keyboard. The LCD is used to display the status of each appliance and the status of each sensor in real time.
Figure 1 System structure diagram
3 Hardware System Design
The CPU uses Atmega128 microcontroller, which is an 8-bit low-power CMOS microprocessor based on AVR RISC structure, with high cost performance, low power consumption and high reliability. The SMS transceiver module uses Saro310 GSM Modem from Xiamen Sangrong Company. The sensor uses SS-168 smoke detection alarm and HD-111 household CO detection alarm from Hong Kong Jiayong Company. They output switch signals when detecting dangerous signals and can send alarm signals to the CPU in a timely and accurate manner. The LCD display module uses LCD12864 with Chinese character LCD display. It has its own Chinese character library. You only need to query the Chinese character library table to realize the Chinese display of LCD. It occupies few CPU pins and only needs three pins to complete communication and control.
Figure 2 Schematic diagram of the main modules of the system.
The keyboard module uses a 4 × 4 small keyboard. The switch drive module realizes the control of weak current over strong current. Because there are high-power electrical appliances in this system, the current will be large when starting, which may reach 10A, so a 2JB0.5-1 solid-state relay is used. The clock module uses the DS1302 clock chip to provide a real-time clock for the CPU. It uses serial data transmission, can provide a programmable charging function for the power-off protection power supply, and can turn off the charging function. The programming is simple and the power consumption is small. The wireless transceiver module uses the superheterodyne two-way wireless receiving module JL-RT01A. The power module introduces 220V AC power from the plug, and after the 220V/36V/12V transformer steps down, the rectifier bridge rectifies, the secondary capacitor filters, and the three-terminal voltage regulator chips 78L05 and 78L24 stabilize the voltage, it provides 5V and 24V power supply for the core board and the interface driver module respectively. [page]
Figure 3 Main program flow chart.
4 Software System Design
The Atmega 128 chip has rich integrated instruction functions and abundant memory and other resources. In order to improve programming efficiency, code readability, portability and maintainability, this system uses C language to develop system software.
4.1 Main program flow
After the system is powered on, it first initializes the underlying hardware (including LCD devices, serial port parameters, etc.) and system I/O, and then sends the ATE command to the SMS module through the RS-232 port to query whether the SMS module is working properly. If a response is received, the AT commands such as "AT + CMG F", "AT + C NMI", "AT + CSCA" are sent in sequence (refer to the AT command set) to set or obtain relevant parameters and complete SMS preprocessing. Then it enters the loop waiting state, periodically queries whether the SMS module has received new SMS, detects the signal input of each sensor and keyboard operation, etc. If a new SMS is found, it is determined whether it comes from an authorized mobile phone. If so, after verifying the authority of the mobile phone number, the SMS is analyzed and responded according to the specific command (see Table 1-3). Once an abnormality is detected in the smoke sensor, CO sensor, etc., the power supply of the main electrical appliances is immediately cut off, an alarm signal is output, and a SMS is sent to the designated mobile phone.
4.2 GSM Short Message Design
4.2.1 SMS sending and receiving mode selection
The Saro 310 GSM Modem module uses the AT command set to control the sending and receiving of SMS messages. It supports two SMS sending and receiving modes: TEXT and PDU.
The former does not support non-ASCII characters and cannot send and receive Chinese text messages, while the latter supports a variety of different encoding formats. Therefore, this system uses the PDU mode to send and receive text messages. The Chinese characters on the mobile phone are displayed using the national standard code. The CPU needs to convert the UCS 2 code into the national standard code first for output.
The conversion between UCS2 code and national standard code cannot be completed by algorithm, but can only be achieved by table lookup. [page]
4.2.2 SMS command format (control protocol)
SMS commands are divided into sensor query commands, basic control commands, and advanced management commands. The formats and descriptions of various commands are shown in Table 1, Table 2, and Table 3 respectively.
Table 1 Sensor query commands
Table 2 Basic control commands
Table 3 Advanced management commands
For example, to turn on the light:
uint8 ExecuteSMS Cmd(void) // execute command
{ case SMS_DD :RELAY_PORT|=BIT(RELAY_DD
) ; // Turn on the light
DvcSt t|=0x02; break; // The command code of the light is 0000 0010B
}
The SMS command is stored in the data buffer in the form of U nicode.
4.2.3 SMS command analysis
When the system receives the SMS command, it will match and scan from sensor query, basic command, and advanced management command in sequence. The scanning code is as follows:
wh ile (- - i &&! (mh = strstr (UART0 _RxBu f,DefDetCmd[i])));
if( ! i ) // If it is not a sensor command
wh ile (- - j&&! (mh = strstr (UART 0 _RxBu f,DefBasicCmd[j])));
if( ! j ) // If it is not a basic command
wh ile (- - k&&! (mh = strstr (UART 0 _RxBu f,DefAdvanceCmd[k])); [page]
Among them, UART 0 _ R x B uf points to the receive data buffer, DefDetCmd is the sensor command predefined in the system, DefBasicCmd is the basic control command, and DefAdvanceCmd is the advanced management command. After the scan is completed, different types of commands are further refined and processed, and the corresponding command numbers are returned. The system completes different operations according to different command numbers.
4.2.4 Send SMS
When the system receives a text message command with "?", it will send a report text message to the authorized number after completing the corresponding operation. The text message format is defined as follows:
typedef struct ShortMessage // short message structure
{uint8 CSCA[19]; // SMS center number
uint8 FirstOctet[3];
uint8 TP_MR[3]; // message reference value
uint8 RecvPhoneNo[19]; // The other party's number field
ui n t8 TP_PID[3] ; // protocol identifier
ui nt8 TP_DCS[3] ; // encoding method
uin t8 TP_VP[3]; // validity period
uint8 TP_UDL[3]; // User data length
uint8 TP_UD[255]; //Message content
}SHORTMESSAGE;
When the system is powered on, the short message preprocessing is performed first, the constants in the message structure are assigned and stored in the Flash, and the message structure is completed when the message is to be sent. The sending process is (: 1) Send the "AT+CMGS" command to the SMS module (; 2) After the SMS module responds, send the short message structure string (; 3) Wait for the sending to be completed.
4.2.5 SMS security design
In order to improve the security of the system, this system has set up an authorized number library. Only the commands sent to the system by the authorized mobile phones in the authorized number library are valid. When the system receives a new SMS, it first determines whether the number is included in the authorized number library. If the SMS comes from an unauthorized mobile phone, the information will be deleted. After executing the command sent by the authorized number, the system will send information about the command execution to the user through the SMS module. The authorized number library can be modified. The mobile phone that manages the number can send SMS commands to add unfamiliar numbers to the authorized number library or delete authorized numbers. It can also add and delete authorized numbers through the keyboard.
5 Physical Testing
The actual test results of the system are shown in Figure 4. By authorizing the mobile phone to send a text message "Turn on the light?" to the system, the system completes the analysis of the text message command, turns on the light, displays the current operation on the LCD, and replies with a text message as required.
Figure 4 LCD control command display and mobile phone query command display.
6 Conclusion
The smart home remote monitoring system designed in this paper only needs to make a few adjustments to the wiring of the original power supply, security and other systems, and can remotely control home appliances through a mobile phone. The system is highly practical, simple to operate, low cost and cost-effective. It can also be easily extended to many fields such as outdoor billboard monitoring, reservoir water level monitoring, elevator safety operation monitoring, etc.
Previous article:Design of MTURTU radio telemetry system based on AVR microcontroller and MODEM chip
Next article:Zigbee sensor node hardware design based on single chip microcomputer
- Popular Resources
- Popular amplifiers
- ARM Cortex-M4+Wi-Fi MCU Application Guide (Embedded Technology and Application Series) (Guo Shujun)
- Intelligent Optimization Algorithm and Its Application (Wang Ling)
- Introduction to Artificial Intelligence and Robotics (Murphy)
- Chip Manufacturing: A Practical Tutorial on Semiconductor Process Technology (Sixth Edition)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- EEWORLD University - Learn C language from scratch
- [ESP32-S2-Kaluga-1 Review] 5. Use LGVL to create a low-level interface?
- Why is the voltage ringing spike of MOSFET different in boost and buck mode?
- The circuit for discharging the PFC output capacitor is shown in Figure 2.
- Basic syntax of Verilog HDL
- Found a method to import Altium Designer into SIwave
- Thanks to okhxyyo for searching and fish001 for sharing
- Please advise, is it easy to pass the postgraduate examination and graduate, and how useful is the degree certificate?
- About the LAUNCHXL-F28379D Development Kit
- Let me try this feature