Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
Tags
- EC2종료
- GP2Y1010AU
- AutoPermissions
- 중국 가정식
- 자자손손 멸치국수
- 제주
- EC2
- 사진찍기 좋음
- GradleException
- 광어튀김 서비스
- 무조건 비빔밥
- 로이앤메이
- Linux
- 리눅스
- 서귀다원
- pm2.5
- 한아름목장
- 성산
- 지은이네 밥상
- 가성비
- 구조에 청소가 필요합니다
- permission cannot be null or empty
- 펑후
- 종가식당
- 갈치공장
- 1602 LCD
- 람다
- 원동항공
- 두문포갈치
- 안매움
Archives
- Today
- Total
내 소소한..
PM2.5 센서 + 1602 LCD로 나만의 미세먼지 센서 만들기 (1) 본문
맨 위에 연필깎이처럼 생긴 구멍있는게 샤프 미세먼지 센서. 아래 LCD가 저렴이 1602 LCD.
맨 위에 연필깎이처럼 생긴 구멍있는게 샤프 미세먼지 센서. 아래 LCD가 저렴이 1602 LCD.
저렴이 먼지센서 샤프(sharp) GP2Y1010AU 로 값을 입력받아서 LCD로 출력한다.
케이스가 없어서 택배 박스에.. 저렴이 3D 프린터라도 하나 사야겠다!!!
핀 배열, 전체 회로도는 다음에 올리고 (다음 글에서 참고: http://ilsognobella.tistory.com/9)
소스코드는 아래와 같다.
#include <liquidcrystal.h>
LiquidCrystal lcd(7, 8, 9, 10, 11, 12); //RS,E,DB4,DB5,DB6,DB7
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;
float avgDustDensity = 0;
float sumDustDensity = 0;
float rawDustDensity[10];
int arraySize = sizeof(rawDustDensity) / sizeof(sumDustDensity);
int seq;
int i;
int arrayFillCnt;
char strbuf[16];
void setup() {
Serial.begin(9600);
pinMode(ledPower, OUTPUT);
lcd.begin(16, 2);
lcd.setCursor(0, 0);
lcd.write("HS PM2.5 CENSOR");
lcd.setCursor(0, 1);
lcd.write(" ");
}
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;
// 음수는 건너뛴다.
if ( dustDensity < 0 ) {
delay(1000);
return;
}
// 평균을 구하기 위한 20개 원시 먼지농도 배열에 값을 입력
rawDustDensity[ seq % arraySize ] = dustDensity;
arrayFillCnt++;
if ( arrayFillCnt > arraySize ){
arrayFillCnt = arraySize;
}
// 평균
sumDustDensity = 0;
for ( i = 0; i < arrayFillCnt; i++ ) {
sumDustDensity += rawDustDensity[i];
}
if ( arrayFillCnt >= 3) {
avgDustDensity = (sumDustDensity - getMin() - getMax()) / (arrayFillCnt-2);
}
Serial.print("Raw Signal Value (0-1023): ");
Serial.print(voMeasured);
Serial.print(" - Voltage: ");
Serial.print(calcVoltage);
Serial.print(" - Dust Density: ");
Serial.print(dustDensity * 1000); // unit: mg/m3
Serial.print(" - Avg: ");
Serial.print(avgDustDensity * 1000); // unit: mg/m3
Serial.print(" - Sum: ");
Serial.print(sumDustDensity * 1000); // unit: mg/m3
Serial.println(sizeof(rawDustDensity)); // unit: mg/m3
lcd.setCursor(0, 1);
sprintf(strbuf,
"V:%01d.%02d D:%3d.%02d",
(int)calcVoltage,
((int)(calcVoltage * 100)) % 100,
(int)(avgDustDensity * 1000),
((long)(avgDustDensity * 100000L)) % 100
);
lcd.write(strbuf);
delay(1000);
seq++;
if ( seq % arraySize == 0 ) {
seq = 0;
}
}
float getMin() {
float min = rawDustDensity[0];
int i = 0;
for ( i = 1; i < arraySize; i++ ) {
if ( min > rawDustDensity[i] ) {
min = rawDustDensity[i];
}
}
return min;
}
float getMax() {
float max = rawDustDensity[0];
int i = 0;
for ( i = 1; i < arraySize; i++ ) {
if ( max < rawDustDensity[i] ) {
max = rawDustDensity[i];
}
}
return max;
}
'IT > Arduino' 카테고리의 다른 글
| PM2.5 센서 + 1602 LCD로 나만의 미세먼지 센서 만들기 (2) (1) | 2018.10.01 |
|---|
Comments