Thursday, April 12, 2012

Low Cost Earth Quake Alarm using Arduino

Yesterday (11th of April 2012) was the first time I have ever experienced an Earth Quake in my life. It was strange because Sri Lanka is said to be a country less prone for Earth Quakes and there hasn't been one as violent as yesterday's one for at least 2 decades.

Even though most of the buildings were shaking along with the things inside for about 50 - 60 seconds, many people haven't noticed the shakes, may be due to the inexperience with Earth Quakes or due to confusion. But the most concerning thing is almost all Sri Lankan buildings are not Earth Quake safe like those in Japan. So feeling the Earth Quake and leaving the building as early as possible is crucial. Especially during night time where people will be sleeping.

For this reason I was inspired to create a Low Cost Earth Quake Alarm which will help those who can't feel an Earth Quake to get out in time and be safe.

I managed to build a small prototype using things lying around in my hack space which are;
  1. Arduino (Any Model)
  2. One Tilt Switch
  3. One Buzzer or Piezo Speaker
  4. One 1K Resistor
  5. 6 Jumper Cables
With the above components I built the below prototype


And used the following arduino sketch to detect changes in Tilt Switch which is connected to analog in pin A0 and if it exceeds a predefined threshold for a predefined period of time, alarm using the Piezo Speaker or Buzzer which is connected to pin no 10 which has PWM.

##############################
##     Shazin Sadakath      ##
##############################

#define TILT_SWITCH_PIN A0
#define BUZZER_PIN 10
#define MAX 100
int tiltValue = 0;
int previousTiltValue = 0;
int valueThreshold = 5;
int timeThreshold = 2 ;
int time = 0;

void setup() 
{
   pinMode(BUZZER_PIN, OUTPUT);
}

void loop() 
{
  tiltValue = analogRead(TILT_SWITCH_PIN);
  if(abs(tiltValue - previousTiltValue) >= valueThreshold)
  {
    time = time + 1;
  }
  else
  {
    reset();
  }
  if(time >= timeThreshold) 
  {
   analogWrite(BUZZER_PIN, MAX);
   delay(500);
   reset();
  }
  previousTiltValue = tiltValue;
  delay(500);
}

void reset() 
{
 time = 0;
 previousTiltValue = 0; 
 analogWrite(BUZZER_PIN, 0);
}

Finally I tested this with some minor shakes and it works. The alarm is going off until the shaking stops completely.



In Sri Lanka we can't buy off the shelf Commercial, Highly Accurate Earth Quake Detectors or Alarms yet so this prototype would be a life saver. Mounting this on a wall or on the roof where it is less like to be disturbed by people's movement and covering it in a box would make it less likely to produce false alarms.

Constructive Criticism is always welcome!

No comments:

Post a Comment