Grove Starter Kit For Arduino - Piezo Vibration Sensor

Grove Starter Kit For Arduino - Piezo Vibration Sensor © LGPL

Teaches you how to use the Piezo vibration sensor in the Arduino Grove starter kit.

  • 1,993 views
  • 0 comments
  • 9 respects

Components and supplies

Apps and online services

About this project

Setup:

For hardware connections simply plug the vibration sensor into A0.

Code

Code for piezo vibration sensorArduino
Touch the piezo sensor to make it vibrate, of course, any way to make it vibrate would be OK too. The LED would be on when vibration detected. You can also Open the serial monitor to see the sensor outputs.
const int ledPin=12;
void setup() {
  Serial.begin(9600);
pinMode(ledPin,OUTPUT);
} 
 
void loop() {
int sensorValue = analogRead(A0);//read the vibration
 Serial.println(sensorValue);//print it
 delay(1000);
 if(sensorValue==1023)//if you have an led it will turn on or off based on the vibration
  {
    digitalWrite(ledPin,HIGH);
  }
 else
 {
  digitalWrite(ledPin,LOW);
  }
}
Code 2 for piezo vibration sensorArduino
You can directly use a digital pin, take D5 of base shield as an example, and connect LED to Pin 12.
const int ledPin=12;
void setup() {
  Serial.begin(9600);
  pinMode(ledPin,OUTPUT);
} 
 
void loop() {
int sensorState = digitalRead(5);
 Serial.println(sensorState);
 delay(1000);
 if(sensorState == HIGH)
  {
    digitalWrite(ledPin,HIGH);
  }
 else
 {
  digitalWrite(ledPin,LOW);
  }
}

Schematics

Vibration sensor setup
connect the vibration sensor to A0
Dscn4049 wr3cqpyksk

Comments

Similar projects you might like

Grove Starter Kit for Arduino: Touch sensor

by Grant

  • 788 views
  • 1 comment
  • 2 respects

Grove Starter Kit For Arduino --- RGB LCD

by Grant

  • 5,490 views
  • 2 comments
  • 7 respects

Vibration Sensor Module

Project tutorial by Alberto Zanon

  • 21,186 views
  • 2 comments
  • 9 respects
Add projectSign up / Login