Earthquake Detector Alarm Using Arduino
Earthquake Detector Alarm Using Arduino
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
Working Explanation:
Working of this Arduino Earthquake Detector is quite 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 Graphs using Processing. 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
surounding 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.
Circuit Explanation:
Circuit for this Earthquake detector Arduino Shield PCB is also simple. In this project, we have used
Arduino that reads accelerometer’s analogy 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
analogy voltages in 3 axes (X, Y, and Z). LCD is used for showing X, Y and Z axis’s 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.
Program
Programming Explanation:
In this Arduino earthquake Detector Project, 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 f
or x
ysample/=samples; // taking avg f
or y
zsample/=samples; // taking avg f
or 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); // re
ading x out
int value2=analogRead(y); //rea
ding y out
int value3=analogRead(z); //rea
ding 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 axi
s 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.
Processing code:
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.
In below function, we have received data from serial port and extract required data
and then mapped it with the size of the graph.
After this, we have plotted unit space, max and min limits, values of x, y and z-axis.
After this we plot the values over the graph by using 3 different colours as Blue for x-axis value,
green colour for y axis and z is represented by red colour.
stroke(0,0,255);
if(y1 == 0)
y1=height-inByte1-shift;
line(x, y1, x+2, height-inByte1-sh
ift) ;
y1=height-inByte1-shift;
stroke(0,255,0);
if(y2 == 0)
y2=height-inByte2-shift;
line(x, y2, x+2, height-inByte2-sh
ift) ;
y2=height-inByte2-shift;
stroke(255,0,0);
if(y2 == 0)
y3=height-inByte3-shift;
line(x, y3, x+2, height-inByte3-sh
ift) ;
y3=height-inByte3-shift;