首页 > 分享 > STM32项目分享:智能宠物项圈系统

STM32项目分享:智能宠物项圈系统

目录 

一、前言

 二、项目简介

1.功能详解

2.主要器件

三、原理图设计

四、PCB硬件设计

PCB图 

五、程序设计 

六、实验效果 

 七、包含内容

  项目分享

一、前言

项目成品图片:

哔哩哔哩视频链接:

https://www.bilibili.com/video/BV1PXBsBBEF7/?spm_id_from=333.337.search-card.all.click

(资料分享见文末) 

 二、项目简介

1.功能详解

基于STM32的智能宠物项圈系统

功能如下:

环境采集:光照强度传感器采集环境光照强度、心率血氧传感器检测宠物的心率血氧数据、温度传感器检测宠物的体温数据、GPS模块检测宠物的位置信息显示功能:环境数据显示在OLED屏幕上模式切换:通过按键可以切换手动模式和自动模式自动模式:光照小于阈值开启LED照明灯、宠物心率/血氧/体温超过阈值时蜂鸣器报警提醒;单片机与手机蓝牙第一次连接后断开连接(单片机端检测不到APP循环发送的信息)时语音播报“小宠物,快回到主人身边”手动模式:手动模式下可通过按键控制LED照明灯和蜂鸣器报警阈值调节:可以通过按键进入系统设置界面,可设置心率、血氧和体温的光照的阈值蓝牙APP:通过蓝牙APP可接收宠物心率、血氧、体温、环境光照强度和GPS经纬度信息数据;可以通过按钮完成控制指令下发 2.主要器件 STM32F103C8T6最小系统板OLED显示屏(4针IIC协议)MAX30102心率血氧传感器DS18B20温度传感器GPS传感器BT04A(蓝牙模块)JR6001语音模块蜂鸣器LED灯

三、原理图设计

四、PCB硬件设计

PCB图 

五、程序设计 

#include "stm32f10x.h"

#include "led.h"

#include "beep.h"

#include "usart.h"

#include "delay.h"

#include "oled.h"

#include "key.h"

#include "Modules.h"

#include "adcx.h"

#include "flash.h"

#include "usart2.h"

#include "usart3.h"

#include "TIM2.h"

#include "timer.h"

#include "GPS.h"

#include "ds18b20.h"

#include "max30102_read.h"

#include "myiic.h"

#define BT_STATE_INIT 0

#define BT_STATE_CONNECTED 1

#define BT_STATE_DISCONNECTED 2

typedef struct {

uint32_t last_ack_time;

uint32_t last_disconnect_time;

uint8_t state;

uint8_t timeout_cnt;

uint32_t last_heartbeat_time;

} BT_Manager;

#define KEY_Long111

#define KEY_11

#define KEY_22

#define KEY_33

#define KEY_44

#define FLASH_START_ADDR0x0801f000

#define HEARTBEAT_CMD "BT_HEARTrn"

#define HEARTBEAT_ACK "1"

#define HEARTBEAT_INTERVAL 1000

#define BT_TIMEOUT_MS 10000

SensorModules sensorData;

SensorThresholdValue Sensorthreshold;

DriveModules driveData;

uint8_t mode = 1;

u8 dakai;

u8 Flag_dakai;

uint8_t is_secondary_menu = 0;

uint8_t secondary_pos = 1;

uint8_t secondary_type = 0;

extern float gps_lat_decimal;

extern float gps_lon_decimal;

static uint8_t count_m = 1;

static uint8_t count_s = 1;

uint8_t auto_page = 1;

extern unsigned char p[16];

BT_Manager bt_manager;

static uint8_t bt_first_connect_disconnect = 0;

static uint8_t bt_has_received_ack = 0;

static uint8_t first_enter_auto_page2 = 0;

enum

{

AUTO_MODE = 1,

MANUAL_MODE,

SETTINGS_MODE

} MODE_PAGES;

int main(void)

{

SystemInit();

delay_init(72);

TIM2_Init(72-1, 1000-1);

ADCX_Init();

LED_Init();

BEEP_Init();

uart_init(9600);

USART2_Init();

USART3_Config();

Key_Init();

DS18B20_Init();

OLED_Init();

GPS_Init();

Init_MAX30102();

srand((unsigned int)delay_get_tick());

uint32_t current_time = delay_get_tick();

bt_manager.last_ack_time = current_time;

bt_manager.last_disconnect_time = current_time;

bt_manager.state = BT_STATE_INIT;

bt_manager.timeout_cnt = 0;

bt_manager.last_heartbeat_time = 0;

bt_first_connect_disconnect = 0;

bt_has_received_ack = 0;

delay_ms(100);

FLASH_ReadThreshold();

OLED_Clear();

static uint8_t last_mode = 0;

static uint32_t last_sensor_time = 0;

static uint32_t last_display_time = 0;

if (Sensorthreshold.tempValue > 40 || Sensorthreshold.hrAvgValue > 120 ||

Sensorthreshold.spo2AvgValue > 100 || Sensorthreshold.luxValue > 500)

{

FLASH_W(FLASH_START_ADDR, 30, 95, 98, 100);

FLASH_ReadThreshold();

}

printf("系统启动,蓝牙初始状态: 初始化n");

USART3_SendString("AF:30");

delay_ms(200);

USART3_SendString("A7:00001");

delay_ms(200);

while (1)

{

uint32_t current_time = delay_get_tick();

USART2_ProcessCmd();

BT_Check_State_Simple();

if(current_time - last_sensor_time > 100) {

SensorScan();

last_sensor_time = current_time;

}

uint8_t current_key_num = KeyNum;

if(current_key_num != 0)

{

switch(mode)

{

case AUTO_MODE:

if(current_key_num == KEY_1)

{

mode = MANUAL_MODE;

count_m = 1;

driveData.LED_Flag = 0;

driveData.BEEP_Flag = 0;

KeyNum = 0;

}

else if(current_key_num == KEY_Long1)

{

mode = SETTINGS_MODE;

count_s = 1;

KeyNum = 0;

}

break;

case MANUAL_MODE:

if(current_key_num == KEY_1)

{

mode = AUTO_MODE;

auto_page = 1;

KeyNum = 0;

}

break;

case SETTINGS_MODE:

break;

}

}

if(last_mode != mode)

{

OLED_Clear();

last_mode = mode;

switch(mode)

{

case AUTO_MODE:

OLED_autoPage1();

break;

case MANUAL_MODE:

OLED_manualPage1();

break;

case SETTINGS_MODE:

OLED_settingsPage1();

break;

}

OLED_Refresh();

}

switch(mode)

{

case AUTO_MODE:

{

uint8_t curr_auto_page = SetAuto();

if(curr_auto_page == 1)

{

SensorDataDisplay1();

}

else

{

SensorDataDisplay2();

}

AutoControl();

Control_Manager();

break;

}

case MANUAL_MODE:

{

static uint8_t manual_page_initialized = 0;

static uint8_t last_manual_count = 0;

static uint8_t last_LED_Flag = 0;

static uint8_t last_BEEP_Flag = 0;

static uint8_t force_refresh = 0;

if(last_mode != mode)

{

manual_page_initialized = 0;

last_manual_count = 0;

last_LED_Flag = driveData.LED_Flag;

last_BEEP_Flag = driveData.BEEP_Flag;

force_refresh = 1;

count_m = 1;

driveData.LED_Flag = 0;

driveData.BEEP_Flag = 0;

}

uint8_t current_manual_count = SetManual();

uint8_t need_refresh = 0;

if(driveData.LED_Flag != last_LED_Flag || driveData.BEEP_Flag != last_BEEP_Flag)

{

need_refresh = 1;

last_LED_Flag = driveData.LED_Flag;

last_BEEP_Flag = driveData.BEEP_Flag;

}

if(!manual_page_initialized || current_manual_count != last_manual_count || need_refresh || force_refresh)

{

OLED_manualPage1();

OLED_manualOption(current_manual_count);

ManualSettingsDisplay1();

manual_page_initialized = 1;

last_manual_count = current_manual_count;

force_refresh = 0;

OLED_Refresh();

}

if(current_key_num != 0)

{

ManualControl(current_manual_count);

OLED_manualPage1();

OLED_manualOption(current_manual_count);

ManualSettingsDisplay1();

OLED_Refresh();

KeyNum = 0;

}

OLED_manualPage1();

OLED_manualOption(current_manual_count);

ManualSettingsDisplay1();

Control_Manager();

break;

}

case SETTINGS_MODE:

{

static uint8_t is_threshold_page_inited = 0;

uint8_t curr_count_s = SetSelection();

if(current_key_num != 0)

{

if (is_secondary_menu == 1)

{

if (current_key_num == KEY_2 || current_key_num == KEY_3 || current_key_num == KEY_4)

{

OLED_Refresh();

KeyNum = 0;

}

else if (current_key_num == KEY_1)

{

is_secondary_menu = 0;

secondary_pos = 1;

OLED_Clear();

OLED_settingsPage1();

SettingsThresholdDisplay1();

OLED_settingsOption(curr_count_s);

OLED_Refresh();

KeyNum = 0;

}

}

else

{

if (current_key_num == KEY_3 || current_key_num == KEY_4)

{

ThresholdSettings(curr_count_s);

SettingsThresholdDisplay1();

OLED_Refresh();

KeyNum = 0;

}

else if (current_key_num == KEY_1)

{

mode = AUTO_MODE;

is_threshold_page_inited = 0;

FLASH_W(FLASH_START_ADDR, Sensorthreshold.tempValue, Sensorthreshold.hrAvgValue,

Sensorthreshold.spo2AvgValue, Sensorthreshold.luxValue);

KeyNum = 0;

}

}

}

if (is_secondary_menu == 1)

{

}

else

{

if (curr_count_s >= 1 && curr_count_s <= 4)

{

if (is_threshold_page_inited == 0)

{

OLED_settingsPage1();

is_threshold_page_inited = 1;

}

}

OLED_settingsOption(curr_count_s);

SettingsThresholdDisplay1();

}

break;

}

}

if(current_time - last_display_time > 50) {

OLED_Refresh();

last_display_time = current_time;

}

}

}

cpp

运行

六、实验效果 

 七、包含内容

  项目分享

相关知识

STM32项目分享:智能宠物喂食系统(升级版)
基于STM32的智能宠物项圈系统设计
STM32项目分享:智能宠物喂食系统
毕设项目分享 stm32智能鱼缸监控投喂系统(源码+硬件+论文)
基于STM32单片机的宠物智能项圈设计资料下载:让爱宠生活更智能
【亲测免费】 基于STM32单片机的宠物智能项圈设计资料下载
基于STM32单片机的宠物智能项圈设计
STM32智能鱼缸系统设计与实现(毕业设计)
STM32驱动的宠物智能项圈:功能与技术选型
基于STM32单片机的智能宠物系统的未来发展

网址: STM32项目分享:智能宠物项圈系统 https://m.mcbbbk.com/newsview1341704.html

所属分类:萌宠日常
上一篇: 派得狗粮:给你的爱犬带来牛肉美味
下一篇: 丰收在即,别在最后关头功亏一篑