-
Notifications
You must be signed in to change notification settings - Fork 0
/
1877-Earthquake Detection System.ino
89 lines (67 loc) · 2.46 KB
/
1877-Earthquake Detection System.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
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
#include "arduino_secrets.h"
#include "thingProperties.h"
const int buzzerPin = D5; // Buzzer pin
const int vibrationPin = D6; // Vibration sensor pin
const int redLedPin = D1; // Red LED pin
const int blueLedPin = D2; // Blue LED pin
const int vibrationThreshold = 5; // Threshold for detecting seismic activity
// Variables for tracking events
bool earthquakeAlert = false;
int vibrationCount = 0;
int vibrationDuration = 0;
void setup() {
Serial.begin(9600);
initProperties();
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo();
// Initialize buzzer, LEDs, and vibration sensor
pinMode(buzzerPin, OUTPUT);
digitalWrite(buzzerPin, LOW); // Turn off buzzer initially
pinMode(vibrationPin, INPUT); // Vibration sensor pin
pinMode(redLedPin, OUTPUT);
pinMode(blueLedPin, OUTPUT);
digitalWrite(redLedPin, LOW);
digitalWrite(blueLedPin, LOW);
}
void loop() {
ArduinoCloud.update();
// Read vibration sensor
int vibration = digitalRead(vibrationPin);
Serial.print("Vibration Sensor: ");
Serial.println(vibration ? "Vibration Detected" : "No Vibration");
// Check for building collapse (continuous vibrations)
if (vibration == HIGH) {
vibrationCount++;
Serial.println(vibrationCount);
if (vibrationCount >= vibrationThreshold) {
triggerEarthquakeAlert() ;
//collapseAlert1 = collapseAlert;
}
} else {
vibrationCount = 0; // Reset count if vibration stops
}
// delay(500); // Delay for stability
}
// Function to trigger earthquake alert
void triggerEarthquakeAlert() {
earhquakealert1 = "Earthquake detected!";
playSiren(); // Start siren
earthquakeAlert = true; // Update cloud variable for IFTTT trigger
Serial.println("Earthquake detected! Alert triggered.");
}
void playSiren() {
for (int i = 0; i < 20; i++) { // Repeat the tone 20 times for a longer sound
tone(buzzerPin, 800); // Lower frequency (800 Hz)
digitalWrite(redLedPin, HIGH);
digitalWrite(blueLedPin, LOW);
delay(300); // Play for 300 milliseconds
tone(buzzerPin, 1200); // Higher frequency (1200 Hz)
digitalWrite(redLedPin, LOW);
digitalWrite(blueLedPin, HIGH);
delay(300); // Play for 300 milliseconds
}
noTone(buzzerPin); // Stop the tone after the loop
digitalWrite(redLedPin, LOW);
digitalWrite(blueLedPin, LOW);
}