赞
踩
Arduino UNO
MQ Sensor(MQ-型号随意)
有源无源蜂鸣器
LED灯(选配 )
Arduino | MQ Sensor |
---|---|
5V | VCC |
GND | GND |
A0 | A0 |
D0 | 3 |
传感器
Arduino | MQ Sensor |
---|---|
5V | VCC |
GND | GND |
A0 | A0 |
D0 | 3 |
LED灯光
红色LED +(长引脚)---------- 10
负极 ---------- GND
绿色LED +(长引脚)---------- 11
负极 ---------- GND
蜂鸣器 正极 ------------ 7
负极 ---------------- GND
#include <Arduino.h> /*定义烟雾传感器A0,D0引脚*/ #define Sensor_AO A0 #define Sensor_DO 3 /*初始化烟雾值*/ unsigned int sensorValue = 0; /*初始化部分*/ void setup() { pinMode(Sensor_DO, INPUT); //输入模式 Serial.begin(9600); //设置串口监视器波特率9600 } /*烟雾检测部分*/ void loop() { sensorValue = analogRead(Sensor_AO); //读取A0口烟雾数值 Serial.print("烟雾值 = "); Serial.println(sensorValue); /*判断是否超过检测阀值*/ if (digitalRead(Sensor_DO) == LOW) { Serial.println("超过烟雾检测阀值!!"); } delay(800); //设置延时 }
#include <Arduino.h> /*定义烟雾传感器A0,D0引脚*/ #define Sensor_AO A0 #define Sensor_DO 3 unsigned int sensorValue = 0; int Buzzer = 7; //蜂鸣器引脚 int RedLED = 10; //红色LED引脚 int GreenLED = 11; //绿色LED引脚 void setup() { pinMode(Sensor_DO, INPUT); pinMode(Buzzer,OUTPUT); pinMode(RedLED,OUTPUT); pinMode(GreenLED,OUTPUT); Serial.begin(9600); } void loop() { int val; val = sensorValue; sensorValue = analogRead(Sensor_AO); Serial.print("Sensor AD Value = "); Serial.println(sensorValue); while(val > 400) { digitalWrite(Buzzer,HIGH); digitalWrite(Buzzer,LOW); digitalWrite(RedLED,HIGH); digitalWrite(RedLED,LOW); delay(50); } digitalWrite(Buzzer,LOW); digitalWrite(GreenLED,HIGH); if (digitalRead(Sensor_DO) == LOW) { Serial.println("超出当前烟雾检测阀值!"); // digitalWrite(RedLED,HIGH); //超过烟雾检测阀值时亮起红灯 } delay(500); }
烟雾数值偏大(小)
每个MQ烟雾传感器后面有一个电位器,通过旋转改变阻值调整大小
⚠️ :MQ传感器工作温度较高,上电发热(预热)属于正常现象,应当先预热一段时间后进行
通过串口监视器,查看当前烟雾检测情况,绿灯常亮,即烟雾在正常预设范围,红灯亮,绿灯熄灭,蜂鸣器短促蜂鸣,烟雾超过预设浓度
下一篇,我将讲解:智能家居物联网烟雾报警器
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。