미세먼지 센서 코드 (미완성) |
좋아요:0 | ||||
---|---|---|---|---|---|
작성자 | 한소라 | 등록일 | 18.07.17 | 조회수 | 127 |
#define NO_DUST_VOLTAGE 400 //mv #define SYS_VOLTAGE 5000 //mv int Analog_Pin = 1; //Connect dust sensor to Arduino A0 pin int Digital_Pin = 2; //Connect 2 led driver pins of dust sensor to Arduino D2 int samplingTime = 280; int deltaTime = 40; int sleepTime = 9680; float analogVal = 0; float digitalVal = 0; float dustDensity = 0; void setup() { Serial.begin(9600); pinMode(Digital_Pin, OUTPUT); } void loop() { digitalWrite(Digital_Pin, LOW); // power on the LED delayMicroseconds(samplingTime); analogVal = analogRead(Analog_Pin); // read the dust value delayMicroseconds(deltaTime); digitalWrite(Digital_Pin, HIGH); // turn the LED off delayMicroseconds(sleepTime); digitalVal = analogVal * (SYS_VOLTAGE / 1024.0); if (digitalVal >= NO_DUST_VOLTAGE) { digitalVal -= NO_DUST_VOLTAGE; dustDensity = digitalVal * 0.2; // Voltage(mv)값을 dust density로 변경 (ug/m3) dustDensity -= 30; } else { dustDensity = 0; } // linear eqaution taken from http://www.howmuchsnow.com/arduino/airquality/ // Chris Nafis (c) 2012 Serial.println("**********************************"); Serial.print(" [Analog Value] : "); Serial.println(analogVal); Serial.print(" [Voltage] : "); Serial.print(digitalVal); Serial.println(" mV "); Serial.print(" Fine Dust(PM 2.5) : "); Serial.print(dustDensity); // unit: mg/m3 Serial.println(" mg/m3 "); Serial.println("**********************************"); Serial.println(""); delay(1000); } |
이전글 | 작품 전시 보고서(이준호, 이예지) |
---|---|
다음글 | 완성작 |