STM32 project design: smart door lock PCB and source code based on STM32F1 (4 unlocking methods)

Project video
Bli bli video link: making
Project data
stm32f1 smart door lock free information link:
Link: https://pan.baidu.com/s/1_au_QM2-59dMhIj4_lP2vQ
Extraction code: wa4y

stm32f1 smart door lock complete information link:
https://download.csdn.net/download/mbs520/52718826

preface

1. Many students reported that STM32F4 is expensive and the production cost is too high, so I spent nearly a month's free time to study the production of F4 smart door lock with the lowest cost and even more functions
STM32F4 smart door lock blog link: https://blog.csdn.net/mbs520/article/details/106987758

1, Project introduction

(1) Function overview

F4 version:
1. The fingerprint information of family members can be added, deleted, checked and modified through the fingerprint module, and the relevant information about whether the addition, deletion, check and modification is successful is displayed on the OLED screen
2. In the process of fingerprint matching, if the collected fingerprint matches with the fingerprint module library, the OLED displays that the matching is successful and rotates the stepping motor for one turn
3. The smart door lock password can be set by pressing the key. The password can be set to two (six digits). If one of the two is matched successfully, the lock can be unlocked, or the password can be modified by pressing the key. All operation processes are displayed in OLED
4. Realize RFID and mobile phone unlocking (Bluetooth unlocking)
5. Extension: virtual password unlocking (virtual password: Baidu)
F1 version added:
1. You can enter 10 cards
2. When unlocking, turn the stepper motor clockwise for one turn and turn the lock counterclockwise
3. New buzzer prompt
4. New unlock error prompt

(2) Main technologies used in the project

F4 version:
1. IIC protocol, SPI protocol, serial port protocol
2. External flash driver, SD card driver
3. FTAFS file system
4. RTC real time clock
F1 version:
1. IIC protocol, SPI protocol, serial port protocol
2. GUI interface design, Chinese character display
3. RTC real time clock

(3) Characteristics of the project

1. Material selection is based on economy

The most expensive material is the fingerprint module 40 yuan, and the single chip microcomputer is only 10 yuan

2. Reduce unnecessary materials

Such as external FLASH,SD Card module, single chip microcomputer, crystal oscillator

2. Use PCB and refuse cumbersome wiring

It is more convenient to make and learn

3. Powerful

It has four unlocking methods, Chinese interface, modification and entry operations, and mobile phone APP control

4. High material function utilization

MCU pin(48pin)Utilization rate>90%,MCU memory(64K)Utilization rate>70%

2, Material selection

1. Master controller STM32F103C8T6 (can be replaced by compatible product CH32F103C8T6)

2. Stepper motor (with drive module)
Model: 28BYJ4+ULN2003

3. 4X4 matrix key

4. Fingerprint module AS608 (serial port control)

5. 0.96 inch OLED display (IIC)
Model: 7-pin

6. RFID RC522 RF module (with one card)
7. DuPont wire, pin, resistor, capacitor, triode, potentiometer, etc

3, Schematic design

Use the simplest hardware circuit to do more functions
(the screenshot is vague and can be viewed by downloading resources)

4, PCB design

It adopts the cheapest double-layer version, 10cm*10cm design

5, Source code design

The source code is transplanted from F4 version of smart door lock. Some incompatible functions have been modified and new functions have been added

void DisUnLock(void )
{
	OLED_Clear();
	Show_Str(20,10,128,24,"Unlocking...",24,0);	
	OLED_Refresh_Gram();//update display
	Walkmotor_ON();
	Show_Str(20,10,128,24,"Unlocked!",24,0);
	OLED_Refresh_Gram();//update display
	delay_ms(1500);
}

void DisLock(void )
{
	OLED_Clear();
	Show_Str(30,20,128,16,"Locked!",16,0);
	OLED_Refresh_Gram();//update display
	Walkmotor_OFF();
	Show_Str(30,20,128,16,"Locked!",16,0);
	OLED_Show_Font(56,48,0);//lock
	OLED_Refresh_Gram();//update display
	delay_ms(1000);
}
 int main(void)
 {			
	u16 set=0;
	int key_num;
	int time1;
	int time2;		//Screen lock time
	char arrow=0;  //Arrow seat
	//SysHSI_Init();
	delay_init();	    	 //Delay function initialization	  
	NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); //Set NVIC interrupt packet 2: 2-bit preemption priority and 2-bit response priority
	uart_init(9600);	 //The serial port is initialized to 9600
	printf("The serial port function is normal\r\n");
	Button4_4_Init();          //Initialize the hardware interface connected with the key
	OLED_Init();    			//Display initialization
	Walkmotor_Init();        //Stepper motor initialization
	BEEP_Init();			//Buzzer initialization
	usart2_init(usart2_baund);           //Initialize fingerprint module
	PS_StaGPIO_Init();
	OLED_Clear(); 
	 
	starting();//Boot info logo
	RTC_Init();	  			//RTC initialization
	SysPartInit();   //System parameter initialization 
 	while(1)
	{
//Lock screen interface
MAIN:
			OLED_Clear(); 
			OLED_Show_Font(56,48,0);//Show lock Icon
			while(1)
			{
				time1++;Display_Data();//Time display: update the display data every 1000ms
				
				if(DisFlag == 1)
				{
					DisFlag = 0;
					OLED_Fill(0,24,16,63,0);
					OLED_Refresh_Gram();//update display
				}
				
				if((time1%100)==1)
				{
					//MFRC522 unlock
						time1=0;
						MFRC522_Initializtion();			
						Error=MFRC522_lock();
						if(Error==0)
						{
							goto MENU;	
						}
						else 
						{
							OLED_Show_Font(56,48,0);//lock
						}
						
						//Mobile phone Bluetooth unlock password 1
						Error=usart1_cherk((char*)sys.passwd1);         
						if(Error==0){ 
							OLED_Clear_NOupdate();
							Show_Str(12,13,128,20,"Bluetooth password 1: correct",12,0); 
							OLED_Refresh_Gram();//update display
							delay_ms(800);
							DisUnLock();
							goto MENU;	
						}
						//Mobile phone Bluetooth unlock password 2
						Error=usart1_cherk((char*)sys.passwd2);         
						if(Error==0){
							OLED_Clear_NOupdate();
							Show_Str(12,13,128,12,"Bluetooth password 2: correct",12,0); 
							OLED_Refresh_Gram();//update display
							delay_ms(800);
							DisUnLock();
							goto MENU;	
						}
				}
				//Fingerprint unlock
				if(PS_Sta)	 //Detect PS_Sta status, if a finger presses
				{
						while(PS_Sta){
						Error=press_FR();//Brush fingerprint
						if(Error==0)
						{
							//DisUnLock();
							goto MENU;   //Skip to unlock interface
						}								
						else 
						{
							OLED_Show_Font(56,48,0);//lock
						}
					}
				}
				//Password lock
				key_num=Button4_4_Scan();	//Key scan
				if(key_num!=-1)
				{
					Error=password();//Password unlocking function
					if(Error==0)
					{
						goto MENU;	//Skip to unlock interface
					}
					else 
					{
						OLED_Show_Font(56,48,0);//lock
					}
				}
				delay_ms(1);
				
			}
			/********************Main interface**************************/

MENU:
			OLED_Clear();
MENUNOCLR:
			OLED_Fill(0,0,20,48,0);
			//Home menu display
			if(arrow<3){
				Show_Str(5,arrow*16,128,16,"->",16,0);//Show arrows
				set=0;}
			else {
				Show_Str(5,(arrow-3)*16,128,16,"->",16,0);
				set=3;}
			Show_Str(25,0,128,16,setup[set],16,0);
			Show_Str(25,16,128,16,setup[set+1],16,0);
			Show_Str(25,32,128,16,setup[set+2],16,0);
			Show_Str(0,52,128,12,"upper    lower     determine",12,0);
			OLED_Refresh_Gram();//update display
			time2=0;
			while(1)
			{
						//Timeout lock screen
						time2++;
						if(time2>10000 | key_num==4){  
							
							OLED_Clear();
								DisLock();
								if(time2>10000)beep_on_mode2();
								time2 =0;
								OLED_Clear();
								goto MAIN;
						}
						//Mobile phone Bluetooth lock
						if(memcmp(USART_RX_BUF,"LOCK",4)==0)	{
							DisLock();
							goto MAIN;
						}
						
						//Function option selection
						key_num=Button4_4_Scan();	
						if(key_num)
						{
							if(key_num==13){
								if(arrow>0)arrow--;
								goto MENUNOCLR;
							}
							if(key_num==15){
								if(arrow<5)arrow++;
								goto MENUNOCLR;
							}
							if(key_num==16){
								switch(arrow)
								{
									case 0:Add_FR();		break;//Recording finger
									case 1:Del_FR();		break;//Delete fingerprint
									case 2:SetPassworld();break;//Change Password
									case 3:Set_Time(); break;  //Set time
									case 4:Add_Rfid(); break;  //Input card
									case 5:Massige(); break;  //display information							
								}
								goto MENU;
							}		
						}delay_ms(1);
			}	
	}
		 
 }
 

6, Android APP Design

1. Icon design

2. Main interface design
Usage: ① enter the APP, wait for 3-5 seconds, and automatically connect the smart door lock
② After the connection is displayed in the upper left corner, enter the password and click OK to unlock
③ If automatic connection is not possible, click the connect button to enter the manual connection interface


3. Connection interface
Usage: double click to connect

4. Information interface design

7, Finished product display

1. Boot interface
Insert picture description here

2. Lock screen display time

3. Unlock display menu

Tags: Embedded system Single-Chip Microcomputer stm32

Posted on Wed, 01 Dec 2021 05:54:29 -0500 by ryanfern86goa