Pages: [1]   Go Down
Author Topic: Meas sensor reading  (Read 376 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have a circuit built using a Piezo vibration sensor large Meas with mass weight. I used the code similar to the knock sensor.

void setup()
{
  Serial.begin(9600); //
}
void loop()
{
      int val;
      val=analogRead(0);//Connect the sensor to analog pin 0
      //if (val>100)
      float rating = val*(500/1023.0);
      Serial.println(rating);
      //Serial.println(val,DEC);//
      //else Serial.println();
      delay(100);
}

It works very well and gives me streaming data to the serial monitor. What I can't figure out is a way to make it print just the highest value per impact. Each impact will occur and be followed by no activity for a couple seconds. Currently I am seeing pretty reliable data but I can't figure out what to do. I tried to change the delay and I tried to assign a value to different ranges without success.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Something like this should get you going:
Code:
int highestval = 0;
int val;
// Loop a few times and read the values, saving the highest
for (int i = 0; i<=100; i++) {
   val = analogRead(0);
   if (val >= highestval) {
       highestval = val;
   }
}

// Now output they highest value
Serial.println(highestval);

// Sleep and then do it again
delay(100);

You can play around with how many times you go in the loop - not sure if 100 is your number but you can probably figure that out.

Good luck,
Dave
Logged

Pages: [1]   Go Up
Jump to: