制作步骤论文里写的比较详细,这里不再介绍了好吧我承认我懒
材料:
Arduino Uno R3开发板(其他型号也可)
红外接收二极管
有源蜂鸣器
MQ-2气体传感器
杜邦线若干&面包板
电脑
完整接线:
如图所示
注:mq-2信号脚用模拟脚,二极管使用数字脚
完整代码:
<!-- wp:paragraph -->
<p>int MQ = A0; //MQ-2<br>int HOT = 4; //红外<br>int BUZZER = 5; //蜂鸣器</p>
<!-- /wp:paragraph -->
<!-- wp:paragraph -->
<p>void setup() {</p>
<!-- /wp:paragraph -->
<!-- wp:paragraph -->
<p>pinMode(MQ, INPUT);<br>pinMode(HOT, INPUT);<br>pinMode(BUZZER, OUTPUT);</p>
<!-- /wp:paragraph -->
<!-- wp:paragraph -->
<p>}<br>void loop() {</p>
<!-- /wp:paragraph -->
<!-- wp:paragraph -->
<p>int sensorValue = analogRead(MQ);<br>Serial.println(sensorValue);<br>if (digitalRead(HOT) || sensorValue <= 100) {<br>digitalWrite(BUZZER, HIGH);<br>}<br>else {<br>digitalWrite(BUZZER, LOW);<br>}<br>}</p>
<!-- /wp:paragraph -->
论文:
原创文章未经许可严禁转载