Want to sense Earthquakes? Maybe equipment vibration? We have put together a quick and inexpensive project that will sense vibration. We use a Vibration sensor from Sparkfun, a SainSmart UNO, and a I2C LCD.
We have created a bar graph that moves back and forth based on vibration intensity, and a “Earthquake” message that displays when the level exceeds a threshold.
See Code and Video below:
Code:
Become the Maker you were born to be. Try Arduino Academy for FREE!
//sensitivity variables
int minimum = 200;
int maximum= 1023;
int maxdelay = 400;
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
#define I2C_ADDR 0x27 // change to your address found with I2C scanner
#define BACKLIGHT_PIN 3
#define En_pin 2
#define Rw_pin 1
#define Rs_pin 0
#define D4_pin 4
#define D5_pin 5
#define D6_pin 6
#define D7_pin 7
LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);
// Custom Character
byte seismic[8] = {
B11111,
B11111,
B11111,
B11111,
B11111,
B11111,
B11111,
B11111,
};
//defines the pin connections
int sensePin= 2;
void setup()
{
Serial.begin(9600);
lcd.begin (16,2); // or (20,4)
// Switch on the backlight
lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
lcd.setBacklight(HIGH);
lcd.createChar(0, seismic);
lcd.begin(16, 2);
}
void loop()
{
int reading= analogRead(sensePin);
Serial.println(reading);
reading = constrain(reading, minimum, maximum);
Serial.println(reading);
reading = map(reading, minimum, maximum, 0, 15);
Serial.println(reading);
lcd.clear();
for (int i=0; i <= reading; i++){
lcd.write(byte(0));
}
if (8<=reading){
lcd.setCursor(0, 1);
lcd.print(“Earthquake”);
delay(500);
}
delay(maxdelay);
lcd.clear();
}
Become the Maker you were born to be. Try Arduino Academy for FREE!
can you please tell me 1 magnitude = how much sensor value?
This is a un-calibrated sensor. You would have to make some educated guesses or scientific measurements to use this to collect normalized data.
can we make this without using I2C?? if yes, can you please help me with the coding.
just use the normal lcd example sketch and add the sensor bits from this sketch.
thank you
if i want to sense the vibration and at that instance of time dynamo will automatically turn on for few second only
this is my project so you wanna help me for this…..