준호씨의 블로그

아두이노 - 먼지 센서 + LCD 본문

메이커

아두이노 - 먼지 센서 + LCD

준호씨 2017. 5. 28. 19:34
반응형
지난 번 만들었던 것 참고: http://junho85.pe.kr/592

이번에는 지난번 만들었던 먼지측정기에 LCD 를 장착해 보기로 하였다. 일단 지인에게 빌려온 LCD 실드를 장착하고 https://www.arduino.cc/en/Tutorial/HelloWorld 에 있는 코드를 돌려 보았다.



LCD 실드는 인터넷 찾아 보니
과 같은 것 같다.

Universal Sheidl 에 저항 100옴, LCD (SD1602VBWB-XA), 가변저항, 핀헤더, 적층형 핀헤더를 이용해서 만든 것으로 보인다.

여기다가 기존처럼 먼지센서 연결해서 다음과 같이 LCD 코드와 먼지센서 코드를 조합한다.
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int ledPower = 12;
int measurePin = A0;
int samplingTime = 280;
int deltaTime = 40;
int sleepTime = 9680;
float voMeasured = 0;
float calcVoltage = 0;
float dustDensity = 0;
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("Dust Density");
pinMode(ledPower,OUTPUT);
pinMode(4, OUTPUT);
}
void loop() {
digitalWrite(ledPower, LOW); // power on the LED
delayMicroseconds(samplingTime);
// 먼지 센서를 값을 0.0V~3.3V 을 0~1024 값으로 변경해 줌.
voMeasured = analogRead(measurePin); // read the dust value
delayMicroseconds(deltaTime);
digitalWrite(ledPower, HIGH); // turn the LED off
delayMicroseconds(sleepTime);
// 입력된 볼트를 계산해 줌
calcVoltage = voMeasured * (3.3/1024);
// 볼트를 기준으로 미세먼지 값으로 변환해 줌, 데이터 시트을 참고 오차가 존재합니다.
dustDensity = (0.17 * calcVoltage - 0.1) * 1000;
// 아날로그로 읽어 들인 0-1024 수치
Serial.print("Raw Signal Value (0-1023): ");
Serial.print(voMeasured);
// 볼트로 계산해서 출력
Serial.print(" - Voltage: ");
Serial.print(calcVoltage);
// 미세먼지 수치 출력
Serial.print(" - Dust density [ug/m3]: ");
Serial.println(dustDensity);
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 1);
// print the number of seconds since reset:
// lcd.print(millis() / 1000);
lcd.print(dustDensity);
lcd.print(" [ug/m3]");
delay(1000);
}
view raw dust_lcd.ino hosted with ❤ by GitHub


짜잔~


여전히 센서 값은 이상하다. 저거 튜닝은 또 차차 해 봐야 겠다.

동작 동영상
반응형
Comments