const int sensorPin = A0; //MQ2가 연결된 아날로그 핀 int gasValue; int correctedGasValue; void setup() { Serial.begin(9600); //시리얼 통신 시작 Serial.println("Welcome to LK World.!"); //시리얼모니터에 문자출력 } void loop() { gasValue = analogRead(sensorPin); //MQ2 센서의 값을 읽어들여 gasValue에 저장 correctedGasValue = calibrateGasValue(gasValue); //가스 값 보정함수 호출하여 correctedGasValue에 저장 Serial.print("GasValue : "); //시리얼모니터에 문자출력 Serial.print(gasValue); // gasValue 변수값을 시리얼모니터에 출력 Serial.print(" | CorrectedGasValue : "); //시리얼모니터에 문자출력 Serial.println(correctedGasValue); // 보정된 가스 값을 시리얼모니터에 출력 delay(1000); //1초 간격으로 측정 } int calibrateGasValue(int rawValue){ //가스 값 보정 알고리즘을 구현 // 센서 특성 및 실험 데이터를 활용하여 보정 수행 // ex) correctedValue = rawValue*(보정 계수); int correctedValue = rawValue*2; // 간단한 예제로 rawValue에 2를 곱하는 보정을 수행 return correctedValue; //보정된 값을 반환 }