forked from hantsairquality/monitor_v1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSharp_gp2y1010au_e.ino
45 lines (32 loc) · 1010 Bytes
/
Sharp_gp2y1010au_e.ino
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*
Standalone Sketch to use with a Arduino UNO and a
Sharp Optical Dust Sensor GP2Y1010AU0F
does not account for read write times, redo with time interupts
*/
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;
void setup(){
Serial.begin(9600);
pinMode(ledPower,OUTPUT);
}
void loop(){
digitalWrite(ledPower,HIGH); // power on the LED
delayMicroseconds(samplingTime);
voMeasured = analogRead(measurePin); // read the dust value
delayMicroseconds(deltaTime);
digitalWrite(ledPower,LOW); // turn the LED off
delayMicroseconds(sleepTime);
// 0 - 5V mapped to 0 - 1023 integer values
// recover voltage
calcVoltage = voMeasured * (5.0 / 1024.0);
Serial.print("Voltage: ");
Serial.print(calcVoltage);
Serial.print('\n');
// delay(1000);
}