/
SGHv3
128 lines (97 loc) · 3.32 KB
/
SGHv3
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*
Standalone Sketch to use with a Arduino Duemilanove, Uno, etc.... and a
Sharp Optical Dust Sensor GP2Y1010AU0F
06.11.2016 #thr
Sharp pin 1 (V-LED) => 5V (connected to 150ohm resister)
Sharp pin 2 (LED-GND) => Arduino GND pin
Sharp pin 3 (LED) => Arduino pin 2
Sharp pin 4 (S-GND) => Arduino GND pin
Sharp pin 5 (Vo) => Arduino A5 pin
Sharp pin 6 (Vcc) => 5V
Hardware connections:
- (GND) to GND
+ (VDD) to 3.3V
(WARNING: do not connect + to 5V or the sensor will be damaged!)
You will also need to connect the I2C pins (SCL and SDA) to your
Arduino. The pins are different on different Arduinos:
Any Arduino pins labeled: SDA SCL
Uno, Redboard, Pro: A4 A5
Mega2560, Due: 20 21
Leonardo: 2 3
Leave the IO (VDDIO) pin unconnected. This pin is for connecting
the BMP180 to systems with lower logic levels such as 1.8V
*/
#include "GP2Y1010AU0F.h"
#include <SFE_BMP180.h>
#include <Wire.h>
int measurePin = 0; //Connect dust sensor to Arduino A0 pin
int ledPower = 12; //Connect D12 led driver pins of dust sensor to Arduino D12
double volt;
//Hardware pin definitions - UV-Senor
int UVOUT = A2; //Output from the sensor
int REF_3V3 = A1; //3.3V power on the Arduino board
//int UVOUT2 = A3; //Output from the sensor
GP2Y1010AU0F DustSensor(ledPower, measurePin);
SFE_BMP180 pressure;
//double baseline; // baseline pressure
#define ALTITUDE 485.590 // Altitude of SparkFun's HQ in Boulder, CO. in meters
int pseudo;
struct pressureValues {
double T;
double P;
double p0;
double a;
} pressureValue;
void setup() {
Serial.begin(9600);
pinMode(UVOUT, INPUT);
pinMode(REF_3V3, INPUT);
//pinMode(UVOUT2, INPUT);
pressure.begin();
}
void loop() {
int uvLevel = averageAnalogRead(UVOUT);
//int uvLevel2 = averageAnalogRead(UVOUT2);
int refLevel = averageAnalogRead(REF_3V3);
// char status;
// double T, P, p0, a;
struct pressureValues Messung;
//Use the 3.3V power pin as a reference to get a very accurate output value from sensor
float outputVoltage = 3.3 / refLevel * uvLevel;
float uvIntensity = mapfloat(outputVoltage, 0.99, 2.8, 0.0, 15.0); //Convert the voltage to a UV intensity level
Messung = _bmp180();
if ( DustSensor.raw() >= 0.0 ) {
Serial.print(Messung.p0);
Serial.print(",");
Serial.print(Messung.P);
Serial.print(",");
Serial.print(Messung.T);
Serial.print(",");
Serial.print(100.0 * DustSensor.density(), 4); // unit: mg/m3
Serial.print(",");
Serial.print(DustSensor.voltage(), 4); // unit: Volt
Serial.print(",");
//Serial.print(" / UV Intensity (mW/cm^2): ");
Serial.println(uvIntensity);
/*Serial.print(" / UV Intensity 2(mW/cm^2): ");
Serial.print(uvIntensity2);
Serial.println(); */
}
delay(1000);
}
//Takes an average of readings on a given pin
//Returns the average
int averageAnalogRead(int pinToRead)
{
byte numberOfReadings = 8;
unsigned int runningValue = 0;
for(int x = 0 ; x < numberOfReadings ; x++)
runningValue += analogRead(pinToRead);
runningValue /= numberOfReadings;
return(runningValue);
}
//The Arduino Map function but for floats
float mapfloat(float x, float in_min, float in_max, float out_min, float out_max)
{
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}