/* *Code for the blow sensor *Based on Knock and Calibrate from Arduino examples *by David Mellis,Tom Igoe and David Cuartielles * * *More info: *http://www.iua.upf.es/~jlozano/interfaces/blow_sensor.html *Jose Lozano * * */ // these constants won't change: const int ledPin = 13; // led connected to digital pin 13 const int piezo = 0; // the piezo is connected to analog pin 0 // these variables will change: int sensorReading = 0; // variable to store the value read from the sensor pin int sensorMax = 0; int sensorMin = 1023; int threshold; void setup() { pinMode(ledPin, OUTPUT); // declare the ledPin as as OUTPUT Serial.begin(57600); // use the serial port pinMode(13, OUTPUT); digitalWrite(13, HIGH); while (millis() < 3000) { threshold = analogRead(piezo); // record the maximum sensor value if (threshold > sensorMax) { sensorMax = threshold; } if (threshold < sensorMin) { sensorMin = threshold; } } // signal the end of the calibration period digitalWrite(13, LOW); threshold = sensorMax; // Serial.println("*"); Serial.println(sensorMax); Serial.println(sensorMax); Serial.println(sensorMax); Serial.println(sensorMin); Serial.println(sensorMin); Serial.println(sensorMin); // Serial.println("*"); } void loop() { // read the sensor and store it in the variable sensorReading: sensorReading = analogRead(piezo); // if the sensor reading is greater than the threshold: if ((sensorReading >= threshold) || (sensorReading <= sensorMin) ) { Serial.println(sensorReading); } delay(3); // Better for Processing showing data }