-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalarma_final.ino
More file actions
84 lines (69 loc) · 2.4 KB
/
alarma_final.ino
File metadata and controls
84 lines (69 loc) · 2.4 KB
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
int WaterAlarm = A0;
int Buzzer = 4;
int Led_water = 3;
int Led_gas = 2;
int water;
//boolean water; //simply reads 1 or 0 as a value 1 when detecting water
// here i set up the tones, you can change them @ void loop.
int tones[] = {261, 277, 293, 311, 329, 349, 369, 392, 415, 440, 466, 493, 523 ,554};
// 1 2 3 4 5 6 7 8 9 10 11 12 13 14
// You can add more tones but i added 14. Just fill in what tone you would like to use, @ void loop you see " tone(Buzzer, tones[12]); " below, digitalWrite(Buzzer, HIGH);
// here you can change the tones by filling in a number between 1 and 14
long previousMillis_water = 0; // will store last time LED was updated
long interval_water = 1000;
int GasSensor = A1;
//int Led_gas = 11;
long previousMillis_gas=0;
long interval_gas=1000;
int gas;
void setup() {
Serial.begin(9600);
pinMode (WaterAlarm, INPUT);
pinMode (GasSensor, INPUT);
//pinMode (Switch,INPUT);
pinMode (Buzzer, OUTPUT);
pinMode (Led_water, OUTPUT);
pinMode (Led_gas, OUTPUT);
}
void loop(){
unsigned long currentMillis = millis();
if(currentMillis - previousMillis_water >interval_water){
previousMillis_water = currentMillis;
water= analogRead(WaterAlarm);
Serial.print("APA:");
Serial.println(WaterAlarm);
if(water >100){
/*client.println("Alerta APA!!!");
client.println("<br />");*/
digitalWrite(Led_water, HIGH);
digitalWrite(Buzzer, HIGH);
tone(Buzzer, tones[8]);
}
else
{
/*client.println("Alarma apa functionala");
client.println("<br />"); */
digitalWrite(Led_water, LOW);
digitalWrite(Buzzer, LOW);
noTone(Buzzer);
}
}
if(currentMillis - previousMillis_gas > interval_gas){
previousMillis_gas = currentMillis;
gas =analogRead(GasSensor);
Serial.print("GAZ:");
Serial.println(WaterAlarm);
if(gas>800)
{
digitalWrite(Led_gas, HIGH);
digitalWrite(Buzzer,HIGH);
tone(Buzzer, tones[6]);
}
else
{
digitalWrite(Led_gas, LOW);
digitalWrite(Buzzer, LOW);
noTone(Buzzer);
}
}
}