Danny van den Brande
Published © CC BY-SA

Earthquake Alarm Using the KY-002

This time I made a Basic earthquake alarm with the KY-002 Shock sensor.

BeginnerFull instructions provided1 hour1,628
Earthquake Alarm Using the KY-002

Things used in this project

Story

Read more

Schematics

Schematic

Code

EARTHQUAKE_ALARM.ino

Arduino
This code is a basic code and a simple example on how to make a Eartquake alarm for example
//Author: Danny van den Brande
//This code is a basic code and a simple example on how to make a Eartquake alarm for example
//Feel free to do what you want with this code.
int GreenLed = 4;
int RedLed = 5;
int Shock = 6; 
int Buzzer = 7;
int val; // define numeric variables val

// 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

void setup ()
{
  pinMode (GreenLed, OUTPUT) ; 
  pinMode (RedLed, OUTPUT) ; 
  pinMode (Shock, INPUT) ; //vibration sensor
  pinMode (Buzzer, OUTPUT) ;
}
void loop ()
{
  val = digitalRead (Shock) ; // Reads Digital Pin of sensor.
  if (val == HIGH) // When the shock sensor detects a signal, LED flashes
  {
    digitalWrite (RedLed, LOW);
    digitalWrite (GreenLed, HIGH);
    digitalWrite (Buzzer, LOW);
  }
  else
  {
    digitalWrite (RedLed, HIGH);
    digitalWrite (GreenLed, LOW);
    digitalWrite(Buzzer, HIGH); // here the Buzzer is set high in order to make a sound.
    tone(Buzzer, tones[6]); //here we set the tone by choosing from number 1 to 14
    delay (50);
    digitalWrite(Buzzer, LOW); // here we set the buzzer low and next we set noTone for the buzzer to make a break.
    noTone(Buzzer);
    delay (50); //this is the delay between each buzzer beep. You can play with the sounds by choosing from number 1 to 14
    digitalWrite(Buzzer, HIGH);
    tone(Buzzer, tones[9]);
    delay (100);
    digitalWrite(Buzzer, LOW);
    noTone(Buzzer);
  }
}

Credits

Danny van den Brande

Danny van den Brande

36 projects • 108 followers
"Hello world."

Comments