Example Code
int pin_LED = 13;
int pin_EP = 9;
void setup() {
Serial.begin(9600);
pinMode (pin_LED, OUTPUT);
pinMode (pin_EP, INPUT); //set EP input for measurment
}
void loop() {
long measurement = TP_init(); //Vibration sensor.
delay(50); // default is 50
Serial.print( "key U:" ); Serial.print( " [" ); Serial.print( measurement ); Serial.print( "] " );
if (measurement > 500){
digitalWrite(pin_LED, HIGH);
Serial.print( "Vibration Level: Earthquake." );
} else if (measurement > 100){
digitalWrite(pin_LED, HIGH);
Serial.print( "Vibration Level: Shake Tea." );
digitalWrite(pin_LED, LOW);
} else {
digitalWrite(pin_LED, LOW);
Serial.print( "Vibration Level: Very Quiet." );
}
}
long TP_init(){
delay(10); // default is 10
long measurement=pulseIn (pin_EP, HIGH); //wait for the pin to get HIGH and returns measurement
return measurement;
}