Smart home system design (monitoring + control)

introduction

As a graduate majoring in electronics, we need to write both graduation thesis and graduation design. I'm very happy that my reply officially ended a few days ago. Now I'd like to summarize and share my graduation project. I hope students interested in this project can gain something. At the same time, if you have problems or need to do it on behalf of students, you can confide in me. This project can be applied to environmental monitoring and smart home!

Functions implemented

  • Monitor environmental factors such as temperature, humidity, light and air quality in the air;
  • Control the simulated "home": door, lamp, curtain and fan;
  • Monitoring data OLED display, mobile phone display and computer display;
  • Control mode: key control, mobile phone control and computer control;
  • Visual display of environmental factors;
  • The platform will automatically alarm when the environmental factors exceed the standard;

Hardware selection

This part mainly introduces the reasons for hardware selection, and the specific use methods can be asked from the merchant when purchasing components.

Main control module

STM32F103C8T6 is selected as the main control module. The main reason for choosing this chip is its cost performance. Compared with 51 and 32, it has powerful peripheral interface and higher running speed. And most students have also used it in the undergraduate stage, so it is also very convenient to apply it.

Wireless communication module

ESP01S is selected as the wireless communication module. Based on this module, the first consideration is the communication mode. If we don't talk about the application scenario and compare the transmission speed, transmission distance and security, zigbee and Bluetooth will be a better choice. However, in the scenario of smart home, wifi will be a better choice, because wifi technology is basically popularized to every family. The next step is the choice of chip. The ESP8266 module of Anxin can be distinguished mainly in terms of packaging mode, hardware configuration, resource pins and so on. For specific distinction, please refer to the document description given on the official website of anxinko, please click!

data acquisition module

Temperature and humidity monitoring

DHT11 is selected as the temperature and humidity detection module in this design. DHT11 is a temperature and humidity sensor with calibrated digital signal output. The sensor is simple to use, and its accuracy and performance parameters are enough to meet the scene of environmental monitoring.
DHT11 complies with single bus protocol and has strict timing requirements. The host must first send a low level of at least 18ms. In this process, DHT11 completes AD conversion and other operations internally. When the host is pulled up, there is 20-40us time for the host to switch input and output. When the host releases the bus control (at this time, the host is in the input state, and the bus is pulled up by the pull-up resistance), DHT11 attempts to pull the bus down, After successfully pulling down, you start to prepare to send data, and then pull up again to start transmitting data.

Air quality monitoring

MQ135 is selected for air monitoring. MQ Series sensors are the most commonly used sensors to monitor the air environment. About a dozen sensors are used to detect different pollutants. In this experiment, MQ135 is used to detect the air quality of ammonia, benzene, alcohol and smoke particles. You can also choose other types of sensors according to your own needs, such as smoke, alcohol, carbon monoxide and so on.

Light monitoring

BH1750 module is selected as the light monitoring module. At the beginning of the design, this monitoring was not taken into account, considering that families can switch lights according to this monitoring. The most commonly used is the BH1750 module, which follows the IIC protocol and needs special attention in hardware configuration and code writing.

Data display module

The data display module adopts OLED module. The data display is nothing more than OLED, LCD, TFT screen, etc. the function of this module is only to assist in monitoring. Considering the cost performance factor, the 0.96 inch OLED screen is finally selected for display.

Furniture simulation module

The furniture simulation module mainly simulates doors, windows, lights and fans. It is realized by stepping motor, steering gear, LED lamp and fan module. You can buy it directly in a treasure, and the application is also very simple. Configure the working mode of the IO port and control the high and low level of the output of the GPIO port.

Cloud platform selection

The cloud platform of this design is the OneNET Internet of things cloud platform of China Mobile.
Before the design, I considered many Internet of things cloud platforms: onenet, smart cloud, Alibaba cloud and so on. Finally, after comparison, one of smart cloud or onenet is selected. Here, the scope of use of the two cloud platforms is described.

  • OneNET: it is more suitable for existing project files, and continue to develop on this basis.
  • Smart cloud: it is suitable for people who do not have engineering documents and choose to use the Internet of things cloud platform from the beginning. Code packages can be generated on the platform for development.

Code writing

There are many contents in the code part. Only part of the main function code is shown here. In addition, cloud format definition, command issuance and driver functions of each module are also important, which will not be shown in detail here.

Header file

#include "stm32f10x.h"
#include "stdio.h"
#include "math.h"
#include "delay.h"
#include "string.h"	
#include "dht11.h"
#include "BH1750.h"
#include "adc.h"
#include "led.h"
#include "OLED_I2C.h"
#include "usart.h"
#include "timer.h"
#include "exti.h"
#include "key.h"
#include "door_bsp.h"
#include "fan.h"
#include "esp8266.h"
#include "MqttKit.h"
#include "onenet.h"

Main function

typedef struct{					//Define structure
	uint8_t temp;				//temperature
	uint8_t humi;				//humidity
	float mq;					//MQ135 sensor
	float sun;					//Light intensity sensor
	uint8_t LED_FLAG;			//LED
	uint8_t FAN_FLAG;			//Fan
	uint8_t DOOR_FLAG;		//Stepper motor
	uint8_t WARNING_FLAG;		//Stepper motor
}SendData;

extern SendData send_data;
extern uint8_t cmd_rev_flag;
SendData send_data = {0, 0, 0.0, 0.0, 0 , 0 , 0 ,0};	//initialization
uint8_t cmd_rev_flag = 0;

int main(void)
{
	unsigned char *data_ptr = NULL;
	unsigned short timeCount = 0;	//Send interval variable
	Hardware_Init();
	Net_Init();
	while(1)
	{  		
		if(++timeCount >= 200 || (cmd_rev_flag == 1))	
{	
			DHT11_Read_Data(&send_data.temp,&send_data.humi);
			send_data.mq=(float)(Get_Adc_Average(ADC_Channel_1,10))*(3.3/4096);	
			send_data.sun = LIght_Intensity();										 
			OneNet_SendData();	//send data
			timeCount = 0;
			cmd_rev_flag=0;
			ESP8266_Clear();
		}
		data_ptr = ESP8266_GetIPD(0);		//Check whether there is a distribution assignment
		if(data_ptr != NULL)
			OneNet_RevPro(data_ptr);
		delay_ms(10);
	}		 
}

Hardware initialization

void Hardware_Init(void)
{
	delay_init();	    			//Delay function initialization
	TIM2_Int_Init(4999,7199);  	//For OLED display
	Usart1_Init(115200);		//Serial port debugging
	Usart2_Init(115200);		//esp8266--stm32 communication
	OLED_Init();			//OLED initialization
	OLED_CLS();
	KEY_Init();				//Key initialization
	NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
//Set interrupt priority group 2 to lay the foundation for subsequent external interrupts
	EXTIX_Init();			//Execute operation by judging key value
	DHT11_Init();			//Temperature and humidity sensor initialization
	Adc_Init();				//Air detection initialization
	BH1750_Init();			//illumination
	TIM3_Int_Init(4999,7199);  	//Alarm display
ESP8266_Init();					//Initialize ESP8266
while(OneNet_DevLink())		//Connect to OneNET
	delay_ms(500);
}	

Result display

Physical drawing and mobile phone interface display

Cloud platform data visualization interface

Display of cloud platform control interface

Extensible function

The system has high scalability. After making the basic model, it can be redeveloped. It should be noted that the hardware resources should be allocated well.

  • Voice module. Voice control of smart home.
  • Security system. Add fingerprint, RFID, face recognition and other door opening methods.
  • Alarm system. At present, we only encounter the automatic reminder of the alarm platform, and the SMS notification function can be added.
  • Auto-Control. When an environmental factor reaches a certain value, it will automatically change the state of smart home.
  • Mode selection. Automatic switching of various modes at home, such as entertainment mode, rest mode, leaving home mode, etc. furniture can correspond to different states.
  • ......

summary

Originally, I planned to write a summary of the problems encountered in this part, but I thought about too many problems and couldn't make it clear at once. If there is a private letter, please write a separate one if necessary. In terms of finishing, the function of this design is: four tests, three displays, two controls and one platform, which basically realizes the requirements of smart home, but these are basic simulations.
The hardware selection and testing of this design are implemented based on the principles of low cost, low power consumption, high integration and high degree of simulation, so the whole system has many advantages. Firstly, the simulation of smart home control system in this design is relatively high from traditional to intelligent, from front-end to back-end coverage and restoration; Secondly, the system has high compatibility, scalability and portability. Based on this, it can be redeveloped, such as adding voice modules, changing higher precision sensors and so on; Finally, it has strong applicability. When there is an independent power supply, it can be directly applied in practice to achieve the role of monitoring.
At this point, it's almost done. If it's not in place, please point out and improve it~

Keywords: C Single-Chip Microcomputer IoT

Added by kayess2004 on Wed, 02 Feb 2022 21:51:58 +0200