-
-
Save hippyaki/12be46e5cca4cc3a78e6b938145ebb6a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <BoltDeviceCredentials.h> //Save your API KEY and DEVICE ID in this file, before using this library | |
#include <BoltIoT-Arduino-Helper.h> | |
#include<LiquidCrystal.h> // lcd Header | |
LiquidCrystal lcd(7,6,5,4,3,2); // pins for LCD Connection | |
#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 | |
boltiot.begin(8,9); //Connect Bolt's RX & TX to the 8 and 9 of the Arduino | |
Serial.begin(9600); | |
delay(500); | |
lcd.print("EarthQuake "); | |
lcd.setCursor(0,1); | |
lcd.print("Detector "); | |
delay(1500); | |
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<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 "); | |
} | |
String data; | |
void loop(){ | |
int value1=analogRead(x); // reading x out | |
int value2=analogRead(y); //reading y out | |
int value3=analogRead(z); //reading z out | |
int x_value =xsample-value1; // finding change in x | |
int y_value=ysample-value2; // finding change in y | |
int z_value=zsample-value3; // finding change in z | |
/*displying change in x,y and z axis values over lcd*/ | |
lcd.setCursor(0,1); | |
lcd.print(x_value ); | |
lcd.setCursor(6,1); | |
lcd.print(y_value); | |
lcd.setCursor(12,1); | |
lcd.print(z_value); | |
delay(100); | |
/* comparing change with predefined limits*/ | |
if(x_value < minVal || x_value > maxVal || y_value < minVal || y_value > maxVal || z_value < minVal || z_value > 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 | |
/*Open Serial monitor to view the values */ | |
Serial.print("x="); | |
Serial.println(x_value ); | |
Serial.print("y="); | |
Serial.println(y_value); | |
Serial.print("z="); | |
Serial.println(z_value); | |
Serial.println(" $"); | |
boltiot.processPushDataCommand(x_value, y_value, z_value); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment