FRIENDz

FAILURE IS THE SIGN OF SUCCESS!!

Detecting Vibration

Arduino-Detecting Vibration

           A Piezo sensor, also known as a knock sensor, produces a voltage in response to physical stress. The more it is stressed, the higher the voltage. The Piezo is polarized and the positive side (usually a red wire or a wire marked with a “+”) is connected to the analog input; the negative wire (usually black or marked with a “-”) is connected to ground. A high-value resistor (1 megohm) is connected across the sensor.
The voltage is detected by Arduino analogRead to turn on an LED. The THRESHOLD value determines the level from the sensor that will turn on the LED, and you can decrease or increase this value to
make the sketch more or less sensitive. Piezo sensors can be bought in plastic cases or as bare metal disks
with two wires attached. The components are the same; use whichever fits your project best. Some sensors, such as the Piezo, can be driven by the Arduino to produce the thing that they can sense.

/* piezo sketch
* lights and LED when the Piezo is tapped
*/
const int sensorPin = 0; // the analog pin connected to the sensor
const int ledPin = 13; // pin connected to LED
const int THRESHOLD = 100;
void setup()
{
pinMode(ledPin, OUTPUT);
}
void loop()
{
int val = analogRead(sensorPin);
if (val >= THRESHOLD)
{
digitalWrite(ledPin, HIGH);
delay(100); // to make the LED visible
}
else
digitalWrite(ledPin, LOW);
}

No comments:

Post a Comment