You are on page 1of 15

GROUP MEMBERS

P.PRABHAS

RITESH KUMAR

LOKESH

CHANDU
Arduino Earthquake Detector Alarm
with Seismic Graph using Accelerometer
s

SHARE

Introduction:
In this project, we will learn how to design Arduino Earthquake Detector Alarm with
Seismic Graph. We have used ADXL335 3 axis Accelerometer as a sensor for
detecting tilting, trembling, or any shaking movement of an earthquake. We have an
interfaced ADXL335 Accelerometer with Arduino and LCD display for designing
Arduino Earthquake Detector Alarm with Seismic Graph.
To learn detail about Accelerometer Working and Tutorial you can visit:
1. Accelerometer Basics and Tutorial Explanation
2. Acceleration Measurement with Accelerometer ADXL335 & Arduino

The Arduino code, as well as processing IDE code both, are given below. The
processing IDE code helps in drawing the graph of the tilting state. The buzzer or
LED is used as an alarm whenever the shaking threshold goes higher.

ADXL335 3 Axis Accelerometer:


Introduction:

This Accelerometer module is based on the popular ADXL335 three-axis analog


accelerometer IC, which reads off the X, Y, and Z acceleration as analog voltages. By
measuring the amount of acceleration due to gravity, an accelerometer can figure
out the angle it is tilted at with respect to the earth. By sensing the amount of
dynamic acceleration, the accelerometer can find out how fast and in what direction
the device is moving. Using these two properties, you can make all sorts of cool
projects, from musical instruments (imagine playing and having the tilt connected to
the distortion level or the pitch-bend) to a velocity monitor on your car (or your
children’s car). The accelerometer is very easy to interface to an Arduino Micro-
controller using 3 analog input pins and can be used with most other
microcontrollers, such as the PIC or AVR.

Features:
1. 3V-6V DC Supply Voltage
2. Onboard LDO Voltage regulator
3. It can be interface with 3V3 or 5V Microcontroller.
4. All necessary Components are populated.
5. Ultra-Low Power: 40uA in measurement mode, 0.1uA in standby@ 2.5V
6. Tap/Double Tap Detection
7. Free-Fall Detection
8. Analog output

Working of ADXL335 Accelerometer:


The most commonly used device is the piezoelectric accelerometer. As the name
suggests, it uses the principle of piezoelectric effect. The device consists of a
piezoelectric quartz crystal on which an accelerative force, whose value is to be
measured, is applied.

Due to the special self-generating property, the crystal produces a voltage that is
proportional to the accelerative force. The working and the basic arrangement is
shown in the figure below.

Arduino Earthquake Detector Alarm with Seismic Graph


using Accelerometer:
Components Required:
1. Arduino Uno Board
2. ADXL335 Accelerometer
3. 16 x 2 LCD Display
4. Buzzer
5. LED

Circuit Diagram & Connections:


Working Explanation:
In this Arduino Earthquake Detector Alarm with Seismic Graph 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.

Download the processing IDE from here: Processing IDE Link

First, upload the Arduino Code/program to the Arduino UNO board. After that open
processing IDE. Copy the code from below and paste it on IDE. Then the next step is
hit on the run. As soon as you hit run the graph starts running. So shake the
accelerometer and observe the graph.
Arduino Source Code/Program:
1#include<LiquidCrystal.h> // lcd Header
2LiquidCrystal lcd(7,6,5,4,3,2); // pins for LCD Connection
3
4#define buzzer 12 // buzzer pin
5#define led 13 //led pin
6
7#define x A0 // x_out pin of Accelerometer
8#define y A1 // y_out pin of Accelerometer
9#define z A2 // z_out pin of Accelerometer
10
11/*variables*/
12int xsample=0;
13int ysample=0;
14int zsample=0;
15long start;
16int buz=0;
17
18/*Macros*/
19#define samples 50
20#define maxVal 20 // max change limit
21#define minVal -20 // min change limit
22#define buzTime 5000 // buzzer on time
23
24void setup()
25{
26lcd.begin(16,2); //initializing lcd
27Serial.begin(9600); // initializing serial
28delay(1000);
29lcd.print("EarthQuake ");
30lcd.setCursor(0,1);
31lcd.print("Detector ");
32delay(2000);
33lcd.clear();
34lcd.print("Calibrating.....");
35lcd.setCursor(0,1);
36lcd.print("Please wait...");
37pinMode(buzzer, OUTPUT);
38pinMode(led, OUTPUT);
39buz=0;
40digitalWrite(buzzer, buz);
41digitalWrite(led, buz);
42for(int i=0;i<samples;i++) // taking samples for calibration
43{
44xsample+=analogRead(x);
45ysample+=analogRead(y);
46zsample+=analogRead(z);
47}
48
49xsample/=samples; // taking avg for x
50ysample/=samples; // taking avg for y
51zsample/=samples; // taking avg for z
52
53delay(3000);
54lcd.clear();
55lcd.print("Calibrated");
56delay(1000);
57lcd.clear();
58lcd.print("Device Ready");
59delay(1000);
60lcd.clear();
61lcd.print(" X Y Z ");
62}
63
64void loop()
65{
66int value1=analogRead(x); // reading x out
67int value2=analogRead(y); //reading y out
68int value3=analogRead(z); //reading z out
69
70int xValue=xsample-value1; // finding change in x
71int yValue=ysample-value2; // finding change in y
72int zValue=zsample-value3; // finding change in z
73
74/*displying change in x,y and z axis values over lcd*/
75lcd.setCursor(0,1);
76lcd.print(xValue);
77lcd.setCursor(6,1);
78lcd.print(yValue);
79lcd.setCursor(12,1);
80lcd.print(zValue);
81delay(100);
82
83/* comparing change with predefined limits*/
84if(xValue < minVal || xValue > maxVal || yValue < minVal || yValue > maxVal || zValue < minVal ||
85zValue > maxVal)
86{
87if(buz == 0)
88start=millis(); // timer start
89buz=1; // buzzer / led flag activated
90}
91
92else if(buz == 1) // buzzer flag activated then alerting earthquake
93{
94lcd.setCursor(0,0);
95lcd.print("Earthquake Alert ");
96if(millis()>= start+buzTime)
97buz=0;
98}
99
100else
101{
102lcd.clear();
103lcd.print(" X Y Z ");
104}
105
106digitalWrite(buzzer, buz); // buzzer on and off command
107digitalWrite(led, buz); // led on and off command
108
109/*sending values to processing for plot over the graph*/
110Serial.print("x=");
111Serial.println(xValue);
112Serial.print("y=");
113Serial.println(yValue);
114Serial.print("z=");
115Serial.println(zValue);
116Serial.println(" $");
}

Processing IDE Code/Program:


1import processing.serial.*;
2PFont f6,f8,f12,f10;
3PFont f24;
4Serial myPort; // The serial port
5int xPos = 0; // horizontal position of the graph
6float y1=0;
7float y2=0;
8float y3=0;
9
10void setup ()
11{
12// set the window size: and Font size
13f6 = createFont("Arial",6,true);
14f8 = createFont("Arial",8,true);
15f10 = createFont("Arial",10,true);
16f12 = createFont("Arial",12,true);
17f24 = createFont("Arial",24,true);
18size(1200, 700);
19
20// List all the available serial ports
21println(Serial.list());
22myPort = new Serial(this, "COM10", 9600);
23println(myPort);
24myPort.bufferUntil('\n');
25background(80);
26}
27
28void draw ()
29{
30serial ();
31}
32
33void serial()
34{
35String inString = myPort.readStringUntil('$'); // reading incomming date from serial
36if (inString != null)
37{
38// extracting all required values of all three axis:
39int l1=inString.indexOf("x=")+2;
40String temp1=inString.substring(l1,l1+3);
41l1=inString.indexOf("y=")+2;
42String temp2=inString.substring(l1,l1+3);
43l1=inString.indexOf("z=")+2;
44String temp3=inString.substring(l1,l1+3);
45
46//mapping x, y and z value with graph dimensions
47float inByte1 = float(temp1+(char)9);
48inByte1 = map(inByte1, -80,80, 0, height-80);
49float inByte2 = float(temp2+(char)9);
50inByte2 = map(inByte2,-80,80, 0, height-80);
51float inByte3 = float(temp3+(char)9);
52inByte3 = map(inByte3,-80,80, 0, height-80);
53float x=map(xPos,0,1120,40,width-40);
54
55//ploting graph window, unit
56strokeWeight(2);
57stroke(175);
58Line(0,0,0,100);
59textFont(f24);
60fill(0,00,255);
61textAlign(RIGHT);
62xmargin("EarthQuake Graph (SESMIOGRAPH)",200,100);
63
64fill(100);
65strokeWeight(100);
66line(1050,80,1200,80);
67
68strokeWeight(1);
69textAlign(RIGHT);
70fill(0,0,255);
71String temp="X:"+temp1;
72Text(temp,100,95);
73
74fill(0,255,0);
75temp="Y:"+temp2;
76Text(temp,100,92);
77
78fill(255,0,0);;
79temp="Z:"+temp3;
80Text(temp,100,89);
81
82
83//ploting x y and z values over graph
84strokeWeight(2);
85int shift=40;
86
87stroke(0,0,255);
88if(y1 == 0)
89y1=height-inByte1-shift;
90line(x, y1, x+2, height-inByte1-shift) ;
91y1=height-inByte1-shift;
92
93stroke(0,255,0);
94if(y2 == 0)
95y2=height-inByte2-shift;
96line(x, y2, x+2, height-inByte2-shift) ;
97y2=height-inByte2-shift;
98
99stroke(255,0,0);
100if(y2 == 0)
101y3=height-inByte3-shift;
102line(x, y3, x+2, height-inByte3-shift) ;
103y3=height-inByte3-shift;
104
105xPos+=1;
106
107if (x >= width-30) // go back to begining
108{
109xPos = 0;
110background(80);
111}
112}
113}
114
115void Line(int x1, int y1, int x2, int y2)
116{
117float xx1=map(x1,0,100,40,width-40);
118float xx2=map(x2,0,100,40,width-40);
119float yy1=map(y1,0,100,height-40,40);
120float yy2=map(y2,0,100,height-40,40);
121
122line(xx1,yy1,xx2,yy2);
123xx2=map(100,0,100,40,width-40);
124yy2=map(0,0,100,height-40,40);
125line(xx1,yy1,xx2,yy2);
126
127strokeWeight(1);
128for(int i=1;i<21;i++)
129{
130yy2=map(i*10,0,200,height-40,40);
131yy1=yy2;
132line(xx1,yy1,xx2,yy2);
133}
134yy2=map(100,0,100,height-40,40);
135yy1=map(0,0,100,height-40,40);
136for(int i=1;i<41;i++)
137{
138xx1=map(i*5,0,200,40,width-40);
139xx2=map(i*5,0,200,40,width-40);
140line(xx1,yy1,xx2,yy2);
141}
142
143textAlign(RIGHT); // 100 degree
144// result+=yy1;
145fill(255);
146strokeWeight(1);
147textFont(f12);
148for(int i=-10;i<11;i++)
149{
150String result="";
151result+=5*i;
152ymargin(result, x1,y1);
153y1+=5;
154}
155
156x1=0;
157y1=0;
158strokeWeight(1);
159textFont(f10);
160for(int i=0;i<41;i++)
161{
162String result="";
163result+=28*3*i;
164xmargin(result, x1,y1);
165x1+=5;
166}
167
168textAlign(RIGHT);
169
170textAlign(RIGHT);
171}
172
173void ymargin(String value, int x1, int y1)
174{
175
176float xx1=map(x1,0,100,40,width-40);
177float yy1=map(y1,0,100,height-40,40);
178text(value,xx1-5,yy1+5);
179}
180
181void xmargin(String value, int x1, int y1)
182{
183
184float xx1=map(x1,0,200,40,width-40);
185float yy1=map(y1,0,100,height-25,25);
186text(value,xx1+7,yy1);
187}
188
189void Text(String value, int x1, int y1)
190{
191
192float xx1=map(x1,0,100,40,width-40);
193float yy1=map(y1,0,100,height-25,25);
194text(value,xx1,yy1);
195}
THANK YOU….

You might also like