Electronic information graduation project stm32 and GSM remote wireless intelligent alarm system (project open source)

Article directory

  • 0 Preface
  • 1 GMS module principle
    • 1.1 GMS module
    • 1.2 Technical Specifications
    • 1.3 Adaptability
    • 1.4 GMS sample code
  • 5 Realize the effect
  • 2 System hardware design
  • 3 Software Design
  • 4 Realize the effect
  • 5 last

0 Foreword

In the past two years, the requirements and difficulty of graduation design and graduation defense have been continuously increasing. The traditional graduation project lacks innovation and highlights, and often fails to meet the requirements of graduation defense. In the past two years, students have been telling seniors about their own projects. The system does not meet the teacher’s requirements.

In order for everyone to pass the graduation project smoothly and with the least amount of energy, the seniors share high-quality graduation design projects. What I want to share today is

Graduation project stm32 and GSM remote wireless intelligent alarm system (project open source)

Seniors here give a comprehensive score for a topic (full score for each item is 5 points)

  • Difficulty factor: 3 points
  • Workload: 4 points
  • Innovation point: 4 points

Project sharing:

https://gitee.com/sinonfin/sharing

1 Principle of GMS module

1.1 GMS module


The GSM module uses SIM900 high-precision wireless GSM/GPRS complete quad-band chip from Shanghai SIMcom Company, uses SMT package and integrates high-performance ARM926EJ-S core. A cost-effective solution that can be adapted to small devices.

The module adopts standard industrial-grade interface, SIM900 is equipped with GSM/GPRS 850/900/1800/1900MHz voice, SMS, data and fax, high cohesion and low power consumption.

The instantaneous current of the module can reach 2A during communication, so it is necessary to connect an external power supply to the control board, a general 7.5V 2000mA DC power supply is enough. DC 7.5V power supply or battery box can also be purchased separately.

1.2 Technical specifications

  • Full quad-band 850/ 900/ 1800/ 1900 MHz
  • GPRS multi-hotspot type 10/8
  • GPRS Compliant Type B Base Station
  • GSM 2/2 + standard
  • Type 4 (2 W @850/ 900 MHz)
  • Type 1 (1W @ 1800/1900MHz)
  • Support SAIC (Single Antenna Interference Cancellation)
  • Adopt compatible AT command control (GSM 07.07, 07.05 and SIMCOM enhanced commands)
  • 0.1mA during low power operation
  • Operating temperature -40°C to + 85°C

1.3 Adaptability

Compatible with cellular AT commands

Introduction to AT commands

  • To use any serial debugging terminal, you need to check “Add new line” or similar. To use the serial window of Arduino IDE version 1.0 or higher, you need to select “Both NL & CR”, and the lower version of the IDE does not support this function.

  • The so-called AT command is a kind of command used by the communication module for communication, starting with the letter “AT”. After sending the AT command, it will return the execution result starting with ” + “. If there is an error, it will return “ERROR” information, and if it is normal, it will send “OK” at the end of the message.

The following are examples of commonly used functions. For complex functions, please refer to the SIM900_ATC document.

To test the signal quality, use the serial port to send the following command:

AT+CSQ

You will receive a reply message like the following:

 + CSQ: 11,0
OK

To make a call (the semicolon after this command is essential), you can replace 10086 in the following command with other numbers.

ATD10086;

Answer the phone

ATA

Send SMS

First set it to text mode:
 AT+CMGF=1
Set to use the module's default international standard alphabetic character set to send SMS
 AT+CSCS?
send target number
 AT+CMGS="10086"
At this time, a ">" prompt will appear in the system, directly enter the text message content
> YE
The purpose of this text message is to send it to 10086 to check the balance. After the sending is successful, you will receive the following prompt from the system, and the number behind it indicates the number of the sending message.
 + CMGS: 115
OK

1.4 GMS sample code

//
// SIM900 GSM/GPRS module driver
//The module is powered by 7.5V power supply, and the SIM card must be inserted during the test
// Author: Senior Dan Cheng Q746876041 Bi She Help
//

#include <Wire.h>

#define GprsPWR 37 //Module power switch signal, processor output high level will cause the module to pull down PWRKEY to turn on and off the module. Users can turn on and off the module by pulling down PWERKEY for at least 1 second and then releasing it.
#define GprsNRST 2 //External reset control pin, the processor control signal is given a high level, causing the module pin to reset to a low level reset.
#define GprsSTATUS 10 //Module status output pin, low level: the module is powered off, high level: the module is in the working state, you need to wait at least 2.5 seconds after the module power switch or module reset to check the status of the STATUS pin.


//Function prototype: void GprsPWRkey(void)
//parameter description: None
//return value: none
//Description: GPRS module power on and off sequence
///
void GprsPWRkey(void)
{<!-- -->
  digitalWrite(GprsPWR,HIGH);
  delay(1500); //Maintain at least 1 second
  digitalWrite(GprsPWR,LOW);
  delay(2500); //After waiting for 2.5 seconds, check the STATUS pin, low level of STATUS: the module is powered off, high level: the module is in working state
}


//Function prototype: void GprsReset(void)
//parameter description: None
//return value: none
//Description: GPRS module reset sequence
///
void GprsReset(void)
{<!-- -->
  digitalWrite(GprsNRST,HIGH);
  delayMicroseconds(50); //At least 50US reset signal
  digitalWrite(GprsNRST,LOW);
  delay(2500); //After waiting for 2.5 seconds, check the STATUS pin, low level of STATUS: the module is powered off, high level: the module is in working state
}


//Function prototype: void GprsInit(void)
//parameter description: None
//Return value: power-on status, 0: the module is powered off 1: the module is in the working state
//Description: GPRS initialization
///
int GprsInit(void)
{<!-- -->
  int temp = 0;
  pinMode(GprsPWR,OUTPUT); //Set each control IO as output
  pinMode(GprsNRST, OUTPUT);
  pinMode(GprsSTATUS,INPUT);
  Serial.begin(9600); //Use serial 2 to communicate with GPRS
  Serial2.begin(9600); //Use serial 2 to communicate with GPRS

  GprsReset(); //Module reset
  
  return temp;
}


//Function prototype: void GprsInit(void)
//parameter description: none
//return value: none
//Description: GPRS module test, make a call, enter ATDxxxxx13800138000 in the serial port debugging terminal; press Enter and line feed to make a call
// Send AT + CSQ to query the signal strength. Various AT commands can be tested here
///
void GprsTest(void)
{<!-- -->
   Serial2.print("A"); //Send a capital letter A to synchronize the baud rate of the GPRS module
  
          //send messages
     Serial2.println("AT+CMGF=1");
     Serial.println("AT+CMGF=1");
     delay(1000);
     Serial2.println("AT + CMGS="13800138000"");//xxx is the phone number
     Serial.println("AT + CMGS="13800138000"");//xxx is the phone number
     delay(1000);
     Serial2.print("TEST");
     Serial.print("TEST");
     delay(1000);
     Serial2.write(26);
      Serial2.write(26);
      Serial2. println();
     delay(5000);

   // SMS to 10086 for Queky
     Serial2.println("AT + CMGS="10086"");//xxx is the phone number
     Serial.println("AT + CMGS="10086"");//xxx is the phone number
     delay(1000);
     Serial2.print("YE");
     Serial.print("YE");
     delay(1000);
     Serial2.write(26);
      Serial2.write(26);
      Serial2. println();

     while(1){<!-- -->
        if(Serial.available()) //Read USB serial port data and send data to GPRS module
       {<!-- -->
         char input = Serial. read();
        Serial2. print(input);
       }
       if( Serial2.available()) //Receive the data returned by the GPRS module and display the data to the USB serial port terminal
      {<!-- -->
        char input2 = Serial2. read();
        Serial. print(input2);
      }
     }
}


void setup()
{<!-- -->
    GprsPWRkey();
    GprsInit();
    delay(2000);
    //GprsReset();
   GprsTest();
}

void loop()
{<!-- -->
    
}

//
// SIM900 GSM/GPRS module driver
//The module is powered by 7.5V power supply, and the SIM card must be inserted during the test
// Author: Senior Dan Cheng Q746876041 Bi She Help
//

5 Realize the effect

Combined with GPS module, send GPS data to your mobile phone

Part of the core code (using STM32 MCU)

#include "gps_config.h"
#include "bsp_usart3.h"
#include "nmea/nmea.h"


/* DMA receive buffer */
uint8_t gps_rbuff[GPS_RBUFF_SIZE];

/* DMA transfer end flag */
__IO uint8_t GPS_TransferEnd = 0, GPS_HalfTransferEnd = 0;



/**
  * @brief GPS_Interrupt_Config Configure the DMA interrupt used by GPS
  * @param None.
  * @retval None.
  */
static void GPS_Interrupt_Config(void)
{<!-- -->
    NVIC_InitTypeDef NVIC_InitStructure;

  NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);

    // DMA2 Channel Interrupt ENABLE
    NVIC_InitStructure.NVIC_IRQChannel = GPS_DMA_IRQn;//Interrupt uses RX not TX ah ah ah fuxx! !
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
    NVIC_Init( &NVIC_InitStructure);

}


/**
  * @brief GPS_ProcessDMAAIRQ GPS DMA interrupt service function
  * @param None.
  * @retval None.
  */
void GPS_ProcessDMAIRQ(void)
{<!-- -->
  
  if(DMA_GetITStatus(GPS_DMA_IT_HT) ) /* DMA half transfer completed */
  {<!-- -->
    GPS_HalfTransferEnd = 1; //Set half transfer complete flag bit
    DMA_ClearFlag(GPS_DMA_FLAG_HT);
        
  }
  else if(DMA_GetITStatus(GPS_DMA_IT_TC)) /* DMA transfer completed */
  {<!-- -->
    GPS_TransferEnd = 1; //Set the transfer completion flag
    DMA_ClearFlag(GPS_DMA_FLAG_TC);

   }
}


/**
  * @brief GPS_DMA_Config gps dma receiving configuration
  * @param None
  * @retval None
  */
static void GPS_DMA_Config(void) //it is a function
{<!-- -->
        DMA_InitTypeDef DMA_InitStructure; //Define a structure of type DMA_InitTypeDef named DMA_InitStructure
    
        /* Turn on the DMA clock */
        RCC_AHBPeriphClockCmd(GPS_DMA_CLK, ENABLE);

        /*Set DMA source: serial port data register address*/
        DMA_InitStructure.DMA_PeripheralBaseAddr = GPS_DATA_ADDR; //Dots are members of the structure, which can be assigned directly, which is equivalent to variables
//Enter gps.config.h from here, it can be seen that the serial communication of GPS is defined as USart2, we can modify it from here
        /* memory address (pointer to the variable to be transferred) */
        DMA_InitStructure.DMA_MemoryBaseAddr = (u32)gps_rbuff;

        /* Direction: from peripheral to memory */
        DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;

        /*Transfer size DMA_BufferSize=SENDBUFF_SIZE*/
        DMA_InitStructure.DMA_BufferSize = GPS_RBUFF_SIZE;

        /* Peripheral address does not increase */
        DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; //If you want to modify, you can directly find the corresponding name modification

        /*Memory address auto-increment*/
        DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;

        /*Peripheral data unit*/
        DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;

        /*memory data unit 8bit*/
        DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;

        /*DMA mode: continuous loop*/
        DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;

        /*Priority: Medium*/
        DMA_InitStructure.DMA_Priority = DMA_Priority_Medium;

        /* Disable memory-to-memory transfers */
        DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;

        /*Configure DMA channel*/
        DMA_Init(GPS_DMA_CHANNEL, & DMA_InitStructure);
    
    GPS_Interrupt_Config();
        
    DMA_ITConfig(GPS_DMA_CHANNEL,DMA_IT_HT|DMA_IT_TC,ENABLE); //Configure DMA to generate an interrupt after sending

        /*Enable DMA*/
        DMA_Cmd(GPS_DMA_CHANNEL, ENABLE);
    
    /* Configure serial port to send TX request to DMA */
        USART_DMACmd(GPS_USART, USART_DMAReq_Rx, ENABLE);


}

/**
  * @brief GPS_Config gps initialization
  * @param None
  * @retval None
  */
void GPS_Config(void)
{<!-- -->
  GPS_USART_INIT(); //Initialize the serial port
  GPS_DMA_Config(); //Initialize the DMA mode of the serial port
  
}

 

/**
  * @brief trace output captured GPS sentences when decoding
  * @param str: String to be output, str_size: data length
  * @retval None
  */
void trace(const char *str, int str_size)
{<!-- -->
  #ifdef __GPS_DEBUG // Configure this macro in the gps_config.h file, whether to output debugging information
    uint16_t i;
    printf("\r\\
Trace: ");
    for(i=0;i<str_size;i++)
      printf("%c",*(str + i));
  
    printf("\\
");
  #endif
}

/**
  * @brief error Output prompt message when decoding error
  * @param str: String to be output, str_size: data length
  * @retval None
  */
void error(const char *str, int str_size)
{<!-- -->
    #ifdef __GPS_DEBUG // Configure this macro in the gps_config.h file, whether to output debugging information

    uint16_t i;
    printf("\r\\
Error: ");
    for(i=0;i<str_size;i++)
      printf("%c",*(str + i));
    printf("\\
");
    #endif
}



/**************************************************** ***************************************************** *****
** Function name: bit IsLeapYear(uint8_t iYear)
** Function description: Judging leap year (only for years after 2000)
** Entry parameters: iYear two-digit year
** Export parameters: uint8_t 1: leap year 0: normal year
***************************************************** ***************************************************** ****/
static uint8_t IsLeapYear(uint8_t iYear)
{<!-- -->
    uint16_t Year;
    Year = 2000 + iYear;
    if((Year & 3)==0)
    {<!-- -->
        return ((Year@0==0) || (Year 0!=0));
    }
     return 0;
}

/**************************************************** ***************************************************** *****
** Function name: void GMTconvert(uint8_t *DT,uint8_t GMT,uint8_t AREA)
** Function description: Convert GMT to time in various time zones around the world
** Entry parameters: *DT: Array representing date and time format YY,MM,DD,HH,MM,SS
** GMT: Time zone number
** AREA: 1( + ) East Area W0(-) West Area
***************************************************** ***************************************************** ****/
void GMTconvert(nmeaTIME *SourceTime, nmeaTIME *ConvertTime, uint8_t GMT, uint8_t AREA)
{<!-- -->
    uint32_t YY,MM,DD,hh,mm,ss; //temporary variable for year, month, day, hour, minute and second
     
    if(GMT==0) return; //If it is in 0 time zone, return directly
    if(GMT>12) return; //The maximum time zone is 12, then return

    YY = SourceTime->year; // get the year
    MM = SourceTime->mon; // get the month
    DD = SourceTime->day; //Get the day
    hh = SourceTime->hour; // get time
    mm = SourceTime->min; //Get minutes
    ss = SourceTime->sec; // get seconds

    if(AREA) // East ( + ) time zone processing
    {<!-- -->
        if(hh + GMT<24) hh + = GMT;//If it is on the same day as GMT, just add hours
        else //If it is 1 day later than GMT, then perform date processing
        {<!-- -->
            hh = hh + GMT-24; //Get the time first
            if(MM==1 || MM==3 || MM==5 || MM==7 || MM==8 || MM==10) //big month (December is processed separately)
            {<!-- -->
                if(DD<31) DD ++ ;
                else
                {<!-- -->
                    DD = 1;
                    MM++;
                }
            }
            else if(MM==4 || MM==6 || MM==9 || MM==11) // small months and February are processed separately)
            {<!-- -->
                if(DD<30) DD ++ ;
                else
                {<!-- -->
                    DD = 1;
                    MM++;
                }
            }
            else if(MM==2) //Process February
            {<!-- -->
                if((DD==29) || (DD==28 & amp; & amp; IsLeapYear(YY)==0)) //It was originally a leap year and it was February 29 or it was not a leap year and it was February 28
                {<!-- -->
                    DD = 1;
                    MM++;
                }
                else DD ++ ;
            }
            else if(MM==12) //Process December
            {<!-- -->
                if(DD<31) DD ++ ;
                else //The last day of New Year's Eve
                {<!-- -->
                    DD = 1;
                    MM = 1;
                    YY++;
                }
            }
        }
    }
    else
    {<!-- -->
        if(hh>=GMT) hh -= GMT; //If it is on the same day as Greenwich Mean Time, only decrease the time
        else //If it is already 1 day earlier than GMT, then perform date processing
        {<!-- -->
            hh = hh + 24-GMT; //Get the time first
            if(MM==2 || MM==4 || MM==6 || MM==8 || MM==9 || MM==11) //Last month is a big month (January is processed separately)
            {<!-- -->
                if(DD>1) DD--;
                else
                {<!-- -->
                    DD = 31;
                    MM --;
                }
            }
            else if(MM==5 || MM==7 || MM==10 || MM==12) //Last month is a small month and February is processed separately)
            {<!-- -->
                if(DD>1) DD--;
                else
                {<!-- -->
                    DD = 30;
                    MM --;
                }
            }
            else if(MM==3) //Process last month is February
            {<!-- -->
                if((DD==1) & amp; & amp; IsLeapYear(YY)==0) //is not a leap year
                {<!-- -->
                    DD = 28;
                    MM --;
                }
                else DD--;
            }
            else if(MM==1) //Process January
            {<!-- -->
                if(DD>1) DD--;
                else //The first day of the new year
                {<!-- -->
                    DD = 31;
                    MM = 12;
                    YY --;
                }
            }
        }
    }

    ConvertTime->year = YY; //update year
    ConvertTime->mon = MM; //update month
    ConvertTime->day = DD; //update day
    ConvertTime->hour = hh; //When updating
    ConvertTime->min = mm; //Update minutes
    ConvertTime->sec = ss; //update seconds
}



/**************************************************** ***********end of file**************************************** *************/

2 System hardware design

The hardware of this system is mainly composed of sensor network, PT2262/2267 wireless transceiver module, MCU controller and GSM module.

The sensor part is mainly to collect home safety information, such as temperature, movement of doors and windows, and the most distinctive part of this design is also the selection of sensors, using a new type of acceleration sensor to make the anti-theft module more perfect; AT2262/2272 is used for wireless The part connecting the sensor and the single-chip microcomputer, this part avoids a large amount of wiring work of the anti-theft system; the single-chip microcomputer is mainly used to process and judge the collected information and make corresponding processing, which is the brain of the whole system; the GSM module is mainly used to contact users , Under the background that mobile phones are very popular in Hyundai, it will be very fast to use the GSM module to directly notify the head of the household of the family security situation by short message or voice call, so that the security situation at home can be dealt with in a timely manner.

3 Software Design

The whole system is mainly divided into two states: the state where the owner is at home and the state where the owner is not at home. When the owner is at home, the alarm system only monitors the temperature sensor and the smoke sensor; when the button of the owner is not at home is pressed, the system enters the state of the owner not at home, and performs a series of monitoring on the doors, windows, temperature, smoke, etc. , Once an accident occurs, the head of the household can be notified in time to take first aid measures to effectively avoid further disasters.
The program is composed of main program, power-on initialization module, owner’s home status module, delay and timer module, no one’s home status module, sensor detection module, serial port initialization and GSM communication module.

  • (1) The main program. After the MCU is powered on, the main program is executed. The main program calls the power-on initialization module, then determines whether the user is at home or not, and determines the working state.
  • (2) Start the initialization module. This module controls the indicator lights of all modules to light up to ensure that all modules are working normally. At the same time, it assigns values to the special registers inside the microcontroller. After the settings are completed, it enters the home state of the master. Only when the system is reset will the module be called again.
  • (3) The master is at home status module. This module invokes a regular scan of the input, and if the temperature or smoke concentration at home is abnormal, it will be an alarm, and at the same time, it can be transferred to the unattended module under the control of the button. The module barrel is combined with a detector detection module, a delay and a timer module to prevent false triggering of the detector and improve system reliability.
  • (4) Delay and timer module. This module contains the software delay sub-function and the sub-function of setting and starting the timer to achieve the regular scanning of the keyboard.
  • (5) No one is at home status module. This module calls the sensor detection module, delay and timing module for external input
    Make a detection, sound an alarm in case the sensor is triggered and go to send SMS module.
  • (6) Sensor detection module. Real-time detection is carried out by means of regular scanning to prevent the alarm from being falsely triggered, and the owner is at home status module and the no one is at home status module return the status of each input port.
  • (7) Sensor detection module. The sensor is mainly composed of MMA7455i acceleration sensor, temperature sensor and smoke sensor, which monitors the situation in the home and performs simple signal processing.
  • (8) Serial port initialization and communication module. This module initializes the serial port when it enters the state of sending short messages, is responsible for sending and receiving data from the serial port, and sets special registers and global variables when sending short messages. Prevent repeated sending of text messages caused by certain sensors being triggered all the time.
  • (9) GSM sending SMS module. The module controls the sending of short messages by calling the serial port initialization and the communication module and the GSM module to send AT commands.

4 Realize the effect

After connecting the circuit, breath on the DHT11 and observe whether the humidity value on the LCD screen increases, so as to judge whether the DHT11 can realize the function of collecting humidity information. At the same time, heat up the soldering iron, and when it reaches a certain temperature, place it next to the DHT11, and observe the change of the temperature value from the LCD screen. At the same time, when the temperature rises to 45°, observe whether the microcontroller will send a text message to the designated mobile phone through GSM .

5 last

Project sharing:

https://gitee.com/sinonfin/sharing