한글보드: PM2.5 미세 먼지센서 어댑터 포함 / GP2Y10
사양 (Specification)
튜토리얼 (Tutorial -1/-2)
샘플 코드 (Sample Code - 1) /* Standalone Sketch to use with a Arduino UNO and a Sharp Optical Dust Sensor GP2Y1010AU0F */
int measurePin = 0; //Connect dust sensor to Arduino A0 pin int ledPower = 2; //Connect 3 led driver pins of dust sensor to Arduino D2
int samplingTime = 280; int deltaTime = 40; int sleepTime = 9680;
float voMeasured = 0; float calcVoltage = 0; float dustDensity = 0;
void setup(){ Serial.begin(9600); pinMode(ledPower,OUTPUT); }
void loop(){ digitalWrite(ledPower,LOW); // power on the LED delayMicroseconds(samplingTime);
voMeasured = analogRead(measurePin); // read the dust value
delayMicroseconds(deltaTime); digitalWrite(ledPower,HIGH); // turn the LED off delayMicroseconds(sleepTime);
// 0 - 5V mapped to 0 - 1023 integer values // recover voltage calcVoltage = voMeasured * (5.0 / 1024.0);
// linear eqaution taken from http://www.howmuchsnow.com/arduino/airquality/ // Chris Nafis (c) 2012 dustDensity = 0.17 * calcVoltage - 0.1;
Serial.print("Raw Signal Value (0-1023): "); Serial.print(voMeasured);
Serial.print(" - Voltage: "); Serial.print(calcVoltage);
Serial.print(" - Dust Density: "); Serial.println(dustDensity); // unit: mg/m3
delay(1000); }
샘플 코드 (Sample Code - 2) / 평균 값 산출
/* Standalone Sketch to use with a Arduino UNO and a Sharp Optical Dust Sensor GP2Y1010AU0F */ int measurePin = 0; //Connect dust sensor to Arduino A0 pin int ledPower = 2; //Connect 3 led driver pins of dust sensor to Arduino D2 int samplingTime = 280; int deltaTime = 40; int sleepTime = 9680; float voMeasured = 0; float calcVoltage = 0; float dustDensity = 0; #define NUMREADINGS 10 // 평균내는 개수 수정 int readings[NUMREADINGS] = {0,}; int index = 0; int total = 0; int val = 0; void setup() { Serial.begin(9600); pinMode(ledPower, OUTPUT); } void loop() { digitalWrite(ledPower, LOW); // power on the LED delayMicroseconds(samplingTime); voMeasured = analogRead(measurePin); // read the dust value delayMicroseconds(deltaTime); digitalWrite(ledPower, HIGH); // turn the LED off delayMicroseconds(sleepTime); // 0 - 5V mapped to 0 - 1023 integer values // recover voltage calcVoltage = voMeasured * (5.0 / 1024.0); // linear eqaution taken from http://www.howmuchsnow.com/arduino/airquality/ // Chris Nafis (c) 2012 dustDensity = 0.17 * calcVoltage - 0.1; Serial.print("Raw Signal Value (0-1023): "); Serial.print(voMeasured); Serial.print(" - Voltage: "); Serial.print(calcVoltage); Serial.print(" - Dust Density: "); //Serial.println(dustDensity); // unit: mg/m3 //Serial.println(dustDensity * 1000); // ug/m3 total -= readings[index]; readings[index] = dustDensity * 1000; total += readings[index]; index++; if (index >= NUMREADINGS) { index = 0; } val = total / NUMREADINGS; Serial.println(val); delay(1000);
} 튜토리얼 (Tutorial -3) 샘플 코드 (Sample Code - 3)
//1602 LCD 세팅 #include <LiquidCrystal.h> // LCD 라이브러리 포함 LiquidCrystal lcd(13, 12, 5, 4, 3, 2); // LCD 핀 설정
//DHT11 온습도센서 세팅 #include "DHT.h" // DHT11 라이브러리 포함 #define DHTPIN 7 // DHT11 연결핀 #define DHTTYPE DHT11 DHT dht(DHTPIN, DHTTYPE);
//먼지센서 세팅 int LED = 11; int DUST = 0; int samplingTime = 280; int deltaTime = 40; int sleepTime = 9680; float dustval = 0; float voltage = 0; float dustug = 0; float dus = 0; float a = 0;
void setup() { Serial.begin(9600); // 시리얼 통신 시작 lcd.begin(16, 2); // 16x2 LCD 선언 pinMode(LED, OUTPUT); // 먼지센서 LED 핀 설정 } void loop() { //먼지센서 코드 digitalWrite(LED, LOW); // 적외선 LED ON delayMicroseconds(samplingTime); dustval = analogRead(DUST); //먼지센서 값 읽기 delayMicroseconds(deltaTime); digitalWrite(LED, HIGH); // 적외선 LED OFF delayMicroseconds(sleepTime); voltage = dustval * (5.0 / 1024.0); // 전압 구하기 dustug = 0.17 * voltage - 0.1; // ug 단위 변환 dus = dustug * 1000; Serial.print("Dust Sensor Voltage: "); Serial.print(voltage); Serial.println("V"); Serial.print("Dust Value: "); Serial.print(dus); // unit: mg/m3 Serial.println("ug");
//dht11 온습도센서 코드 int h = dht.readHumidity(); // 습도 값 구하기 int t = dht.readTemperature(); // 온도 값 구하기 Serial.print("Humidity: "); Serial.print(h); Serial.println(" %\t"); Serial.print("Temperature: "); Serial.print(t); Serial.println(" C");
//1602 LCD 모듈 코드 lcd.clear(); analogWrite(6, 120); lcd.setCursor(0, 0); lcd.print("H: "); lcd.print(h); lcd.print(" % "); lcd.print("T: "); lcd.print(t); lcd.print(" C"); lcd.setCursor(0, 1); lcd.print("Dust: "); if (dus > 0) { a = dus; lcd.print(a); } else { lcd.print(a); } lcd.print("ug");
//RGB LED 모듈 코드 if (a < 35) { // 좋음 analogWrite(9, 0); analogWrite(10, 20); } if (a > 35 & a < 75) { // 나쁨 analogWrite(9, 30); analogWrite(10, 3); } if (a > 75) { // 매우나쁨 analogWrite(9, 20); analogWrite(10, 0); } delay(1000); }
판매처 - 메카솔루션 (http://mechasolution.com) / 디스트리뷰터 문의 - ![]() ![]() |