https://blog.naver.com/darknisia/221222455928
https://devicemart.blogspot.com/2019/12/gp2y1010au0f.html
/*
Standalone Sketch to use with a Arduino UNO and a
Sharp Optical Dust Sensor GP2Y1010AU0F
*/
int measurePin = A0; //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
// linear eqaution taken from http://www.howmuchsnow.com/arduino/airquality/
// Chris Nafis (c) 2012
dustDensity = voMeasured*0.000830078125 - 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);
}
'임베디드 > Arduino' 카테고리의 다른 글
아두이노 내부 풀업 저항 사용하기 (0) | 2020.11.15 |
---|---|
발열패드 COM-11288 (0) | 2020.10.22 |
dht22 (0) | 2020.10.21 |
analogWrite() 함수 (0) | 2020.09.18 |
RGB LED 랜덤함수 (0) | 2020.09.18 |