Smoke sensor MQ-2 experiment

Smoke sensor MQ-2 experiment

Experimental phenomena

The smoke sensor converts the smoke concentration value into an analog voltage value output. The arduino reads the analog voltage value through the A0 pin and sends it to the PC through the serial port. When the analog voltage value exceeds the module's comparator setting value, the module D0 pin outputs low power level. When the arduino monitors the bottom signal of the D0 pin, the onboard LED lights up and alarms, and the serial port outputs the Alarm signal. The alarm threshold can be adjusted by adjusting the on-board potentiometer.

Theoretical study

Insert picture description here
Apply a 5V voltage between VCC and GND.
After waiting for about 30s for the sensor to warm up, read the analog output A0 pin voltage.
Adjust the potentiometer to change the LED alarm threshold.
When the concentration is greater than the set value, the LED indicator on the module lights up , At the same time D0 pin outputs low level.

Schematic diagram

Insert picture description here

Code writing

#include<Arduino.h>
#define sensor A5
#define led 13
#define sensor_d0 2
unsigned int sensorvalue = 0;
void setup() {
    
    
  // put your setup code here, to run once:
  pinMode(sensor_d0, INPUT);
  pinMode(sensor, INPUT);
  pinMode(led, OUTPUT);
  Serial.begin(9600);
  Serial.println("welcome to use");
}
void loop() {
    
    
  // put your main code here, to run repeatedly:
  sensorvalue = analogRead(sensor);
  Serial.print("ad value = ");
  Serial.println(sensorvalue);
  if (digitalRead(sensor_d0) == LOW) {
    
    
    Serial.println("alarm");
    digitalWrite(led, HIGH);
  } else {
    
    
    digitalWrite(led, LOW);
  }
  delay(1000);
}

Guess you like

Origin blog.csdn.net/qq_45671732/article/details/109613432