Sunday, October 18, 2015

Knock Sensor using arduino and piezo element

This is a simple knock sensor using arduino UNO and piezo element. the delay time can change from program code.
the sensitivity also can change by two ways:
1-change the value of resistor from 0.5 to 1.5 mega ohm
OR
2-change the number that written after " threshold= "







const int sensorPin=0;
const int ledPin= 13;
const int threshold= 50;

void setup()
{
pinMode(ledPin, OUTPUT);
}

void loop()
{
int val= analogRead(sensorPin);
if (val >= threshold)
{
digitalWrite(ledPin, HIGH);
delay(5000);
digitalWrite(ledPin, LOW);
}
else
digitalWrite(ledPin, LOW);
}