미세먼지

3반 미세먼지 측정기 조 -아두이노 코드 포함

coding art 2017. 11. 13. 17:49
728x90

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 sum = 0;
float voMeasured = 0;
float calcVoltage = 0;
float dustDensity = 0;
float average_dustDensity;


void setup(){
  Serial.begin(9600);
  pinMode(ledPower,OUTPUT);// 미세먼지 센서 내부 LED
}
 
void loop() {

  average_dustDensity = particleSensing();
  Serial.print("P");
  Serial.println((int)average_dustDensity);
  delay(500);
 }

float particleSensing() {
  digitalWrite(ledPower,LOW); // power on the LED
  delayMicroseconds(samplingTime);
   voMeasured = analogRead(measurePin);
  delayMicroseconds(deltaTime);
  digitalWrite(ledPower,HIGH); // turn the LED off
  delayMicroseconds(sleepTime);
  
  // 0 - 5V mapped to 0 - 1023 integer values
  calcVoltage = voMeasured * (5.0 / 1024.0);
  if( calcVoltage > 0.6 ) {
  dustDensity =1000.0*( 0.172 * calcVoltage - 0.1);
 
  delay(190);
  }
  return dustDensity;
}//프로그램 끝