dustsensor.ino

dustsensorv2.ino



첨부된 2 가지  케이스로 코딩됨.

미세먼지 측정센서로 측정된 미세먼지 농도를 
16x2 LCD 에 표현하기.


아두이노 코딩도 계속하다 보니 자연스럽게 되는것 같다. 전자회로도 또한 친숙해지는것 같고.
연습이 완벽하게 만든다고 했나? 생각보다 쉽게 만들어짐에 놀라웠다.

Practice makes perfect, thanks.


#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

int Vo = A0;
int V_LED = 2;

float Vo_value = 0;
float Voltage = 0;
float dustDensity = 0;
float dustCleanVoltage = 0.44;
int samplingTime = 280;
int deltaTime = 40;
int sleepTime = 9680;

void setup(){
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("dust");
Serial.begin(9600);

/*digital output:*/
pinMode(V_LED, OUTPUT);

/*analog input:*/
pinMode(Vo, INPUT);
}

/** references :
* http://blog.naver.com/PostView.nhn?blogId=darknisia&logNo=221222455928
* http://arduinodev.woofex.net/2012/12/01/standalone-sharp-dust-sensor/
* */
// 미세먼지 센서(GP2Y1010AU0F)
// : 적외선 발광 다이오드(IRED)와 포토다이오드가 대각선으로 배치되어 공기 중 먼지의 반사광을 감지
void loop(){
digitalWrite(V_LED,LOW); //ired 'on'
delayMicroseconds(samplingTime);
Vo_value = analogRead(Vo); //read the dust value
delayMicroseconds(deltaTime);// pulse width 0.32 - 0.28 = 0.04 msec
//0.32 msec의 펄스폭을 유지하기 위해 필요한 코드입니다

digitalWrite(V_LED,HIGH); //ired 'off'
delayMicroseconds(sleepTime);


/*
이 센서의 출력전압(Vo)는 먼지가 없을 때의 출력전압(Voc)과 먼지 농도(ΔV)에 비례하여 출력됩니다.
다시 표현하면 ΔV = Vo – Voc
미세먼지 농도[µg/m³] = (Vo – Voc) / 0.005
*/
Voltage = Vo_value * (5.0 / 1024.0);

dustDensity = (Voltage - dustCleanVoltage)/0.005;

Serial.print(" Raw Signal Value (0-1023):");
Serial.print(Vo_value);
Serial.print(" | Volatage:");
Serial.print(Voltage);
Serial.print(" | Dust Density:");
Serial.print(dustDensity);
Serial.print("[ug/m3]");
if(dustDensity<31){
Serial.println(" => [Great(~30)]");
} else if(dustDensity>30 && dustDensity<81){
Serial.println(" => [Good(31~80)]");
} else if(dustDensity>81 && dustDensity<151){
Serial.println(" => [Bad(81~150)]");
} else{
Serial.println(" => [Too Bad(151~)]");
}


// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 0);
lcd.print(dustDensity);
lcd.setCursor(0, 1);
if(dustDensity<31){
lcd.print(": Great(~30)");
} else if(dustDensity>30 && dustDensity<81){
lcd.print(": Good(31~80)");
} else if(dustDensity>81 && dustDensity<151){
lcd.print(": Bad(81~150)");
} else{
lcd.print(": Too Bad(151~)");
}
delay(5000);
}


 

+ Recent posts