Microcontroller development | Design of baby sleep monitoring system based on microcontroller

Author's homepage: Programming Thousand Paper Cranes

About the author: Java, front-end, and Python have been developed for many years, and have worked as a senior engineer, project manager, and architect

Main content: Java project development, Python project development, university data and AI project development, MCU project design, interview technology arrangement, latest technology sharing

Favorites, likes, don't get lost, it's good to follow the author

Get the source code at the end of the article

Item number: BS-DPJ-003

Foreword:

Babies sleep most of the day, how to monitor the baby's sleep, comfort the baby in time, and how to solve the baby's wetness problem are the most concerned issues for new mothers. Most families will choose convenient diapers, but diapers are not only expensive, but also highly absorbent. If they are not replaced in time, skin diseases such as rashes are likely to develop, which is also a threat to the baby's body; the baby wakes up It will cry, and the parents did not hear it in time, causing the baby to be left alone for a long time. Therefore, designing a sleep monitoring system suitable for babies is very helpful for novice parents. This thesis uses STC89C52 single-chip microcomputer as the core, adopts voice control, voice broadcast, humidity acquisition circuit to collect data of various scenes, and realizes real-time monitoring of children through LED lights, voice broadcast and other methods.

1. Environmental introduction

Language environment: C language development

 

Development technology: 51 single-chip microcomputer; sound control circuit; voice broadcast; humidity collection; liquid crystal display

2. Project introduction

Sleep is an important physiological process of the human body, and its quality is directly related to the health of the human body. In medicine, people's understanding of the structure and process of sleep is mainly achieved through polysomnography and multi-channel sleep recording. Specifically, it uses electroencephalography (EEG) to monitor sleepers' brain waves to predict sleep conditions. However, since medical devices and technologies are mainly used in hospitals and scientific research institutes, their popularity is limited by high costs. In recent years, with the rapid development of sensing technology, the development of micro-detectors has also been continuously improved. At present, the most common one is to use an actigraph for monitoring, usually using sensors in three directions to obtain the movements of various parts of the human body, such as Fitbit, JawboneUP, WakeMate, YawnLog, etc. are all portable smart phones currently on the market . The analysis software can analyze the energy consumption, sleep quality, wake-up time, sleep efficiency, etc. of the human body based on the collected information.

At the same time, a large number of smart phone-based sleep management software (SleepAsAndroid, Sleep Cycle) record the sleep behavior by calling the acceleration sensor in the smart hardware, so that the quality of sleep can be monitored only by using smart hardware. the goal of. However, this type of sensor still has some drawbacks, such as: unclear behavior recognition and high false recognition rate.

In today's society, work pressure is increasing, and women have to take care of work and family at the same time, especially new mothers, who have to take care of babies and take care of housework, which makes new mothers very anxious. Babies sleep most of the day, and how to monitor their sleep, how to soothe them, and how to troubleshoot wetness are all concerns for busy new mothers. Most families will choose to use portable diapers, but diapers are not only expensive, but also highly absorbent. If they are not replaced in time, it is likely to cause rashes on the baby's skin. Cotton diapers are hygienic and comfortable, and they need to be replaced in time. Most of the urine humidity testing equipment on the market is single, which is easy to cause false positives. Therefore, when the baby is sleeping, it is very important for novice parents to know whether the baby has wetted the bed.

This thesis is mainly aimed at the design of the baby sleep monitoring system with single chip microcomputer as the core. When the baby is monitored during sleep, it will send an alarm when the baby is wet or crying because it needs to be tended.

First of all, after referring to the relevant data, the whole scheme and function are determined, and according to the design requirements, the circuit design and hardware construction are completed, and then the control software of the single-chip microcomputer is written, and finally the actual welding and experiment are carried out.

The system mainly includes: 51 single-chip minimum system, LED indicator light, ULN2003 driving stepper motor, function keys, WT588D playback, sound acquisition module, humidity detection, LCD display current information and status, sound sensor to detect baby crying, humidity sensor detection Baby bedwetting, bedwetting detection, LED light on, sound broadcast. The specific is this:

1) Consult relevant data and understand the basic principles of 51 microprocessors;

2) Understand the application of 51 microprocessors in infant sleep monitoring;

3) Completed the circuit design of the infant sleep monitoring system with single-chip microcomputer as the core;

4) Carry out related control with C language;

5) Debug the program to make it meet the design requirements;

6) Welding a piece of hardware circuit for detecting and analyzing baby sleep monitoring system;

7) Complete the graduation design report.

2.1 Overall system block diagram

The overall design block diagram of this scheme is shown in Figure 2-1.

Figure 2-1 System block diagram

Figure 2-1 is the system configuration of this system, as can be seen from the figure, it includes nine components:

1) Microprocessor:

Because STC89C52 is a low power consumption, high-performance COMS 8-bit microcontroller, it has 8K programmable Flash memory in its system. The system takes STC89C52 series microprocessor as the core, and carries out corresponding data processing and control according to the collected data.

2) Voice control circuit:

This system is mainly used to collect the sound exceeding a certain decibel to meet the requirement of starting the stepper motor.

3) Humidity acquisition circuit:

This circuit mainly completes the measurement of each temperature and sends it to the single chip microcomputer for processing.

4) Voice acquisition circuit:

This line is used to determine if the baby is crying.

5) Stepping motor:

This module enables the rocking of the crib.

6) LED lights:

In this system, the LED light will emit light in time, allowing the nannies to take care of the baby in time to check whether the baby has wet the bed.

7) Voice broadcast:

WT588D will automatically alarm in this system to remind the nanny to pay attention to whether the baby has wet the bed, and can put the baby to sleep in time.

8) LCD1602 module:

This system adopts DuPont line to connect with single-chip microcomputer, and the single-chip microcomputer collects relevant signals and transmits them to the liquid crystal display to improve its brightness.

9) System power supply circuit: provide a stable DC regulated power supply for the work of the alarm system.

2.2 System function design

After the system starts, it will deal with the following situations accordingly:

1. Whenever the baby horn cries, the motor will automatically swing by the audio control circuit, and the voice module will automatically play light songs to calm the baby;

2. The voice control module can obtain the crying situation of the baby in real time;

3. Whenever a child urinates and the quilt is wet, the signal from the humidity sensor triggers an automatic alarm, voice prompts whether the bed is wet, and the LED light is on;

4. ULN2003 is used to drive the stepping motor. When the baby needs to be coaxed, the motor can be controlled to rotate left and right to make the baby quiet.

5. The button is used for 3 different settings, which is convenient for quick processing of various situations.

 

Three, system display

overall display

System test: When the humidity detector detects that the baby wets the bed, it will make a voice broadcast + LCD light flashing display

 

Fourth, the core code display

#include <reg52.h>			 //调用单片机头文件
#include <intrins.h>
#include "lcd1602.h"
#include "StepMotor.h"

#define uchar unsigned char  //无符号字符型 宏定义	变量范围0~255
#define uint  unsigned int	 //无符号整型 宏定义	变量范围0~65535

#include "WT588D.h"

//按键引脚定义
sbit KEY1 = P3^5;
sbit KEY2 = P3^6;
sbit KEY3 = P3^7;

sbit ShiDu = P1^0;//湿度传感器
sbit LED = P1^1;
sbit Voice = P1^2;//声音传感器

bit openFlag = 0;//电机开启标志 
bit Mode = 0;//0是自动模式,1是手动模式

uint DJ_TIME = 0;//电机开启时间

/*********************定时器1初始化******************/
void time_init()	  
{
	TMOD |= 0X10;	  
  TH1=0x4c;//50ms
  TL1=0x00; 	
	ET1 = 1;
	TR1 = 1;//开启定时
	EA  = 1;	 	  //开总中断
}

void keyscan()
{
		if(KEY1 == 0)//切换键按下
		{
				delay_ms(10);
				if(KEY1 == 0)
				{
						while(!KEY1);//等待按键松开
						Mode = !Mode;
            if(Mode==0)lcd_write_str(0, 1, "MODE: ZIDONG    ");			
            else lcd_write_str(0, 1, "MODE: SHOUDONG  ");	
            openFlag = 0;					
				}
		}
    if(Mode==1)//手动模式
		{
				if(KEY2 == 0)//手动开关键按下
				{
						delay_ms(10);
						if(KEY2 == 0)
						{
								while(!KEY2);
						
								openFlag = 1;
						}
				}
				if(KEY3 == 0)//手动开关键按下
				{
						delay_ms(10);
						if(KEY3 == 0)
						{
								while(!KEY3);
						
								openFlag = 0;
						}
				}
		}
}

void motoRotate()//电机处理
{
	  static uint djcount=0;
	  static bit flag = 0;

	  if(flag == 0)
		{
			  djcount++;
				if(djcount < 30)
				{
						MotorCW();//正转
				}
				else
				{
						if(djcount < 130)
						{
								MotorStop();//电机停止
						}
						else
						{
								flag = 1;
							  djcount = 130;
						}
				}
		}
    else
		{
			  djcount--;
				if(djcount > 100)
				{
						MotorCCW();//电机反转
				}
				else
				{
					  if(djcount<=0){flag = 0;djcount=0;}
						MotorStop();//电机停止
				}
		}
}

void main()
{
	  uint sy_count1 = 0;
	  uint sy_count2 = 0;
	  uint yuyin = 0;
	  bit flag = 0;
	
		time_init();//定时器初始化
		lcd_init();//1602初始化
		lcd_write_str(0, 0, "STATE: CLOSE    ");
    lcd_write_str(0, 1, "MODE: ZIDONG    ");

		while(1)
		{
			  keyscan();
			  if(Mode == 0)//在自动模式下
				{
						if(Voice == 0)//检测到有声音
						{
								if(sy_count1++ > 10)//检测哭声是否延续
								{
										DJ_TIME = 60;//电机开启时间1分钟
										openFlag = 1;//电机开启
									  sy_count1 = 0;
									  if(ShiDu==0)Line_1A(1);//播报歌曲
								}
						}
						else
						{
								if(sy_count2++ > 200)
								{
										sy_count2 = 0;
									  sy_count1 = 0;
								}
						}
				}
        if(ShiDu==1)//检测到尿不湿湿了
				{
						LED = 0;
					  if(flag == 0)//只播报一次
						{
								flag = 1;
							  Line_1A(0);//播报
							  yuyin = 0;
						}
						if(flag==1)
						{
								if(yuyin++ > 400)
								{
										yuyin = 0;
									  Line_1A(0);//播报
								}
						}
				}
				else
				{
						LED = 1;flag = 0;
				}
			  if(openFlag==1)//电机开启
				{
					  lcd_write_str(0, 0, "STATE: OPEN ");
						motoRotate(); 
				}else 
				{
					  lcd_write_str(0, 0, "STATE: CLOSE");
						MotorStop();//电机关闭
				}
			  
			  delay_ms(1);
		}
}


void zd1() interrupt 3
{
	  static uchar cnt1=0;
		TH1=0x4c;//50ms
		TL1=0x00; 
	
		if(cnt1++ >= 20)//1s
		{
				cnt1 = 0;
        if(DJ_TIME > 0)
				{
						DJ_TIME--;
				}
				else
				{
						if(Mode == 0)openFlag=0;
				}
		}
}

#include <reg52.h>
#include <intrins.h>
#include "lcd1602.h"

sbit RS = P2^5;//数据命令引脚
sbit RW = P2^6;//读写引脚
sbit E = P2^7;//使能引脚

#define DataPort P0//1602并行通信口

void delay_ms(unsigned int ms)//延时毫秒函数
{
	unsigned char i, j;
		do
		{
				_nop_();
				i = 2;
				j = 199;
				do
				{
					while (--j);
				} while (--i);
		}while(--ms);
}

void lcd_clear(void)//清屏函数
{
     lcd_write_com(0x01);
		delay_ms(5);
}

void lcd_write_com(unsigned char byte)//写命令
{
		RS = 0;
	  RW = 0;
	  E = 1;
	  DataPort = byte;
	  _nop_();
	  _nop_();
	  delay_ms(1);
	  E = 0; 
}

void lcd_write_data(unsigned char byte)//写数据
{
	  RS = 1;
	  RW = 0;
	  E = 1;
	  DataPort = byte;
	  _nop_();
	  _nop_();
	  delay_ms(1);
	  E = 0;
}

void lcd_init()//1602初始化
{
	  delay_ms(5);
	  lcd_write_com(0x38);//设置16*2显示,5*7点阵,8位数据接口
	  delay_ms(5);
	  lcd_write_com(0x38);//设置16*2显示,5*7点阵,8位数据接口
	  delay_ms(5);
	  lcd_write_com(0x38);//设置16*2显示,5*7点阵,8位数据接口
	  delay_ms(5);
	  lcd_write_com(0x08); //关闭显示
	  delay_ms(5);
	  lcd_write_com(0x01);//清屏指令
	  delay_ms(5);
	  lcd_write_com(0x06);
	  delay_ms(5);
	  lcd_write_com(0x0c);
	  delay_ms(5);
	  
}

void lcd_write_char(unsigned char x,unsigned char y,unsigned char byte)//在某一位置显示一字符
{
	  if(0 == y)
		{
			lcd_write_com(0x80 + x);//第一行
		}
	  else if(1 == y)
		{
			lcd_write_com(0x80 + 0x40 + x);//第二行
		}
		lcd_write_data(byte);//显示数据
}

void lcd_write_str(unsigned char x, unsigned char y, unsigned char *s)//在某一位置显示一字符串
{
	 if(0 == y)
		{
			lcd_write_com(0x80 + x);//第一行
		}
	  else
		{
			lcd_write_com(0x80 + 0x40 + x);//第二行
		}
		
		while(*s)//判断是否检测到结尾符 
		{
			lcd_write_data(*s);//显示数据
			s++;//指针加1 
		}
		
}



V. Project Summary

This paper adopts various research methods such as information learning method, literature research method and experience method, including:

(1) Information learning method: understand and practice the baby's sleep monitoring function, and combine the current actual situation to develop the baby's sleep monitoring system.

(2) Literature research: The domestic and foreign research results on infant sleep monitoring design were collected, sorted out, and systematically analyzed.

(3) Empirical method: During system design, problems such as code errors often occur.

Guess you like

Origin blog.csdn.net/BS009/article/details/132299833