Introduction With the rapid development of Internet of Things (IoT) technology, intelligent homes have gradually entered thousands of households. Among them, the security system, as an important component of smart homes, plays a crucial role in ensuring family safety. This article designs an intelligent home security system based on the 51 microcontroller, integrating temperature and humidity/smoke/human infrared detection, GSM remote alarm, fingerprint/password door lock control, and home appliance linkage functions, providing users with comprehensive security protection. System Design Overview This system uses the STC89C52 microcontroller as the core control unit, implements environmental monitoring through various sensors, utilizes a GSM module for remote alarms, employs fingerprint recognition technology for door lock control, and achieves linkage functions through intelligent control of home appliances.
Hardware Design 1. Sensor Module • Temperature/Humidity Detection: Uses DS18B20 digital temperature sensor and DHT11 temperature and humidity sensor to monitor indoor environment in real-time. • Smoke Detection: MQ-2 gas sensor is used to detect the concentration of combustible gases, and the ADC0832 analog-to-digital converter converts the analog signals into digital signals that can be processed by the microcontroller. • Human Infrared Detection: HC-SR501 human infrared sensor is used to detect abnormal intrusions. 2. Alarm and Control Module • GSM Module: SIM800L module is used to send alarm messages remotely. • Door Lock Control: Uses a 12864 LCD display and fingerprint module (such as FPM10A) to implement fingerprint/password door lock control. • Home Appliance Linkage: Controls lighting and curtain motors through relays to achieve intelligent linkage. Software Design 1. System Initialization
#include <reg52.h>
#include "stdio.h"
#include "intrins.h"
#include "usart.h"
#define u8 unsigned char
#define u16 unsigned int
// System parameter definitions
u8 yushe_wendu = 50; // Temperature preset value
u8 yushe_yanwu = 100; // Smoke preset value
u8 yushe_shidu = 60; // Humidity preset value
u8 mode = 0; // System working mode
// Sensor pin definitions
sbit DS18B20 = P1^0;
sbit MQ2 = P1^1;
sbit HC_SR501 = P1^2;
sbit GSM_TX = P3^0;
sbit GSM_RX = P3^1;
sbit FINGERPRINT = P1^3;
sbit LED_RED = P2^0;
sbit LED_GREEN = P2^1;
sbit BUZZER = P2^2;
sbit LIGHT_RELAY = P2^3;
sbit CURTAIN_RELAY = P2^4;
2. Temperature/Soot/Humidity Detection
// Temperature reading function
u16 read_temperature(void)
{
// DS18B20 temperature reading code
// ...
return temperature_value;
}
// Smoke concentration reading function
u16 read_smoke(void)
{
// ADC0832 smoke concentration reading code
// ...
return smoke_value;
}
// Humidity reading function
u16 read_humidity(void)
{
// DHT11 humidity reading code
// ...
return humidity_value;
}
3. Human Infrared Detection and Alarm
// Human infrared detection function
void check_invasion(void)
{
if (HC_SR501 == 0)
{
// Detected intrusion
LED_RED = 1; // Red light on
BUZZER = 1; // Buzzer sounds
send_gsm_alert("Intrusion Alert!"); // Send GSM alarm
}
}
4. GSM Remote Alarm
// GSM module initialization
void init_gsm(void)
{
// GSM module initialization code
// ...
}
// Send alarm message
void send_gsm_alert(char *msg)
{
// Send message code
// ...
USART_SendString("AT+CMGF=1\r\n"); // Set SMS mode
USART_SendString("AT+CMGS=\"13800138000\"\r\n"); // Send to specified number
USART_SendString(msg);
USART_SendString("\x1A"); // End character
}
5. Fingerprint/Password Door Lock Control
// Fingerprint recognition function
u8 fingerprint_recognition(void)
{
// Fingerprint recognition code
// ...
return is_valid;
}
// Door lock control
void control_lock(u8 open)
{
if (open)
{
// Unlock operation
// ...
LED_GREEN = 1; // Green light on
}
else {
// Lock operation
// ...
LED_GREEN = 0;
}
}
6. Home Appliance Linkage Control
// Light control function
void control_light(u8 status)
{
if (status)
{
LIGHT_RELAY = 1; // Turn on light
}
else {
LIGHT_RELAY = 0; // Turn off light
}
}
// Curtain control function
void control_curtain(u8 status) {
if (status) {
CURTAIN_RELAY = 1; // Open curtain
} else {
CURTAIN_RELAY = 0; // Close curtain
}
}
System Function Implementation When the system is running, it first initializes and then continuously checks the data from various sensors. When the temperature, humidity, or smoke concentration exceeds the preset threshold, or when human intrusion is detected, the system immediately activates sound and light alarms and sends alarm messages to the user’s mobile phone via the GSM module. In terms of door lock control, users can unlock using fingerprints or passwords. The system uses a 12864 LCD display to show the operation interface, providing a friendly user interaction experience. Users can set alarm thresholds and adjust system parameters on the display. The home appliance linkage function automatically controls lighting and curtains based on environmental conditions. For example, when insufficient indoor light is detected, the system automatically turns on the lights; when excessive sunlight is detected, it automatically closes the curtains to maintain comfortable indoor lighting. The system also supports preset scenes, such as “Home Mode” (one-click to turn on lights + curtains) and “Movie Mode” (dim lights + close curtains). Conclusion This system successfully implements intelligent home security functions based on the 51 microcontroller, including environmental monitoring, remote alarms, intelligent door locks, and home appliance linkage. The system features low cost, high stability, and comprehensive functionality, effectively enhancing family safety. In the future, the system can be further optimized, such as adding a WiFi module for mobile APP remote control, using more precise sensors to improve detection accuracy, and incorporating AI algorithms to achieve smarter linkage strategies, providing users with a more convenient and secure home environment.