0
  • 聊天消息
  • 系统消息
  • 评论与回复
登录后你可以
  • 下载海量资料
  • 学习在线课程
  • 观看技术视频
  • 写文章/发帖/加入社区
会员中心
创作中心

完善资料让更多小伙伴认识你,还能领取20积分哦,立即完善>

3天内不再提示

STM32项目分享:智能语音台灯(机智云)

机智云 2025-07-24 18:03 次阅读
加入交流群
微信小助手二维码

扫码添加小助手

加入工程师交流群

项目成品图片:


81ac6b46-6875-11f0-a486-92fbcf53809c.jpg


01

项目简介


1.功能详解


STM32智能语音台灯(机智云)

功能如下:


STM32F103C8T6单片机作为主控单元

按键切换模式,支持自动/手动两种模式

光敏电阻采集光照强度,超声波传感器采集坐姿距离,所有参数显示在OLED

智能模式:自动识别有人开灯,并根据环境光强度控制灯的亮度

按键模式:按键手动调节灯亮度

语音模式:通过语音识别控制台灯调光与模式切换

坐姿报警:超声波距离报警

机智云APP:通过APP可查看数据,以及控制下发



2.材料清单

STM32F103C8T6单片机

OLED 屏幕

DHT11温湿度传感器

光电红外传感器

光敏传感器

SNR8016语音模块

HC-SR04超声波传感器

ESP8266模块(WIFI)

有源蜂鸣器

大功率LED灯模块


02


原理图设计


81ba808c-6875-11f0-a486-92fbcf53809c.png


03

PCB硬件设计


PCB图

81d0b442-6875-11f0-a486-92fbcf53809c.png81ebf130-6875-11f0-a486-92fbcf53809c.png


04

程序设计


#include"stm32f10x.h" // Device header#include"adcx.h"#include"ldr.h"#include"oled.h"#include"dht11.h"#include"pwm.h"#include"led.h"#include"key.h"#include"tim2.h" #include"tim3.h" #include"hc_sr501.h"#include"hc_sr04.h"#include"sensormodules.h"#include"usart.h"#include"gizwits_product.h"#include"myrtc.h"#include"flash.h"#include"iwdg.h"#include"usart3.h"
#defineKEY_Long111
#defineKEY_11#defineKEY_22#defineKEY_33#defineKEY_44
#defineFLASH_START_ADDR0x0801f000//写入的起始地址
uint8_thc501;//存储人体信号uint8_tsystemModel =0;//存储系统当前模式
uint8_thour,minute,second;//时 分 秒uint8_tmenu =1;//显示菜单变量


SensorModules sensorData;//声明传感器数据结构体变量SensorThresholdValue Sensorthreshold;//声明传感器阈值结构体变量
enum{display_page =1,settingsPage,timeSettingsPage
}MenuPages;
/** * @brief 显示主页面固定内容 * @param 无 * @retval 无 */voidOLED_Menu(void){//显示“Time:”OLED_ShowString(1,1,"Time");OLED_ShowChar(1,5,':');
//显示“温度:”OLED_ShowChinese(2,1,0);OLED_ShowChinese(2,2,1);OLED_ShowChar(2,5,':');//显示“湿度:”OLED_ShowChinese(2,5,2);OLED_ShowChinese(2,6,1);OLED_ShowChar(2,13,':');
//显示“光强:”OLED_ShowChinese(3,1,4);OLED_ShowChinese(3,2,5);OLED_ShowChar(3,5,':');//显示“距离:”OLED_ShowChinese(3,5,17);OLED_ShowChinese(3,6,18);OLED_ShowChar(3,13,':');
//显示“亮度:”OLED_ShowChinese(4,1,6);OLED_ShowChinese(4,2,1);OLED_ShowChar(4,5,':');}
/** * @brief 显示主页面的传感器数据等信息 * @param 无 * @retval 无 */voidOLED_Menu_SensorData(void){//显示时间数据OLED_ShowNum(1,6,MyRTC_Time[3],2);OLED_ShowChar(1,8,':');OLED_ShowNum(1,9,MyRTC_Time[4],2);OLED_ShowChar(1,11,':');OLED_ShowNum(1,12,MyRTC_Time[5],2);
//显示温度数据OLED_ShowNum(2,6, sensorData.temp,2);OLED_ShowChar(2,8,'C');
//显示湿度数据OLED_ShowNum(2,14, sensorData.humi,2);OLED_ShowChar(2,16,'%');
//显示光强数据OLED_ShowNum(3,6, sensorData.lux,3);
//显示距离数据OLED_ShowNum(3,14, sensorData.distance,3);
//显示亮度等级OLED_ShowNum(4,6, ledDutyRatio,3);OLED_ShowChar(4,9,'%');
//显示是否有人if(sensorData.people){OLED_ShowChinese(1,8,19);}else{OLED_ShowString(1,15," ");}
//显示系统当前模式 手动模式 or 自动模式if(systemModel){//显示“自动”OLED_ShowChinese(4,7,9);OLED_ShowChinese(4,8,10);}else{//显示“手动”OLED_ShowChinese(4,7,11);OLED_ShowChinese(4,8,12);}}
/** * @brief 显示系统设置界面 * @param 无 * @retval 无 */voidOLED_SetInterfacevoid(void){//显示“系统设置界面”OLED_ShowChinese(1,2,20);OLED_ShowChinese(1,3,21);OLED_ShowChinese(1,4,22);OLED_ShowChinese(1,5,23);OLED_ShowChinese(1,6,24);OLED_ShowChinese(1,7,25);
//显示“系统时间”OLED_ShowChinese(2,2,20);OLED_ShowChinese(2,3,21);OLED_ShowChinese(2,4,28);OLED_ShowChinese(2,5,29);OLED_ShowChar(2,11,':');OLED_ShowString(2,13,"xxx");
//显示“光照阈值”OLED_ShowChinese(3,2,4);OLED_ShowChinese(3,3,5);OLED_ShowChinese(3,4,26);OLED_ShowChinese(3,5,27);OLED_ShowChar(3,11,':');
//显示”距离阈值“OLED_ShowChinese(4,2,17);OLED_ShowChinese(4,3,18);OLED_ShowChinese(4,4,26);OLED_ShowChinese(4,5,27);OLED_ShowChar(4,11,':');
//显示光照阈值数值OLED_ShowNum(3,13, Sensorthreshold.Illumination_threshold,3);
//显示距离阈值数值OLED_ShowNum(4,14, Sensorthreshold.Distance_threshold,2);}
/** * @brief 记录阈值界面下按KEY1的次数 * @param 无 * @retval 返回次数 */uint8_tSetSelection(void){staticuint8_tcount =1;if(KeyNum == KEY_1){KeyNum =0;count++;if(count >=4){count =1;}}returncount;}
/** * @brief 显示阈值界面的选择符号 * @param num 为显示的位置 * @retval 无 */voidOLED_Option(uint8_tnum){switch(num){case1:OLED_ShowChar(1,1,' ');OLED_ShowChar(2,1,'>');OLED_ShowChar(3,1,' ');OLED_ShowChar(4,1,' ');break;case2:OLED_ShowChar(1,1,' ');OLED_ShowChar(2,1,' ');OLED_ShowChar(3,1,'>');OLED_ShowChar(4,1,' ');break;case3:OLED_ShowChar(1,1,' ');OLED_ShowChar(2,1,' ');OLED_ShowChar(3,1,' ');OLED_ShowChar(4,1,'>');break;default:break;}}
/** * @brief 显示时间调节界面的选择符号 * @param num 为显示的位置 * @retval 无 */voidOLED_Time_Option(u8 num){switch(num){case1:
OLED_ShowChar(2,6,'v');OLED_ShowChar(2,9,' ');OLED_ShowChar(2,12,' ');break;case2:OLED_ShowChar(2,6,' ');OLED_ShowChar(2,9,'v');OLED_ShowChar(2,12,' ');break;case3:OLED_ShowChar(2,6,' ');OLED_ShowChar(2,9,' ');OLED_ShowChar(2,12,'v');break;default:break;}}
/** * @brief 显示时间调节界面的内容 * @param 无 * @retval 无 */voidOLED_ThresholdTime(void){//系统时间:OLED_ShowChinese(1,3,20);OLED_ShowChinese(1,4,21);OLED_ShowChinese(1,5,28);OLED_ShowChinese(1,6,29);OLED_ShowChar(1,13,':');
OLED_ShowNum(3,5,hour,2);OLED_ShowChar(3,7,':');OLED_ShowNum(3,8,minute,2);OLED_ShowChar(3,10,':');OLED_ShowNum(3,11,second,2);}
/** * @brief 对阈值界面的传感器阈值进行修改 * @param num 为当前用户需要更改的传感器阈值位置 * @retval 无 */voidThresholdModification(uint8_tnum){switch(num){case1:if(KeyNum == KEY_3){KeyNum =0;OLED_Clear();menu = timeSettingsPage;
hour = MyRTC_Time[3];minute = MyRTC_Time[4];second = MyRTC_Time[5];}elseif(KeyNum == KEY_4){KeyNum =0;OLED_Clear();menu = timeSettingsPage;
hour = MyRTC_Time[3];minute = MyRTC_Time[4];second = MyRTC_Time[5];}break;
case2:if(KeyNum == KEY_3){KeyNum =0;Sensorthreshold.Illumination_threshold +=10;if(Sensorthreshold.Illumination_threshold >999){Sensorthreshold.Illumination_threshold =1;}}elseif(KeyNum == KEY_4){KeyNum =0;Sensorthreshold.Illumination_threshold -=10;if(Sensorthreshold.Illumination_threshold < 1){Sensorthreshold.Illumination_threshold = 999;}}break;case 3:if (KeyNum == KEY_3){KeyNum = 0;Sensorthreshold.Distance_threshold++;if (Sensorthreshold.Distance_threshold >99){Sensorthreshold.Distance_threshold =1;}}elseif(KeyNum == KEY_4){KeyNum =0;Sensorthreshold.Distance_threshold--;if(Sensorthreshold.Distance_threshold < 1){Sensorthreshold.Distance_threshold = 99;}}break;default: break;}}
/** * @brief 对系统时间进行修改 * @param num 为当前用户需要更改的时分秒位置 * @retval 无 */voidTimeModification(uint8_tnum){switch(num){case1:if(KeyNum == KEY_3){KeyNum =0;hour++;if(hour >24){hour =0;}}elseif(KeyNum == KEY_4){KeyNum =0;hour --;if(hour >24){hour =24;}}break;
case2:if(KeyNum == KEY_3){KeyNum =0;minute++;if(minute >60){minute =0;}}elseif(KeyNum == KEY_4){KeyNum =0;minute --;if(minute >60){minute =60;}}break;case3:if(KeyNum == KEY_3){KeyNum =0;second++;if(second >60){second =0;}}elseif(KeyNum == KEY_4){KeyNum =0;second --;if(second >60){second =60;}}break;default:break;}}
/** * @brief 获取语音模块数据 * @param 无 * @retval 无 */voidAsrpro(void){if(Usart3_RxFlag ==1){Usart3_RxFlag =0;switch(Usart3_RxPacket[3]){/*控制开关灯*/case1:if(!systemModel){if(Usart3_RxPacket[4]){ledDutyRatio =100;TIM_SetCompare1(TIM1, ledDutyRatio);}else{ledDutyRatio =0;TIM_SetCompare1(TIM1, ledDutyRatio);}}break;
/*控制灯暗一点或亮一点*/case2:if(!systemModel){if(Usart3_RxPacket[4]){ledDutyRatio +=25;if(ledDutyRatio >100){ledDutyRatio =100;}TIM_SetCompare1(TIM1, ledDutyRatio);}else{ledDutyRatio -=25;if(ledDutyRatio >100){ledDutyRatio =0;}TIM_SetCompare1(TIM1, ledDutyRatio);}}break;
/*控制灯亮度百分比调节*/case3:if(!systemModel){switch(Usart3_RxPacket[4]){case0:ledDutyRatio =0;TIM_SetCompare1(TIM1, ledDutyRatio);break;
case1:ledDutyRatio =10;TIM_SetCompare1(TIM1, ledDutyRatio);break;
case2:ledDutyRatio =20;TIM_SetCompare1(TIM1, ledDutyRatio);break;
case3:ledDutyRatio =30;TIM_SetCompare1(TIM1, ledDutyRatio);break;
case4:ledDutyRatio =40;TIM_SetCompare1(TIM1, ledDutyRatio);break;
case5:ledDutyRatio =50;TIM_SetCompare1(TIM1, ledDutyRatio);break;
case6:ledDutyRatio =60;TIM_SetCompare1(TIM1, ledDutyRatio);break;
case7:ledDutyRatio =70;TIM_SetCompare1(TIM1, ledDutyRatio);break;
case8:ledDutyRatio =80;TIM_SetCompare1(TIM1, ledDutyRatio);break;
case9:ledDutyRatio =90;TIM_SetCompare1(TIM1, ledDutyRatio);break;
case16:ledDutyRatio =100;TIM_SetCompare1(TIM1, ledDutyRatio);break;
default:break;}}break;
/*控制系统模式*/case4:if(Usart3_RxPacket[4]){systemModel =1;ledDutyRatio =0;TIM_SetCompare1(TIM1, ledDutyRatio);}else{systemModel =0;ledDutyRatio =0;TIM_SetCompare1(TIM1, ledDutyRatio);}break;
default:break;}}}
/** * @brief 获取传感器的数据 * @param 无 * @retval 无 */voidsensorScan(void){DHT11_Read_Data(&sensorData.humi, &sensorData.temp);HC_SR04_Deboanle(&sensorData.distance);LDR_LuxData(&sensorData.lux);HC_SR501_Input(&sensorData.people);}

intmain(void){ADCX_Init();PWM_Init(100-1,720-1);Timer2_Init(9,14398);Uart2_Init(9600);Uart1_Init(115200);IWDG_Init();//初始化看门狗Uart3_Init();
LDR_Init();OLED_Init();DHT11_Init();LED_Init();Key_Init();HC_SR501_Init();HC_SR04_Init();Buzzer_Init();MyRTC_Init();
Sensorthreshold.Illumination_threshold =FLASH_R(FLASH_START_ADDR);//从指定页的地址读FLASHSensorthreshold.Distance_threshold =FLASH_R(FLASH_START_ADDR+2);//从指定页的地址读FLASH

GENERAL_TIM_Init();userInit();//完成机智云初始赋值gizwitsInit();//开辟一个环形缓冲区while(1){do{currentDataPoint.valueIllumination_threshold = Sensorthreshold.Illumination_threshold;currentDataPoint.valueDistance_threshold = Sensorthreshold.Distance_threshold;}while(0);
IWDG_ReloadCounter();//重新加载计数值 喂狗sensorScan();//获取传感器数据Asrpro();//执行语音指令
switch(menu){casedisplay_page:
MyRTC_ReadTime();//调用此函数后,RTC硬件电路里时间值将刷新到全局数组OLED_Menu_SensorData();//显示主页面传感器数据、系统模式等内容OLED_Menu();//显示主页面的固定内容if(!systemModel){LED_PWM_KEY();//按键控制LED的PWM}
//切换系统模式if(KeyNum == KEY_1){KeyNum =0;systemModel = ~systemModel;if(systemModel){currentDataPoint.valueModel =1;ledDutyRatio =0;TIM_SetCompare1(TIM1, ledDutyRatio);}else{currentDataPoint.valueModel =0;ledDutyRatio =0;TIM_SetCompare1(TIM1, ledDutyRatio);}}
//判断是否进入阈值设置界面if(KeyNum == KEY_Long1){KeyNum =0;OLED_Clear();//清屏menu = settingsPage;//跳转到阈值设置界面}break;casesettingsPage:OLED_SetInterfacevoid();//显示阈值设置界面的固定内容OLED_Option(SetSelection());//实现阈值设置页面的选择功能ThresholdModification(SetSelection());//实现阈值调节功能
//判断是否退出阈值设置界面if(KeyNum == KEY_2){KeyNum =0;OLED_Clear();//清屏menu = display_page;//跳转到主界面
//存储修改的传感器阈值至flash内FLASH_W(FLASH_START_ADDR, Sensorthreshold.Illumination_threshold, Sensorthreshold.Distance_threshold);currentDataPoint.valueIllumination_threshold = Sensorthreshold.Illumination_threshold;currentDataPoint.valueDistance_threshold = Sensorthreshold.Distance_threshold;}break;casetimeSettingsPage:OLED_ThresholdTime();//显示时间设置界面的内容OLED_Time_Option(SetSelection());//实现间设置界面的选择功能TimeModification(SetSelection());//实现时间调节功能
//判断是否退出时间设置界面if(KeyNum == KEY_2){KeyNum =0;//将更改的数据赋值回RTC数组中MyRTC_Time[3] = hour;MyRTC_Time[4] = minute;MyRTC_Time[5] = second;MyRTC_SetTime();//调用此函数后,全局数组里时间值将刷新到RTC硬件电路
OLED_Clear();//清屏menu = settingsPage;//回到阈值设置界面}break;}//判断上位机是否更改阈值,如更改则保存至flash中if(valueFlashflag){valueFlashflag =0;//存储修改的传感器阈值至flash内FLASH_W(FLASH_START_ADDR, Sensorthreshold.Illumination_threshold, Sensorthreshold.Distance_threshold);}
userHandle();//更新机智云数据点变量存储的值gizwitsHandle((dataPoint_t *)¤tDataPoint);//数据上传至机智云}}


05

实验效果


81f9ef9c-6875-11f0-a486-92fbcf53809c.jpg82125366-6875-11f0-a486-92fbcf53809c.jpg


声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉
  • STM32
    +关注

    关注

    2305

    文章

    11120

    浏览量

    371053
  • 智能语音
    +关注

    关注

    11

    文章

    821

    浏览量

    50027
  • 机智云
    +关注

    关注

    3

    文章

    629

    浏览量

    27621
收藏 人收藏
加入交流群
微信小助手二维码

扫码添加小助手

加入工程师交流群

    评论

    相关推荐
    热点推荐

    诚接stm32项目

    诚接stm32项目价格私聊
    发表于 05-17 10:20

    【万元大奖】机智智能硬件创新大赛

    选题,以供参战团队参考:智能灯(WiFi) 、智能健康计、智能药盒、智能玩具(语音)。(具体见附件:机智
    发表于 07-06 13:42

    基于机智物联网远程控制台灯

    待着无聊,发个帖子,这个帖子是关于物联网的主要设备机智gokit 2.0开发板台灯先看下最终效果吧:下图开发板是用的机智的,简单的说是做
    发表于 12-01 19:41

    机智2016~2017优秀项目盘点

    】之无线工业粉尘监测仪【Gokit 3】之仓鼠管家和OpenHamtaro开源项目【Gokit】之智慧宿舍【Gokit 3】之智能婴儿摇篮【GoKit+STM32】之智能家居
    发表于 09-22 13:03

    【视频推荐】以智能语音鱼缸为例,讲解机智代码

    机智代码讲解本视频以智能语音鱼缸为例,按照如下图所示的文件内容目录,详细讲解机智代码,如主要
    发表于 07-19 17:15

    基于STM32芯片和机智平台的一款智能台灯

    来改变灯光亮灭。DHT11温湿度模块:用来实时监测台灯周围的环境变化MQ-2气体传感器:对家庭室内环境实时检测时钟显示PCF8563模块软件部分:使用机智物联网开发平台,使用机智
    发表于 07-22 15:31

    CubeMX如何创建stm32项目

    CubeMX如何创建stm32项目
    发表于 02-14 06:24

    STM32项目分享:智能家居(机智)系统

    STM32项目分享:智能家居(机智)系统
    的头像 发表于 07-28 08:10 3948次阅读
    <b class='flag-5'>STM32</b><b class='flag-5'>项目</b>分享:<b class='flag-5'>智能</b>家居(<b class='flag-5'>机智</b><b class='flag-5'>云</b>)系统

    STM32项目分享:智能台灯系统

    01—项目简介1.功能详解基于STM32智能台灯系统。功能如下:亮度控制:按键控制照明灯的亮度(5挡亮度)计时功能:按键启动计时,累
    的头像 发表于 11-29 01:02 2705次阅读
    <b class='flag-5'>STM32</b><b class='flag-5'>项目</b>分享:<b class='flag-5'>智能</b><b class='flag-5'>台灯</b>系统

    STM32项目分享:机智智慧农业系统

    01—项目简介1.功能详解基于STM32机智智慧农业系统。功能如下:温湿度采集:使用DHT11温湿度传感器采集环境温湿度土壤湿度
    的头像 发表于 12-19 18:40 1899次阅读
    <b class='flag-5'>STM32</b><b class='flag-5'>项目</b>分享:<b class='flag-5'>机智</b><b class='flag-5'>云</b>智慧农业系统

    STM32项目分享:智能台灯(机智)系统

    01—项目简介1.功能详解STM32智能台灯机智)系统功能如下:1.检测功能:系统检测周围温
    的头像 发表于 03-10 08:03 1463次阅读
    <b class='flag-5'>STM32</b><b class='flag-5'>项目</b>分享:<b class='flag-5'>智能</b><b class='flag-5'>台灯</b>(<b class='flag-5'>机智</b><b class='flag-5'>云</b>)系统

    STM32项目分享:STM32智能语音台灯

    项目简介1.功能详解STM32智能语音台灯功能如下:1.STM32F103C8T6单片机系统板
    的头像 发表于 03-15 10:02 2328次阅读
    <b class='flag-5'>STM32</b><b class='flag-5'>项目</b>分享:<b class='flag-5'>STM32</b><b class='flag-5'>智能</b><b class='flag-5'>语音</b><b class='flag-5'>台灯</b>

    基于机智智能台灯原型系统设计

    为了提升工作和学习的健康与生活质量,设计了一款基于物联网的智能台灯。该台灯STM32为主控,结合多种传感器、语音播报和
    的头像 发表于 04-11 19:35 1157次阅读
    基于<b class='flag-5'>机智</b><b class='flag-5'>云</b>的<b class='flag-5'>智能</b><b class='flag-5'>台灯</b>原型系统设计

    STM32项目分享:智能家居(机智)升级版

    01—项目简介1.功能详解STM32智能家居(机智)升级版功能如下:检测功能:监测环境温湿度、烟雾浓度、一氧化碳、空气质量、光照强
    的头像 发表于 07-02 18:04 606次阅读
    <b class='flag-5'>STM32</b><b class='flag-5'>项目</b>分享:<b class='flag-5'>智能</b>家居(<b class='flag-5'>机智</b><b class='flag-5'>云</b>)升级版

    STM32项目分享:智能厨房安全系统(机智)

    01—项目简介1.功能详解STM32智能厨房安全系统(机智)功能如下:STM32F103C8T
    的头像 发表于 09-10 00:01 890次阅读
    <b class='flag-5'>STM32</b><b class='flag-5'>项目</b>分享:<b class='flag-5'>智能</b>厨房安全系统(<b class='flag-5'>机智</b><b class='flag-5'>云</b>)