# Seismic Speed Calculation

Hi there i study geophysics in Istanbul University and there is a school project that i need to make.

I’m trying to calculate seismic speed in a solid. For example sound speed in a wood is almost 4000 meters/second. I want to calculate this value.

So my setup is :

A Piezoelectric sensor
A hammer.
And a metal plate

Hammer is connected to ground. Metal plate is connected to digital port 7 on arduino.
Piezoelectric sensor is in the beginning of wood and metal plate is in the end of the wood.
Wood is almost 1 meters long.

What i am trying to do is when i hit the hammer to the metal plate. I read the value from digitalread 0 and assigning micros() value to a variable

seismic wave goes through the wood and when it reaches piezoelectric sensor i get the micros() value again then i substract those values and calculate how much it takes the seismic wave to go through wood. Then i’m dividing woods length to the time difference and i get the speed value. But there is a problem

according to the calculations i should get a time value like 170uS-200uS but i’m getting 2000-3000uS

The code :

``````#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif
#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif

void setup() {
pinMode(0, INPUT);
pinMode(7, INPUT);
digitalWrite(7, HIGH);
Serial.begin(57600);
sbi(ADCSRA,ADPS2);
cbi(ADCSRA,ADPS1);
cbi(ADCSRA,ADPS0);
}

void loop()
{

while(digitalRead(7) == 1){}
unsigned long baslangic = micros();
while(analogRead(0) < 25){}
unsigned long son = micros();
Serial.println(son-baslangic);
delay(500);

}
``````

those definitions on the beginning is for speeding up the analogread sample

i couldn’t figured the problem what do you guys think?

Maybe the vibrations from the hammer are lasting for 2000 uS and it is taking the last vibration for the calculation, not the first one.
I think you need it to only take a sample once.

if (digitalRead(7)==1 && stop !=1){ //‘stop’ is there so that it will only do it once
unsigned long baslangic = micros();
stop=1;
}
if( (analogRead(0) < 25 && stop2 !=1){ //stop2 is there so that it will only do it once
unsigned long son = micros();
stop2=1;
Serial.println(son-baslangic);
}