본문 바로가기
Arduino

[Arduino Nano/나노] MQ-7 CO 센서

by 놀자요를레히 2021. 1. 29.

[Arduino Nano/나노] MQ-7 CO 센서

 

 

 

MQ-7 CO sensor

 

공기중에 있는 CO 농도를 감지하는 센서

(자세한 내용은 하단의 데이터시트 참고)

 

 

 

MQ-7 datasheet.pdf
0.05MB

 

 

 

아두이노 연결

MQ-7 Arduino Nano
AO A0
DO X
GND GND
VCC 5V

 

MQ-7 - Arduino Nano

 

 

 

사용 라이브러리

MQ7Sensor.zip
0.02MB

 

 

 

아두이노 코드

 

Before we can use this formula in a sketch, we need to determine R0 of the MQ-7 sensor first. This varies between devices so there is a need for actual testing.

 

From the log-log plot, we can see that RS/R0 is constant in air and is equal to 1. Since by definition, R0 is the resistance of the sensor in clean air, then only RS varies for every gas.

 

RS is the sensor resistance and forms a voltage divider with the resistor R2 (see schematic diagram above). Thus, RS can be determined if the series resistor R2 from the schematic is known. Most boards use a 2 kilo-ohm resistor for R2.

 

We can then use this sketch to get R0:

float sensor_volt;
float RS_gas;
float R0;
int R2 = 2000;

void setup() {
  Serial.begin(9600);
}

void loop() {
  int sensorValue = analogRead(A0);
  sensor_volt=(float)sensorValue/1024*5.0;
  RS_gas = ((5.0*R2)/sensor_volt)-R2;
  R0 = RS_gas/1;
  Serial.print("R0 : ");
  Serial.println(R0);
}

R0을 구했으면 5번째 줄의 R0의 값에 해당값을 작성하고 구한다

float RS_gas = 0;
float ratio = 0;
float sensorValue = 0;
float sensor_volt = 0;
float R0 = 해당값 작성;
 
void setup() {
 Serial.begin(9600);
}
 
void loop() {
   sensorValue = analogRead(A0);
   sensor_volt = sensorValue/1024*5.0;
   RS_gas = (5.0-sensor_volt)/sensor_volt;
   ratio = RS_gas/R0; //Replace R0 with the value found using the sketch above
   float x = 1538.46 * ratio;
   float ppm = pow(x,-1.709);
   Serial.print("PPM: ");
   Serial.println(ppm);
   delay(1000);
}

 

 

결과값

 

 

 

참고 : www.teachmemicro.com/use-mq-7-carbon-monoxide-sensor/

댓글