-
Notifications
You must be signed in to change notification settings - Fork 1
/
emergencyVentSystem.c
93 lines (83 loc) · 1.87 KB
/
emergencyVentSystem.c
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
#include "MQ135.h"
#include <SPI.h>
#include <Servo.h> //servo library
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);
MQ135 gasSensor = MQ135(A1);
int val;
int sensorPin = A1;
int sensorValue = 0;
Servo servo;
int servoPin =9;
int buzzer=11;
void setup() {
Serial.begin(9600);
pinMode(sensorPin, INPUT);
display.begin(SSD1306_SWITCHCAPVCC,0x3C);
display.clearDisplay();
display.display();
servo.attach(servoPin);
servo.write(0); //close cap on power on
delay(100);
servo.detach();
}
float temp;
void loop() {
val = analogRead(A1);
temp= analogRead(A0);
temp=temp*0.48828125;
Serial.print ("raw = ");
Serial.println (val);
float ppm = gasSensor.getPPM();
Serial.print ("ppm: ");
Serial.println (ppm);
Serial.print("Temperature: ");
Serial.print(temp);
Serial.print("C");
Serial.println();
if(ppm>10){ //we took this as the dummy data
servo.attach(servoPin);
delay(1);
servo.write(0);
delay(3000);
servo.write(360);
delay(1000);
servo.detach();
//buzzer
tone(buzzer, 45);
delay(1000);
noTone(buzzer);
delay(1000);
//oled display
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(18,43);
display.println("CO2");
display.setCursor(63,43);
display.println("(PPM)");
display.setTextSize(2);
display.setCursor(28,5);
display.println(ppm);
display.display();
display.clearDisplay();
delay(1000);
}
if(ppm<=10){
servo.attach(servoPin);
servo.write(0);
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(18,43);
display.println("CO2");
display.setCursor(63,43);
display.println("(PPM)");
display.setTextSize(2);
display.setCursor(28,5);
display.println(ppm);
display.display();
display.clearDisplay();
delay(1000);
}
}