设计做有关空气质量检测的都可以选择mp503这个传感器哦~
本压缩包里包含基础的mp403 ADC采集和4脚OLED的显示
首先mp403使用前请先预热5min左右才能正常工作
A:0V B:0V ---- 质量优
A:0V B:5V ---- 轻度污染
A:5V B:0V ---- 中度污染
A:5V B:5V ---- 重度污染
mp503检测方式为adc电压采集
我用的是
A--PA0
B--PA1
VCC--VCC
GND--GND
具体空气质量等级的评级可搜索mp503手册查看
单片机源程序如下:
- #include "delay.h"
- #include "sys.h"
- #include "oled.h"
- #include "pid.h"
- #include "adc.h"
- int main(void)
- {
- float temp0,temp1,mp503A,mp503B;
- u16 adcx0,adcx1;
- delay_init(); //延时函数初始化
- OLED_Init(); //初始化OLED
- OLED_Clear();
- Adc_Init(); //ADC初始化
- OLED_XianShi();
- while(1)
- {
- adcx0=Get_Adc_Average(ADC_Channel_0,20);
- temp0=(float)adcx0*(3.3/4096);
- mp503A=adcx0=temp0;
- OLED_ShowNum(38,0,temp0,1,16);
- temp0-=adcx0;
- temp0*=1000;
- OLED_ShowNum(54,0,temp0,3,16);
- delay_ms(250); //显示A0电压输出(A0=A)
-
- adcx1=Get_Adc_Average(ADC_Channel_1,20);
- temp1=(float)adcx1*(3.3/4096);
- mp503B=adcx1=temp1;
- OLED_ShowNum(38,3,temp1,1,16);
- temp1-=adcx1;
- temp1*=1000;
- OLED_ShowNum(54,3,temp1,3,16);
- delay_ms(250); //显示A1电压输出(A1=B)
- if(mp503A<1)
- {
- if(mp503B<1)
- OLED_ShowCHinese(72,5,0); //空气质量优
- else
- {
- OLED_ShowCHinese(72,5,1);
- //OLED_ShowCHinese(70,5,2);
- //OLED_ShowCHinese(70,5,3);
- //OLED_ShowCHinese(70,5,4); //轻度污染
- }
- }
- if(mp503A>=2)
- {
- if(mp503B<1)
- {
- OLED_ShowCHinese(72,5,2);
- //OLED_ShowCHinese(70,5,0);
- //OLED_ShowCHinese(70,5,0);
- //OLED_ShowCHinese(70,5,0);
- }
- else
- {
- OLED_ShowCHinese(72,5,3);
- //OLED_ShowCHinese(70,5,0);
- //OLED_ShowCHinese(70,5,0);
- //OLED_ShowCHinese(70,5,0);
- }
- }
- }
-
- }
复制代码
Keil代码下载:
MP503.7z
(252.59 KB, 下载次数: 38)
|