Design and implementation of home alarm system based on ATmega128 and GSM

Publisher:谁与争锋1Latest update time:2011-04-15 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

introduction

With the development of electronic technology, the anti-theft alarm system has evolved from the original simplification and localization to intelligence and integration. At present, the common communication methods of the anti-theft alarm system on the market include fixed-line dial-up and broadband network. However, the alarm implemented by fixed-line dial-up is easy to be damaged and may not be able to alarm when in a call state. Broadband network also faces the risk of line cut-off and is not easy to popularize.

This article proposes a smart home alarm system that uses the reliable and mature GSM mobile network to achieve remote alarm and monitoring in the most intuitive Chinese short message or phone form to achieve security monitoring of the home environment. It uses infrared sensors for detection and is equipped with smoke sensors and gas leak sensors to achieve fire prevention and gas leak prevention. The security system with GSM network function allows users to arm, disarm or query the security system through text messages no matter where they are.

System composition and main functions

The home burglar alarm system mainly consists of a GSM network module, an infrared sensor, a gas leak sensor, a smoke sensor, an ATmega128 microcontroller, an audible and visual alarm, and a Flash memory. The system hardware structure is shown in Figure 1.

Figure 1 System hardware structure diagram

The front-end sensors of the system mainly include anti-theft, fire prevention and gas leakage prevention sensors. They are selected and installed in appropriate places according to needs to collect illegal intrusion and danger signals and transmit them to the single-chip microcomputer; the single-chip microcomputer is responsible for receiving and processing sensor signals to determine whether there is any danger. The single-chip microcomputer continuously detects various sensor signals. If a high level is detected, the system controls the GSM network module to realize short message alarm, and sends the alarm information to the user's mobile phone through the GSM service network. At the same time, the sound and light alarm is activated to send the corresponding alarm signal as needed. If the community network has been realized, the alarm information will also be sent to the community security office of the network center; the household owner can also turn on the *microphone on the host by sending a text message to further confirm whether there is any danger at home. This system can effectively achieve the purpose of anti-theft and alarm.

System hardware design

ATmega128 Functional Features Description

This system uses Atmel's AVR microcontroller ATmega128 as the control core. ATmega128 is an 8-bit low-power CMOS microprocessor based on AVR RISC structure. Due to its advanced instruction set and single-cycle instruction execution time, the data throughput of ATmega128 is as high as 1 MIPS/MHz, which can alleviate the contradiction between power consumption and processing speed of the system. ATmega128 has the following features: 128K bytes of in-system programmable Flash, 4K bytes of EEPROM, 4K bytes of SRAM, 53 general-purpose I/O lines, 32 general-purpose working registers, real-time clock RTC, 4 flexible timers/counters (T/C) with comparison mode and PWM function, two USARTs, byte-oriented two-wire interface TWI, 8-channel 10-bit ADC (with optional programmable gain), programmable watchdog timer with on-chip oscillator, SPI serial port, I2C, JTAG test interface compatible with IEEE 1149.1 specification, and six power saving modes that can be selected by software.

GSM module structure and communication interface

The GSM module uses Siemens industrial-grade GSM module TC35i, which can quickly and safely implement the short message service (Short Message Service) in the system solution. The TC35i module is mainly composed of six parts: GSM baseband processor, GSM radio module, power supply module, flash memory, ZIF connector, antenna interface, etc. It has a compact design, greatly reducing the product size, is compatible with GSM2/2+, and complies with ETSI standards GSM0707 and GSM0705. The module's operating voltage is 3.3~4.8 V, compatible with dual-band (GSM 900/GSM l800) operation, and has an RS232 data communication port. The module integrates radio frequency circuits and basebands, provides users with a standard AT command interface, and provides fast, reliable and secure transmission for data, voice and short messages. TC35i has 40 pins led out through the ZIF connector.

Since the RS232 level of the PC does not match the level of the TC35i, the serial communication of the TC35i follows the RS232 standard, so the connection and communication between the PC and the TC35i can be realized through the serial port level conversion circuit MAX232. In this system, the ATmega128 microcontroller and the TC35i communicate through the serial port. Both ATmega128 and TC35i are TTL levels. The operating voltage range of ATmega128 is 2.7~5.5V, and the operating voltage range of TC35i is 3.3~4.8V. They can be directly connected by adding resistors, but generally they must be connected through the interface circuit. The interface circuit is implemented with the 7407 buffer/driver chip. The interface circuit is shown in Figure 2.

Sensor selection and interface circuit

The security functions such as anti-theft, fire prevention, and gas leakage prevention must be realized by installing corresponding sensors. For the anti-theft sensor, this design uses an infrared reflective sensor.

Install the infrared reflective sensor on both sides of the door and window or in the passage. When someone enters, the infrared reflective sensor will detect it and send a high level to the microcontroller to start the anti-theft alarm system. The infrared reflective sensor can even form a detection system for opposite beams to increase the control range. The interface circuit structure of the infrared reflective sensor and the ATmega128 microcontroller is shown in Figure 3.

This design uses semiconductor gas sensors as gas leak sensors. It detects gas by using the changes in physical properties such as conductivity produced when the gas to be tested contacts the surface of a semiconductor (mainly metal oxides). In addition, this design uses an ion smoke sensor (NIS-09C), which is widely used in various fire alarm systems and has better performance than gas-sensitive resistor fire alarms.

Storage Components Introduction

In order to store preset telephone numbers, record alarm information, and store Chinese and English character dot matrix, this system uses an off-chip Flash memory AT24C1024 that can ensure that data is not lost when power is off. This chip is an I2C bus memory. Data communication with the MCU only requires two pins, SDA and SCL. Compared with the usual parallel memory, it can greatly save the MCU's port pin resources and PCB wiring area. The I2C flash memory and the single-chip microcomputer interface circuit are shown in Figure 4. AT24C1024 uses a two-wire protocol serial bus (I2C bus) and its transmission protocol for bidirectional transmission.

GSM SMS sending principle and process

AT commands are used to operate TC35i, which includes the control of GSM voice and short messages. In order to support Chinese text messages, this design uses PDU mode to send and receive text messages, and Chinese characters use hexadecimal Unicode encoded characters. The text message module sends text messages controlled by AT commands. There are two formats of text messages sent: text format and PDU format. The former can only send characters and letters, while the latter can send characters, letters and Chinese characters. In order to make it easy for users to read the content of text messages, this article chooses to use PDU format. The transmission uses 8 data bits and 1 stop bit, no parity bit, and the baud rate is 19200bps. The basic commands for sending short messages are as follows:

1. Set the short message service center address AT+CSCA="+8613753485894" (Taiyuan)

2. Set the short message sending format (0-PDU, 1-text) AT+CMGF=1;

3. Send a short message (the content of the short message is "test") AT+CMGS="13753485896" (destination address) >test^z

4. List all short messages AT+CMGL=

"ALL"

5. Read the content of the short message (Once more), assuming INDEX=6, AT+CMGR=6

6. Delete short message AT+CMGD=

The implementation process of the short message sending system is shown in Figure 5. First, the serial port is initialized, and the AT command is used to check whether the GSM module is successfully connected. If the single-chip computer detects the high level of infrared, gas leakage, smoke and other sensors, the corresponding high level information is encoded according to a certain encoding method, and then the PDU format data is generated according to the short message center number, the destination user number of the short message, the encoding method and the short message validity period. Finally, the AT command [AT+CMGS] is used to send the short message to the user's mobile phone.

System software design

The software design of the system is written in C language of AVR series microcontroller. The software part focuses on the detection of sensor alarm signals and the control of TC35i SMS module. The flow chart of the system main program and interrupt program is shown in Figure 6. The system first initializes the serial port, interrupt and TC35i SMS module of the microcontroller. The ATmega128 microcontroller continuously detects the I/O port of the remaining sensor interface circuits. When the switch value of the sensor is detected to be 1 (high level), it means that an alarm is needed. The interrupt is opened to enter the interrupt processing subfunction. The interrupt processing subfunction completes the sending of short messages for corresponding anti-theft, fire prevention, gas leakage and other events, and starts the sound and light alarm at the same time. By using ATmega128 to send a series of AT commands to the TC35i GSM module through UART0 serial communication, the sending, receiving, searching and management of short messages based on GSM can be realized.


Figure 6 Main program and interrupt program flow chart

in conclusion

This paper discusses the design and implementation of a short message anti-theft alarm system based on ATmega128 and TC35i, proving that it is completely feasible to use TC35i short messages for alarm. The system overcomes the defects of traditional sound and light alarms and provides users with a convenient and practical home anti-theft alarm system. This design has the advantages of simple implementation, low cost, wide application range, safety and reliability, and has broad application prospects. By adding or reducing functional modules and modifying the microcontroller firmware, monitoring and anti-theft systems for other occasions can be produced, such as car anti-theft, warehouse anti-theft liquid level alarm, etc.

Reference address:Design and implementation of home alarm system based on ATmega128 and GSM

Previous article:Closed-loop linear speed control system based on single-chip microcomputer and rotary encoder
Next article:Simple sine wave control of brushless DC motor based on XC866

Latest Industrial Control Articles
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号