laitimes

Human health monitoring system based on single-chip STM32 - single-chip embedded Internet of Things

author:Embedded XFF

Human health monitoring system based on STM32

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

1 Introduction

Based on the worker monitoring system developed by STM32F103C8T6 single-chip microcomputer, the system can monitor temperature and humidity, smoke concentration, heart rate, sanitation worker location in real time, and can display these data on the upper computer end, put the finger on the heart rate detection sensor, the upper computer has a heart rate display, smoke rain and fog concentration exceeds the threshold will alarm and display the location of workers.

2 Main components

  • STM32F103C8T6
  • Heart rate sensor
  • Greenhouse degree sensor
  • Smoke concentration sensor

3 Achieve the effect

Human health monitoring system based on single-chip STM32 - single-chip embedded Internet of Things

4 Design principles

4.1 ATGM332D positioning module

Brief introduction

The ATGM332D-5N series module is the general name of the 12X16 size family of high-performance BDS/GNSS all-constellation positioning and navigation modules. This series of module products are based on the fourth generation of low-power GNSS SOC single-chip - AT6558, which supports GPS in the United States and BDS (Beidou Satellite Navigation System) in China

ATGM332D-5N series modules have the advantages of high sensitivity, low power consumption and low cost, suitable for car navigation, handheld positioning, wearable devices, and can directly replace NEO-M8N, and are fully compatible with package size and pin definition.

The default baud rate of the module is 9600, and all packets are fully open and cannot be used directly

9600 with all packets fully open, which will cause data congestion, and the occurrence time will be delayed by a full second, about 1, 2, 3, and 4 seconds.

The baud rate must be increased to 115200; Or turn off redundant messages and leave only RMC.

Description of latitude and longitude data

Human health monitoring system based on single-chip STM32 - single-chip embedded Internet of Things

4.2 MAX30102 heart rate sensor

MAX30102 is a module that integrates pulse oximeter and heart rate monitor biosensors. It integrates a red LED and an infrared LED, photodetector, optical components, and low-noise electronics with ambient light suppression. The MAX30102 uses a 1.8V power supply and a separate 5.0V power supply for internal LEDs and is used in wearable devices for heart rate and blood oxygen collection and wear on fingers, earlobes, and wrists. The standard 2C-compatible communication interface can transmit the collected values to Arduino, KL25Z and other microcontrollers for heart rate and blood oxygen calculation. In addition, the chip can also shut down the module through software, and the standby current is close to zero, so that the power supply is always in the power state. Because of its excellent performance, the chip is widely used in Samsung Galaxy S7 mobile phones. Compared to its predecessor MAX30100 (MAX30100 is now obsolete), the MAX30102's integrated glass cover effectively eliminates external and internal light interference for optimal and reliable performance.

There are three main methods of pulse measurement:

  • One is extracted from ECG signals;
  • The second is to calculate the pulse rate from the fluctuation measured by the pressure sensor when measuring blood pressure;
  • The third is the photoplethysmography method.

Both of the first two methods of extracting signals limit the patient's activity and increase the patient's physical and psychological discomfort if used for a long time. As one of the most common methods of monitoring measurement, photoplethysmography pulse measurement has the characteristics of simple method, convenient wearing and high reliability. The basic principle of photoplethysmography is to use human tissues to cause different light transmittance when blood vessels pulsate to measure pulse and blood oxygen saturation. The sensor used consists of two parts, a light source and a phototransducer, which are fixed to the patient's fingers, wrists or earlobes by straps or clips. The light source generally uses a specific wavelength light-emitting diode that selectively selects oxygenated hemoglobin (HbO2) and blood red egg white (Hb) in arterial blood (generally red light around 660nm and infrared light around 900nm). When the beam passes through the peripheral blood vessels of the human body, the transmittance of this light changes due to changes in the congestion volume of the arterial beat, and the light reflected by the human tissue is received by the photoelectric converter, which is converted into an electrical signal and amplified and output. Since the pulse is a signal that changes periodically with the pulse of the heart, and the volume of arterial blood vessels also changes periodically, the electrical signal change period of the photoelectric converter is the pulse rate. At the same time, according to the definition of blood oxygen saturation, it is expressed as:

Human health monitoring system based on single-chip STM32 - single-chip embedded Internet of Things

The MAX30102 itself integrates a complete light-emitting LED and driver part, light sensing and AD conversion part, ambient light interference cancellation and digital filtering part, leaving only the digital interface to the user, which greatly reduces the user's design burden. Users only need to use a single-chip microcomputer to read the FIFO of the MAX30102 itself through hardware I2C or analog I2C interface, and the converted light intensity value can be obtained, and the heart rate value and blood oxygen saturation can be obtained by writing the corresponding algorithm.

Human health monitoring system based on single-chip STM32 - single-chip embedded Internet of Things

4.3 DHT11 temperature and humidity sensor

Brief introduction

Human health monitoring system based on single-chip STM32 - single-chip embedded Internet of Things

The DHT11 digital humidity and temperature sensor is a temperature and humidity composite sensor with a calibrated digital signal output. It uses dedicated digital module acquisition technology and temperature and humidity sensing technology to ensure high reliability and excellent long-term stability. The sensor consists of a resistive moisture sensing element and an NTC temperature measuring element, and is connected to a high-performance 8-bit microcomputer. Therefore, the product has the advantages of excellent quality, ultra-fast response, strong anti-interference ability and extremely high cost performance. Each DHT11 sensor is calibrated in an extremely precise humidity calibration chamber. The calibration coefficients are stored in the OTP memory in the form of a program and are called up internally in the sensor during the processing of the detection signal. Single-wire serial interface makes system integration quick and easy. Its ultra-small size, extremely low power consumption, and signal transmission distance of more than 20 meters make it the best choice for a variety of applications and even the most demanding applications. The product is available in a 4-pin single-row pin package. Easy to connect, special packages are available according to user needs.

connection

Human health monitoring system based on single-chip STM32 - single-chip embedded Internet of Things

DHT11 encoding steps

  1. Do not read within 1s after the point on the single-chip microcomputer (not important)
  2. The host (microcomputer) sends a start signal: the host first pulls the data high and the data delay is 18ms to pull the data high (the single-chip pin is set as the input through this operation).
  3. The slave (DHT11) responds after receiving the start signal: the slave pulls the data low, the host reads that the data line is pulled low for 80us, and then the slave pulls the data line high for 80us until the end of the high level, which means that the host can start receiving data.
  4. The host begins to receive data: the host first pulls the data line high (IO is set as input) The slave pulls the data line low, and the host reads the data line level until the end of the low level (about 50us) After the slave pulls the data line high, the delay is about 40us (between 28~70us) The host reads the data line level again, if it is low, it is "0", if it is high, it is "1". Continue to repeat steps 1,2 above for a total of 40 times.

4.4 MQ-2 smoke sensor

Brief introduction

MQ-2 is commonly used in gas leakage monitoring devices in homes and factories, and is suitable for the detection of liquefied gas, benzene, alkane, alcohol, hydrogen, smoke, etc. Therefore, the MQ-2 can be accurately described as a multi-gas detector.

The MQ-2 has an extremely wide detection range. Its advantages: high sensitivity, fast response, good stability, long life, simple drive circuit.

Human health monitoring system based on single-chip STM32 - single-chip embedded Internet of Things

Second, the working principle of MQ-2

MQ-2 smoke sensor belongs to tin dioxide semiconductor gas sensing material, surface ionic N-type semiconductor. At 200~300 degrees Celsius, tin dioxide adsorbs oxygen in the air to form negative ion adsorption of oxygen, which reduces the electron density in the semiconductor, thereby increasing its resistance value. When in contact with smoke, if the barrier at the intergranular boundary changes in response to smoke, it will cause a change in surface conductivity. Using this point, the information about the presence of this smoke can be obtained, the greater the concentration of smoke, the greater the conductivity, the lower the output resistance, the greater the output analog signal.

Human health monitoring system based on single-chip STM32 - single-chip embedded Internet of Things

5 parts of core code

/** \file max30102.cpp ******************************************************
*
* Project: MAXREFDES117#
* Filename: max30102.cpp
* Description: This module is an embedded controller driver for the MAX30102
*
* Revision History:
*\n 1-18-2016 Rev 01.00 GL Initial release.
*\n
*/

#include "max30102.h"
#include "myiic.h"

#define max30102_WR_address 0xAE
bool maxim_max30102_write_reg(uint8_t uch_addr, uint8_t uch_data)
/**
* \brief        Write a value to a MAX30102 register
* \par          Details
*               This function writes a value to a MAX30102 register
*
* \param[in]    uch_addr    - register address
* \param[in]    uch_data    - register data
*
* \retval       true on success
*/
{
    /* 第1步:发起I2C总线启动信号 */
    i2c_Start();

    /* 第2步:发起控制字节,高7bit是地址,bit0是读写控制位,0表示写,1表示读 */
    i2c_SendByte(max30102_WR_address | I2C_WR);	/* 此处是写指令 */

    /* 第3步:发送ACK */
    if (i2c_WaitAck() != 0)
    {
        goto cmd_fail;	/* EEPROM器件无应答 */
    }

    /* 第4步:发送字节地址 */
    i2c_SendByte(uch_addr);
    if (i2c_WaitAck() != 0)
    {
        goto cmd_fail;	/* EEPROM器件无应答 */
    }

    /* 第5步:开始写入数据 */
    i2c_SendByte(uch_data);

    /* 第6步:发送ACK */
    if (i2c_WaitAck() != 0)
    {
        goto cmd_fail;	/* EEPROM器件无应答 */
    }

    /* 发送I2C总线停止信号 */
    i2c_Stop();
    return true;	/* 执行成功 */

cmd_fail: /* 命令执行失败后,切记发送停止信号,避免影响I2C总线上其他设备 */
    /* 发送I2C总线停止信号 */
    i2c_Stop();
    return false;
}

bool maxim_max30102_read_reg(uint8_t uch_addr, uint8_t *puch_data)
/**
* \brief        Read a MAX30102 register
* \par          Details
*               This function reads a MAX30102 register
*
* \param[in]    uch_addr    - register address
* \param[out]   puch_data    - pointer that stores the register data
*
* \retval       true on success
*/
{
    /* 第1步:发起I2C总线启动信号 */
    i2c_Start();

    /* 第2步:发起控制字节,高7bit是地址,bit0是读写控制位,0表示写,1表示读 */
    i2c_SendByte(max30102_WR_address | I2C_WR);	/* 此处是写指令 */

    /* 第3步:发送ACK */
    if (i2c_WaitAck() != 0)
    {
        goto cmd_fail;	/* EEPROM器件无应答 */
    }

    /* 第4步:发送字节地址, */
    i2c_SendByte((uint8_t)uch_addr);
    if (i2c_WaitAck() != 0)
    {
        goto cmd_fail;	/* EEPROM器件无应答 */
    }


    /* 第6步:重新启动I2C总线。下面开始读取数据 */
    i2c_Start();

    /* 第7步:发起控制字节,高7bit是地址,bit0是读写控制位,0表示写,1表示读 */
    i2c_SendByte(max30102_WR_address | I2C_RD);	/* 此处是读指令 */

    /* 第8步:发送ACK */
    if (i2c_WaitAck() != 0)
    {
        goto cmd_fail;	/* EEPROM器件无应答 */
    }

    /* 第9步:读取数据 */
    {
        *puch_data = i2c_ReadByte();	/* 读1个字节 */

        i2c_NAck();	/* 最后1个字节读完后,CPU产生NACK信号(驱动SDA = 1) */
    }
    /* 发送I2C总线停止信号 */
    i2c_Stop();
    return true;	/* 执行成功 返回data值 */

cmd_fail: /* 命令执行失败后,切记发送停止信号,避免影响I2C总线上其他设备 */
    /* 发送I2C总线停止信号 */
    i2c_Stop();
    return false;
}

bool maxim_max30102_init(void)
/**
* \brief        Initialize the MAX30102
* \par          Details
*               This function initializes the MAX30102
*
* \param        None
*
* \retval       true on success
*/
{
    if(!maxim_max30102_write_reg(REG_INTR_ENABLE_1, 0xc0)) // INTR setting
        return false;
    if(!maxim_max30102_write_reg(REG_INTR_ENABLE_2, 0x00))
        return false;
    if(!maxim_max30102_write_reg(REG_FIFO_WR_PTR, 0x00)) //FIFO_WR_PTR[4:0]
        return false;
    if(!maxim_max30102_write_reg(REG_OVF_COUNTER, 0x00)) //OVF_COUNTER[4:0]
        return false;
    if(!maxim_max30102_write_reg(REG_FIFO_RD_PTR, 0x00)) //FIFO_RD_PTR[4:0]
        return false;
    if(!maxim_max30102_write_reg(REG_FIFO_CONFIG, 0x6f)) //sample avg = 8, fifo rollover=false, fifo almost full = 17
        return false;
    if(!maxim_max30102_write_reg(REG_MODE_CONFIG, 0x03))  //0x02 for Red only, 0x03 for SpO2 mode 0x07 multimode LED
        return false;
    if(!maxim_max30102_write_reg(REG_SPO2_CONFIG, 0x2F)) // SPO2_ADC range = 4096nA, SPO2 sample rate (400 Hz), LED pulseWidth (411uS)
        return false;

    if(!maxim_max30102_write_reg(REG_LED1_PA, 0x17))  //Choose value for ~ 4.5mA for LED1
        return false;
    if(!maxim_max30102_write_reg(REG_LED2_PA, 0x17))  // Choose value for ~ 4.5mA for LED2
        return false;
    if(!maxim_max30102_write_reg(REG_PILOT_PA, 0x7f))  // Choose value for ~ 25mA for Pilot LED
        return false;
    return true;
}

bool maxim_max30102_read_fifo(uint32_t *pun_red_led, uint32_t *pun_ir_led)

/**
* \brief        Read a set of samples from the MAX30102 FIFO register
* \par          Details
*               This function reads a set of samples from the MAX30102 FIFO register
*
* \param[out]   *pun_red_led   - pointer that stores the red LED reading data
* \param[out]   *pun_ir_led    - pointer that stores the IR LED reading data
*
* \retval       true on success
*/
{
    uint32_t un_temp;
    uint8_t uch_temp;
    *pun_ir_led = 0;
    *pun_red_led = 0;
    maxim_max30102_read_reg(REG_INTR_STATUS_1, &uch_temp);
    maxim_max30102_read_reg(REG_INTR_STATUS_2, &uch_temp);



    /* 第1步:发起I2C总线启动信号 */
    i2c_Start();

    /* 第2步:发起控制字节,高7bit是地址,bit0是读写控制位,0表示写,1表示读 */
    i2c_SendByte(max30102_WR_address | I2C_WR);	/* 此处是写指令 */

    /* 第3步:发送ACK */
    if (i2c_WaitAck() != 0)
    {
        printf("read fifo failed");
        goto cmd_fail;	/* EEPROM器件无应答 */
    }

    /* 第4步:发送字节地址, */
    i2c_SendByte((uint8_t)REG_FIFO_DATA);
    if (i2c_WaitAck() != 0)
    {
        goto cmd_fail;	/* EEPROM器件无应答 */
    }


    /* 第6步:重新启动I2C总线。下面开始读取数据 */
    i2c_Start();

    /* 第7步:发起控制字节,高7bit是地址,bit0是读写控制位,0表示写,1表示读 */
    i2c_SendByte(max30102_WR_address | I2C_RD);	/* 此处是读指令 */

    /* 第8步:发送ACK */
    if (i2c_WaitAck() != 0)
    {
        goto cmd_fail;	/* EEPROM器件无应答 */
    }

    un_temp = i2c_ReadByte();
    i2c_Ack();
    un_temp <<= 16;
    *pun_red_led += un_temp;
    un_temp = i2c_ReadByte();
    i2c_Ack();
    un_temp <<= 8;
    *pun_red_led += un_temp;
    un_temp = i2c_ReadByte();
    i2c_Ack();
    *pun_red_led += un_temp;

    un_temp = i2c_ReadByte();
    i2c_Ack();
    un_temp <<= 16;
    *pun_ir_led += un_temp;
    un_temp = i2c_ReadByte();
    i2c_Ack();
    un_temp <<= 8;
    *pun_ir_led += un_temp;
    un_temp = i2c_ReadByte();
    i2c_Ack();
    *pun_ir_led += un_temp;
    *pun_red_led &= 0x03FFFF; //Mask MSB [23:18]
    *pun_ir_led &= 0x03FFFF; //Mask MSB [23:18]

    /* 发送I2C总线停止信号 */
    i2c_Stop();
    return true;
cmd_fail: /* 命令执行失败后,切记发送停止信号,避免影响I2C总线上其他设备 */
    /* 发送I2C总线停止信号 */
    i2c_Stop();
    return false;
}

bool maxim_max30102_reset()
/**
* \brief        Reset the MAX30102
* \par          Details
*               This function resets the MAX30102
*
* \param        None
*
* \retval       true on success
*/
{
    if(!maxim_max30102_write_reg(REG_MODE_CONFIG, 0x40))
        return false;
    else
        return true;
}


           
//DHT11温湿度传感器部分
#include "reg52.h"
#include "LCD1602.h"
#include "intrins.h"

//typedef unsigned char uchar;
//typedef unsigned int uint;
	
//定义变量
sbit Data=P3^6;
uchar rec_dat[13];//用于保存接收到的数据组

void DHT11_delay_us(uchar n)
{
    while(--n);
}

void DHT11_delay_ms(uint z)
{
   uint i,j;
   for(i=z;i>0;i--)
      for(j=110;j>0;j--);
}

void DHT11_start()
{
   Data=1;
   DHT11_delay_us(2);
   Data=0;
   DHT11_delay_ms(20);   //延时18ms以上
   Data=1;
   DHT11_delay_us(30);
}

uchar DHT11_rec_byte()      //接收一个字节
{
   uchar i,dat=0;
  for(i=0;i<8;i++)    //从高到低依次接收8位数据
   {          
      while(!Data);   //等待50us低电平过去
      DHT11_delay_us(8);     //延时60us,如果还为高则数据为1,否则为0 
      dat<<=1;           //移位使正确接收8位数据,数据为0时直接移位
      if(Data==1)    //数据为1时,使dat加1来接收数据1
         dat+=1;
      while(Data);  //等待数据线拉低    
    }  
    return dat;
}

void DHT11_receive()      //接收40位的数据
{
    uchar R_H,R_L,T_H,T_L,RH,RL,TH,TL,revise; 
    DHT11_start();
    if(Data==0)
    {
        while(Data==0);   //等待拉高     
        DHT11_delay_us(40);  //拉高后延时80us
        R_H=DHT11_rec_byte();    //接收湿度高八位  
        R_L=DHT11_rec_byte();    //接收湿度低八位  
        T_H=DHT11_rec_byte();    //接收温度高八位  
        T_L=DHT11_rec_byte();    //接收温度低八位
        revise=DHT11_rec_byte(); //接收校正位

        DHT11_delay_us(25);    //结束

        if((R_H+R_L+T_H+T_L)==revise)      //校正
        {
            RH=R_H;
            RL=R_L;
            TH=T_H;
            TL=T_L;
        } 
		
	
        /*数据处理,方便显示*/
        rec_dat[0]=RH/10+'0';
        rec_dat[1]=(RH%10)+'0';
		rec_dat[2]='%';
        rec_dat[3]='R';
        rec_dat[4]='H';
        rec_dat[5]=' ';
		rec_dat[6]=' ';
        rec_dat[7]=(TH/10)+'0';
        rec_dat[8]=(TH%10)+'0';
		rec_dat[9]='^';
        rec_dat[10]='C';
    }
}

void main()
{
	//使用lcd1602显示数据
	DHT11_receive();
	lcd1602(rec_dat);
}
           
// MQ-2烟雾传感器

unsigned char GetYanWuValue(void)
{
		unsigned int sum=0;
		unsigned char m,value=0;
		for(m=0;m<20;m++)			//读50次AD值
			sum = adc0832(0)+sum;		//读到的AD值,将读到的数据累加到sum
		value=(unsigned char)(sum/20);				//跳出上面的for循环后,将累加的总数除以50得到平均值value
	
		if(value > ADC_Zero) 
				value = value - ADC_Zero;              //首先减去零点漂移
			else
				value = 0;
	
		return value;

}


           

The full code can be collected for free by joining the group.

The learning road of embedded IoT is very long, and many people miss out on high-paying offers because the learning route is wrong or the learning content is not professional enough. But don't worry, I've put together a list of more than 150 GB of learning resources for you, basically covering everything about embedded IoT learning. Click the link below to receive learning resources for 0 yuan, making your learning road smoother! Remember to like, follow, favorite, and retweet!

Click here to find the assistant 0 yuan to receive: scan the code to enter the group to receive the information

Human health monitoring system based on single-chip STM32 - single-chip embedded Internet of Things
Human health monitoring system based on single-chip STM32 - single-chip embedded Internet of Things

Read on