Go Down

Topic: Meas sensor reading (Read 675 times) previous topic - next topic


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);
      //else Serial.println();

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.


Something like this should get you going:
Code: [Select]

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

// Sleep and then do it again

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,

Go Up