-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpollution.h
executable file
·64 lines (55 loc) · 1.72 KB
/
pollution.h
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
static const uint8_t D8 = 15;
const int ledPin = D8; // IRED pin
static const uint8_t D9 = 3;
const int buzzerPin =D9;
const int dustPin = A0; // dust sensor - node A0 pin
float voltsMeasured = 0; //raw voltage data from sensor
float calcVoltage = 0; //refined voltage data range (0-5)volts
float dustDensity = 0; //dust density measured with refrence to refined voltage
char data; //data received form bluetooth
int num; //data mapped 0 to 9
void s_read() //read data from the sensor
{
digitalWrite(ledPin, LOW); // power on the LED
delayMicroseconds(300);
voltsMeasured = analogRead(dustPin); // read the dust value
delayMicroseconds(40);
digitalWrite(ledPin, HIGH); // turn the LED off
delayMicroseconds(9680);
if (Serial.available())
{
data = Serial.read();
Serial.println(data);
}
}
void s_calculate() // calculate the pollution density
{
//measure your 5v and change below
calcVoltage = voltsMeasured * (5.0 / 1024.0); //formula for voltage calculation
dustDensity = 170 * ( calcVoltage -0.0); //0.0 for calibration
num = map(dustDensity, 0, 700, 0, 10);// mapping of dust density between 0-10
}
void s_print()
{
Serial.println("GP2Y1010AU0F readings");
Serial.print("Raw Signal Value = ");
Serial.println(voltsMeasured);
Serial.print("Voltage = ");
Serial.println(calcVoltage);
Serial.print("Dust Density = ");
Serial.println(dustDensity); // ug/m3
Serial.println("");
}
void s_send() //for streaming to bluetooth device
{
Serial.println(dustDensity);
}
void dangerCheck() //For buzzer
{
if (dustDensity >= 220)
{
tone(buzzerPin, 800);
delay(91);
noTone(buzzerPin);
}
}