개발자/라즈베리파이4

mq135 air quality sensor 라즈베리파이 4 공기질 센서

지구빵집 2022. 5. 30. 08:18
반응형

 

공기질 센서는 NH3, NOx, 알코올, 벤젠, 연기 및 CO2를 포함한 광범위한 가스를 감지하기 위한 것입니다. 사무실이나 공장에서 사용하기에 이상적이며 간단한 구동 및 공기질 모니터링 센서입니다.

 

MQ135 센서를 사용하기 전에 예열해야 합니다. 즉, 5V에 연결하고 최소 12-24 시간 동안 실행해야 합니다. 그 후 측정 값을 보정해야 합니다.

 

센서 파트 넘버: MQ-135 Air quality hazardous gas sensor module

 

MQ135 공기질 센서 이미지

 

MQ135 공기질 센서 이미지
MQ135 공기질 센서 기구 사이즈

 

LM393 칩셋, MQ135 가스 센서 기반 / 이산화탄소(CO2), 암모니아(NH3), 질소 산화물(NOx), 알콜류, 벤젠 및 연기 등 유해가스, 공기질 센서 / DC 5V / Size: 32mm * 22mm 

 

Technical Specification 

 

  • 메인 칩: LM393, MQ135
  • 가스 감지 프로브 작동 전압: DC 5V
  • 신호 출력 표시기 지침; 이중 신호 출력(아날로그 출력 및 TTL 레벨 출력);
  • TTL 출력 유효 신호가 낮습니다. (마이크로 컨트롤러 IO 포트에 액세스할 수 있는 출력 낮은 신호 표시등)
  • 농도가 증가하면 아날로그 출력이 증가하고 농도가 높을수록 전압이 높아집니다.
  • 황화물, 벤젠 고감도의 증기, 연기 및 기타 유해 가스
  • 수명이 길고 안정적인 안정성이 있습니다.
  • 신속한 응답 회복 특성; 

 

MQ 시리즈 가스 센서 종류

 

MQ-2 Methane, Butane, LPG, Smoke

MQ-3 Alcohol, Ethanol, Smoke

MQ-4 Methane, CNG Gas

MQ-5 Natural gas, LPG

MQ-6 LPG, butane

MQ-7 Carbon Monoxide

MQ-8 Hydrogen Gas

MQ-9 Carbon Monoxide, flammable gasses

MQ131 Ozone

MQ135 Air Quality

MQ136 Hydrogen Sulphide gas

MQ137 Ammonia

MQ138 Benzene, Toluene, Alcohol, Propane, Formaldehyde gas, Hydrogen

MQ214 Methane, Natural Gas

MQ216 Natural gas, Coal Gas

MQ303 AAlcohol, Ethanol, smoke

MQ306 ALPG, butane

MQ307 ACarbon Monoxide

MQ309 ACarbon Monoxide, flammable gas 

 

 

연결도

 

- 파일 이름: gasdetect.c

- 소스코드: 할당된 gpio 번호는 예고없이 변경할 수 있습니다.

 

공기질 센서 출력을 폴링 방식으로 데이터 얻는 코드

 

#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>
#include <wiringPi.h>


// Use GPIO Pin 7, which is Pin 11 for wiringPi library

#define AIRCHECK 6  //gpio7


// the event counter 
volatile int eventCounter = 0; 

// -------------------------------------------------------------------------
// myInterrupt:  called every time an event occurs
void myInterrupt(void) {
   eventCounter++;

}


// main
int main(void) 
{
	// sets up the wiringPi library
	if (wiringPiSetup () < 0) 
	{
		fprintf (stderr, "Unable to setup wiringPi: %s\n", strerror (errno));
		return 1;
	}
	
	pinMode(AIRCHECK, INPUT);

	// set Pin 17/0 generate an interrupt on high-to-low transitions
	// and attach myInterrupt() to the interrupt
	/*if ( wiringPiISR (LIGHTSEN_OUT, INT_EDGE_RISING, &myInterrupt) < 0 ) 
	{
		fprintf (stderr, "Unable to setup ISR: %s\n", strerror (errno));
		return 1;
	}*/

	// display counter value every second.
	while ( 1 ) 
	{
		//printf( "%d\n", eventCounter );
		//eventCounter = 0;
		
		if(digitalRead(AIRCHECK) == 0)
			printf("Air Check-Bad !!!!!!!!!!!\n");
		if(digitalRead(AIRCHECK) == 1)
			printf("Air Check-Good \n");		
	
		delay( 100 ); // wait 1 second
	}

	return 0;
}

 

아래는 인터럽트 방식으로 데이터를 얻는 코드

 

#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>
#include <wiringPi.h>


// Use GPIO Pin 17, which is Pin 0 for wiringPi library

#define AIRCHECK 6 //gpio17


// the event counter 
volatile int eventCounter = 0; 

// -------------------------------------------------------------------------
// myInterrupt:  called every time an event occurs
void myInterrupt(void) {
   eventCounter++;

}


// -------------------------------------------------------------------------
// main
int main(void) {
  // sets up the wiringPi library
  if (wiringPiSetup () < 0) {
      fprintf (stderr, "Unable to setup wiringPi: %s\n", strerror (errno));
      return 1;
  }

  // set Pin 17/0 generate an interrupt on high-to-low transitions
  // and attach myInterrupt() to the interrupt
  if ( wiringPiISR (AIRCHECK, INT_EDGE_FALLING, &myInterrupt) < 0 ) {
      fprintf (stderr, "Unable to setup ISR: %s\n", strerror (errno));
      return 1;
  }

  // display counter value every second.
  while ( 1 ) {
    printf( "%d\n", eventCounter );
    //eventCounter = 0;
    delay( 1000 ); // wait 1 second
  }

  return 0;
}

 

참고

MQ-135 Air quality hazardous gas sensor module 공기질/위험가스 

MQ135 아두이노 대기오염센서

 

 

 

반응형