Earthquake Detector Alarm using Arduino - Internet of Things

Earthquake Detector Alarm using Arduino

Earthquake Detector Arduino Shield using Accelerometer
An earthquake is an unpredictable natural disaster that causes damage to lives and property. It happens suddenly and we cannot stop it but we can be alerted from it. In todays time, there are many technologies which can be used to detect the small shakes and knocks, so that we can take precautions prior to some major vibrations in earth. Here we are using Accelerometer ADXL335 to detect the pre-earthquake vibrations. Accelerometer ADXL335 is highly sensitive to shakes and vibrations along with all the three axes. Here we are building an Arduino based Earthquake Detector using Accelerometer.
We are here building this Earthquake detector as a Arduino Shield on PCB and will also show the Vibrations Graph on computer using Processing.

Components Required:
·         Arduino UNO
·         Accelerometer ADXL335
·         16x2 LCD
·         Buzzer
·         BC547 transistor
·         1k Resistors
·         10K POT
·         LED
·         Power Supply 9v/12v
·         Berg sticks male/female
Accelerometer:
Pin Description of accelerometer:
  1. Vcc         5 volt supply should connect at this pin.
  2. X-OUT   This pin gives an Analog output in x direction
  3. Y-OUT   This pin give an Analog Output in y direction
  4. Z-OUT   This pin gives an Analog Output in z direction
  5. GND      Ground
  6. ST          This pin used for set sensitivity of sensor
 

Also check our other projects using Accelerometer: 
·         Ping Pong Game using Arduino

Working Explanation:
Working of this Earthquake Detector is simple. As we mentioned earlier that we have used Accelerometer for detecting earthquake vibrations along any of the three axes so that whenever vibrations occur accelerometer senses that vibrations and convert them into equivalent ADC value. Then these ADC values are read by Arduino and shown over the 16x2 LCD. We have also shown these values on Graph using Processing. Learn more about Accelerometer by going through our other Accelerometer projects here.
First we need to calibrate the Accelerometer by taking the samples of surrounding vibrations whenever Arduino Powers up. Then we need to subtract those sample values from the actual readings to get the real readings. This calibration is needed so that it will not show alerts with respect to its normal surrounding vibrations. After finding real readings, Arduino compares these values with predefined max and min values. If Arduino finds any changes values are more then or less then the predefined values of any axis in both direction (negative and positive) then Arduino trigger the buzzer and shows the status of alert over the 16x2 LCD and a LED also turned on as well. We can adjust the sensitivity of Earthquake detector by changing the Predefined values in Arduino code.

Demonstration Video and Arduino Code are given at the end of the article.

Circuit Explanation:
Circuit of this Earthquake detector Arduino Shield PCB is also simple. In this project, we have used Arduino that reads accelerometers analog voltage and convert them into the digital values. Arduino also drives the buzzer, LED, 16x2 LCD and calculate and compare values and take appropriate action. Next part is Accelerometer which detects vibration of earth and generates analog voltages in 3 axes (X, Y, and Z). LCD is used for showing X, Y and Z axiss change in values and also showing alert message over it. This LCD is attached to Arduino in 4-bit mode. RS, GND, and EN pins are directly connected to 9, GND and 8 pins of Arduino and rest of 4 data pins of LCD namely D4, D5, D6 and D7 are directly connected to digital pin 7, 6, 5 and 4 of Arduino. The buzzer is connected to pin 12 of Arduino through an NPN BC547 transistor. A 10k pot is also used for controlling the brightness of the LCD.  

Programming Explanation:
In this Earthquake Detector Arduino Shield, we have made two codes: one for Arduino to detect an earthquake and another for Processing IDE to plot the earthquake vibrations over the graph on Computer. We will learn about both the codes one by one:

Arduino code:
First of all, we calibrate the accelerometer with respect to its placing surface, so that it will not show alerts with respect to its normal surrounding vibrations. In this calibration, we take some samples and then take an average of them and stores in a variable.
  for(int i=0;i<samples;i++)      // taking samples for calibration
  {
    xsample+=analogRead(x);
    ysample+=analogRead(y);
    zsample+=analogRead(z);
  }

  xsample/=samples;   // taking avg for x
  ysample/=samples;   // taking avg for y
  zsample/=samples;   // taking avg for z
 
  delay(3000);
  lcd.clear();
  lcd.print("Calibrated");
  delay(1000);
  lcd.clear();
  lcd.print("Device Ready");
  delay(1000);
  lcd.clear();
  lcd.print(" X     Y     Z   ");

Now whenever Accelerometer takes readings, we will subtract those sample values from the readings so that it can ignore surroundings vibrations.
    int value1=analogRead(x);   // reading x out
    int value2=analogRead(y);   //reading y out
    int value3=analogRead(z);   //reading z out

    int xValue=xsample-value1;    // finding change in x
    int yValue=ysample-value2;    // finding change in y
    int zValue=zsample-value3;    // finding change in z

  /*displying change in x,y and z axis values over lcd*/
    lcd.setCursor(0,1);
    lcd.print(zValue);
    lcd.setCursor(6,1);
    lcd.print(yValue);
    lcd.setCursor(12,1);
    lcd.print(zValue);
    delay(100)

Then Arduino compares those calibrated (subtracted) values with predefined limits. And take action accordingly. If the values are higher than predefined values then it will beep the buzzer and plot the vibration graph on computer using Processing.
      /* comparing change with predefined limits*/
    if(xValue < minVal || xValue > maxVal  || yValue < minVal || yValue > maxVal  || zValue < minVal || zValue > maxVal)
    {
      if(buz == 0)
      start=millis();   // timer start
       buz=1;       // buzzer / led flag activated
    }

   else if(buz == 1)        // buzzer flag activated then alerting earthquake
   {
      lcd.setCursor(0,0);
      lcd.print("Earthquake Alert   ");
      if(millis()>= start+buzTime)   
      buz=0;
   }

Processing code:
Below is the Processing Code attached, you can download the code from below link:

We have designed a graph using Processing, for earth quake vibrations, in which we defined the size of the window, units, font size, background, reading and displaying serial ports, open selected serial port etc.
 // set the window sizeand Font size
  f6 = createFont("Arial",6,true);
  f8 = createFont("Arial",8,true);
  f10 = createFont("Arial",10,true);
  f12 = createFont("Arial",12,true);
  f24 = createFont("Arial",24,true);
  size(1200, 700);       

 // List all the available serial ports
 println(Serial.list());
 myPort = new Serial(this, "COM43", 9600);
 println(myPort);
 myPort.bufferUntil('\n');
 background(80)

In below function, we have received data from serial port and extract required data and then mapped it with the size of the graph.
 // extracting all required values of all three axis:
 int l1=inString.indexOf("x=")+2;
 String temp1=inString.substring(l1,l1+3);
 l1=inString.indexOf("y=")+2;
 String temp2=inString.substring(l1,l1+3);
 l1=inString.indexOf("z=")+2;
 String temp3=inString.substring(l1,l1+3);

 //mapping x, y and z value with graph dimensions
 float inByte1 = float(temp1+(char)9);
 inByte1 = map(inByte1, -80,80, 0, height-80);
 float inByte2 = float(temp2+(char)9);
 inByte2 = map(inByte2,-80,80, 0, height-80);
 float inByte3 = float(temp3+(char)9);
 inByte3 = map(inByte3,-80,80, 0, height-80);
 float x=map(xPos,0,1120,40,width-40);

After this, we have plotted unit space, max and min limits, values of x, y and z-axis.
  //ploting graph window, unit
  strokeWeight(2);
  stroke(175);                       
  Line(0,0,0,100);
  textFont(f24);      
  fill(0,00,255);
  textAlign(RIGHT);
  xmargin("EarthQuake Graph By Circuit Digest",200,100);
 
   fill(100);
   strokeWeight(100);
   line(1050,80,1200,80);
   .... ....
   ..........

After this we plot the values over the graph by using 3 different colors as Blue for x-axis value, green color for y axis and z is represented by red color.
   stroke(0,0,255);        
   if(y1 == 0)
   y1=height-inByte1-shift;
   line(x, y1, x+2, height-inByte1-shift) ;
   y1=height-inByte1-shift;
  
   stroke(0,255,0);           
   if(y2 == 0)
   y2=height-inByte2-shift;
   line(x, y2, x+2, height-inByte2-shift) ;
   y2=height-inByte2-shift;
  
   stroke(255,0,0);            
   if(y2 == 0)
   y3=height-inByte3-shift;
   line(x, y3, x+2, height-inByte3-shift) ;
   y3=height-inByte3-shift;

Also learn more about processing by going through our other Processing projects.

Circuit and PCB Design using EasyEDA:
EasyEDA is not only the one stop solution for schematic capture, circuit simulation and PCB design, they also offer a low cost PCB Prototype and Components Sourcing service. They recently launched their component sourcing service where they have a large stock of electronic components and users can order their required components along with the PCB order.
While designing your circuits and PCBs, you can also make your circuit and PCB designs public so that other users can copy or edit them and can take benefit from there, we have also made our whole Circuit and PCB layouts public for this Earthquake Indicator Shield for Arduino UNO, check the below link:
Below is the Snapshot of Top layer of PCB layout from EasyEDA, you can view any Layer (Top, Bottom, Topsilk, bottomsilk etc) of the PCB by selecting the layer form the LayersWindow.

You can also see Photo view of PCB using EasyEDA:

Calculating and Ordering Samples online:
After completing the design of PCB, you can click the icon of Fabrication output, which will take you on the PCB order page. Here you can view your PCB in Gerber Viewer or download Gerber files of your PCB. Here you can select the number of PCBs you want to order, how many copper layers you need, the PCB thickness, copper weight, and even the PCB color. After you have selected all of the options, click Save to Cartand complete your order. Recently they have dropped their PCB rates significantly and now you can order 10 pcs 2-layer PCB with 10cm x 10cm size just for $2.

Here is the PCBs I Got from EasyEDA:

Below are the pictures of final Shield after soldering the components on PCB:
 Demo & Code



Earthquake Detector Alarm using Arduino Earthquake Detector Alarm using Arduino Reviewed by XXX on สิงหาคม 27, 2560 Rating: 5

ไม่มีความคิดเห็น