-
Notifications
You must be signed in to change notification settings - Fork 34
/
smoke.ino
41 lines (36 loc) · 1.1 KB
/
smoke.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
// Threshold value is the magnitude or intensity that must be
// exceeded for a certain phenomenon too occur. We're keeping it
// sensorThres = 400. The value 400 has been choosen and tested
// due to reason how the circuit will behave during favourable condition.
// If smoke detection value will be greater than threshold then
// alarm will be activated. If smoke detection value will be less than
// threshold then alarm will remain silent.
int redLed = 12;
int greenLed = 11;
int buzzer = 10;
int smokeA0 = A5;
// Your threshold value
int sensorThres = 400;
void setup() {
pinMode(redLed, OUTPUT);
pinMode(greenLed, OUTPUT);
pinMode(buzzer, OUTPUT);
pinMode(smokeA0, INPUT);
Serial.begin(9600);
}
void loop() {
int analogSensor = analogRead(smokeA0);
Serial.print("Pin A0: ");
Serial.println(analogSensor);
// Checks if it has reached the threshold value
if (analogSensor > sensorThres) {
digitalWrite(redLed, HIGH);
digitalWrite(greenLed, LOW);
tone(buzzer, 1000, 200);
} else {
digitalWrite(redLed, LOW);
digitalWrite(greenLed, HIGH);
noTone(buzzer);
}
delay(100);
}