Home
»Unlabelled
» Arduino piezo code
/* Piezo Knock
* -----------
* Turn a standard piezo buzzer into a force sensor
*
* Created 24 October 2006
* copyleft 2006 Tod E. Kurt
* http://todbot.com/
*/
int ledPin = 13;
int piezoPin = 0;
int THRESHOLD = 100; // set minimum value that indicates a knock
int val = 0; // variable to store the value coming from the sensor
int t = 0; // the "time" measured for how long the knock lasts
void setup() {
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
Serial.println("ready"); // indicate we're waiting
}
void loop() {
digitalWrite(ledPin,LOW); // indicate we're waiting
val = analogRead(piezoPin); // read piezo
if( val >= THRESHOLD ) { // is it bigger than our minimum?
digitalWrite(ledPin, HIGH); // tell the world
t = 0;
while(analogRead(piezoPin) >= (THRESHOLD/2)) {
t++;
} // wait for it to go LOW (with a little hysteresis)
if(t!=0)
Serial.println(t);
}
}
Disclaimer: All the information in this blog is just gathered from different sites in the web and placed here and I am not the owner for these content
Popular Projects
-
I just recently talked about me starting a saltwater reef aquarium. A lot of time and money goes into starting such a device, and the reward...
-
intro Arduino EMF (Electromagnetic Field) Detector A while back I saw an EMF (Electromagnetic Field) Detector at makezine.com that used a le...
-
intro Temperature Control For Kitchen Appliances In this Instructable, I will step through controlling the temperature of most kitchen appli...
-
intro Logger Shield: Datalogging for Arduino Data logging shield Here's a handy Arduino shield: we've had a lot of people looking fo...
-
intro Arduino Home automation This is a relatively simple controller for controlling equipment in your home. At the moment I control my cent...
-
int switchPin = 2; // switch input int motor1Pin1 = 3; // pin 2 on L293D int motor1Pin2 = 4; // pin 7 on L293D int enablePin = 9; ...