Question
Accelerometer ADXL335, Arduino Uno R3, LCD and buzzer are used to build an earthquake detector. What is the sampling rate and frequency for this arduino
Accelerometer ADXL335, Arduino Uno R3, LCD and buzzer are used to build an earthquake detector. What is the sampling rate and frequency for this arduino programming code? Please explain and show the calculation.
#include
#define buzzer 12 // buzzer pin #define led 13 //led pin
#define x A0 // x_out pin of Accelerometer #define y A1 // y_out pin of Accelerometer #define z A2 // z_out pin of Accelerometer
/*variables*/ int xsample=0; int ysample=0; int zsample=0; long start; int buz=0;
/*Macros*/ #define samples 50 #define maxVal 20 // max change limit #define minVal -20 // min change limit #define buzTime 5000 // buzzer on time
void setup() { lcd.begin(16,2); //initializing lcd Serial.begin(9600); // initializing serial delay(1000); lcd.print("EarthQuake "); lcd.setCursor(0,1); lcd.print("Detector "); delay(2000); lcd.clear(); lcd.print("Circuit Digest "); lcd.setCursor(0,1); lcd.print("Saddam Khan "); delay(2000); lcd.clear(); lcd.print("Calibrating....."); lcd.setCursor(0,1); lcd.print("Please wait..."); pinMode(buzzer, OUTPUT); pinMode(led, OUTPUT); buz=0; digitalWrite(buzzer, buz); digitalWrite(led, buz); for(int i=0;i 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 "); } void loop() { 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); /* 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; } else { lcd.clear(); lcd.print(" X Y Z "); } digitalWrite(buzzer, buz); // buzzer on and off command digitalWrite(led, buz); // led on and off command }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started