Published © LGPL

Grove Starter Kit For Arduino - Piezo Vibration Sensor

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

BeginnerProtip30 minutes6,806
Grove Starter Kit For Arduino - Piezo Vibration Sensor

Things used in this project

Hardware components

Arduino 101
Arduino 101
×1
Seeed Studio SeeedStudio grove starter kit Arduino 101
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Vibration sensor setup

connect the vibration sensor to A0

Code

Code for piezo vibration sensor

Arduino
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 sensor

Arduino
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);
  }
}

Credits

Comments