1.火焰传感器(4线)
火焰传感器模块主要采用外敏感型AC检测红外信号强度,并将其转换为机器人可识别的信号,以检测火焰信号。
图1-1火焰传感器
1.火焰传感器检测到的波长为760纳米~1100纳米范围的光源,打火机测试火焰距离为80cm,火焰越大,测试距离越远。
2、工作电压3.3~5V
三、输出形式:DO和AO模拟电压输出
2.设计火焰报警器
我在火焰传感器报警的设计中使用了它LED当火焰传感器检测到火焰时,灯、蜂鸣器和火焰传感器提高电平,蜂鸣器响起并驱动LED灯点亮。
LED灯的配置PB2时钟的GPIOB6引脚; 蜂鸣器PB2时钟的GPIOA1引脚;
配置了火焰传感器PB2时钟的GPIO10引脚
正常配置各硬件初始化,其中LED灯和蜂鸣器的模式是GPIO_Mode_OUT_PP火焰传感器的模式用于推拉输出GPIO_Mode_IPU上拉输入。上拉输入,只要检测到火焰则会接收到信号,而GPIO_Mode_IPD是下拉输入,是火焰检测后收到的信号,所以程序应该写GPIO_Mode_IPU。
3.程序设计
(1)LED灯程序
LED灯的程序是我上一篇文章写的按钮开关LED程序即可
https://blog.csdn.net/weixin_62353329/article/details/126001958?spm=1001.2014.3001.5501
(2)蜂鸣器程序
蜂鸣器正常打开时钟,初始化程序
Buzzer.c
#include "stm32f10x.h" // Device header void Buzzer_Init(void) { RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE); GPIO_InitTypeDef GPIO_InitStructure; GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP; //推挽输出 GPIO_InitStructure.GPIO_Pin=GPIO_Pin_1; GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz; //速率50MHz GPIO_Init(GPIOA,&GPIO_InitStructure); GPIO_SetBits(GPIOA,GPIO_Pin_1); } void Buzzer_ON(void) { GPIO_ResetBits(GPIOA,GPIO_Pin_1); } void Buzzer_OFF(void) { GPIO_SetBits(GPIOA,GPIO_Pin_1); } void Buzzer_Turn(void) { if (GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_1)==1) { GPIO_SetBits(GPIOA,GPIO_Pin_1); } else { GPIO_ResetBits(GPIOA,GPIO_Pin_1); } }
Buzzer.h
#ifndef __Buzzer_H #define __Buzzer_H void Buzzer_Init(void); void Buzzer_ON(void); void Buzzer_OFF(void); void Buzzer_Turn(void); #endif
(3)火焰传感器
Flame.c
#include "stm32f10x.h" // Device header void Flame_Init(void) { RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE); GPIO_InitTypeDef GPIO_InitStructure; GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IPU ; //上拉输入 GPIO_InitStructure.GPIO_Pin=GPIO_Pin_10; GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz; GPIO_Init(GPIOB,&GPIO_InitStructure); GPIO_SetBits(GPIOB, GPIO_Pin_10); } uint8_t Flame_Get(void) { return GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_10); ///读取输入值 }
Flame.h
#ifndef __Flame_H #define __Flame_H #include "stm32f10x.h" void Flame_Init(void); uint8_t Flame_Get(void); #endif
(4)主程序
在主程序中配置头文件main可以直接调用前面写的硬件程序xxx_Init。使用while...if如果传感器电平较高,蜂鸣器就会响起LED灯亮了,否则,火焰警报就配置好了。
main.c
#include "stm32f10x.h" // Device header #include "Delay.h" #include "Buzzer.h" #include "Flame.h" #include "LED.h" int main(void) { Buzzer_Init(); Flame_Init(); LED_Init(); while (1) { if ( Flame_Get() ==1) { Buzzer_OFF(); LED2_OFF(); } else { Buzzer_ON(); LED2_ON(); } } }
4.效果展示
图4-1未检测火焰的效果
图4-2检测到火焰效果后