Experiment 10 - Piezo-Disc as a sensor
In this experiment, we want to check the different usages of piezoelectric sensors.
1. Piezoelectric disc as a voltage producer
Materials: One piezoelectric disc, One multimeter
Task:
Connect two outputs of the piezoelectric disc to two terminals of the multimeter. Then put your piezoelectric disc in a soft cloth and push it. You will see the produced voltage by the piezoelectric disc.
2. Interfacing a Piezoelectric sensor with Arduino and turning on an LED by Piezoelectric disc
In this experiment, we want to connect an LED with a piezoelectric disc and changing the mechanical energy to electrical energy, and turning an LED on.
Materials: one piezoelectric disc, One 1 Mega ohm sensor, one breadboard, one Arduino, one LED
You can connect the piezoelectric disc in the following way to connect it to the breadboard easier.
Put the LED and 1 Mega ohm resistor on the breadboard. Then follow these steps:
- Connect the positive pin of LED (longer terminal) to pin number 4 of Arduino.
- Connect the other terminal to GND of Arduino.
- Connect the positive output of the piezoelectric disc to one end of the resistor and connect the other end of the resistor to the A0 port of Arduino.
- Connect the other terminal of the piezoelectric disc to the GND of Arduino.
- Run the following code in Arduino programm:
int led=4;
int sensor=A0;
int threshold=1000;
void setup(){
pinMode(4,OUTPUT);
pinMode(A0,INPUT);
Serial.begin(9600);
}
void loop(){
int value=analogRead(sensor);
if (value>=threshold)
{
digitalWrite(led,HIGH);
delay(100);
}
else
{
digitalWrite(led,LOW);}
Serial.println(value);
}
When you run this code, you will see by pushing the piezoelectric disc the LED will be turned on.
3. Making a Knock Sensor
In this experiment, we use piezoelectric sensor as a switch button. It reads an analog pin and compares the result to a set threshold. You can use the previous circuit and run the following code in Arduino. If the result is greater than the threshold, it writes "knock" to the serial port, and toggles the LED on pin 4. If not, it only shows the sensor output.
const int ledPin = 4; // LED connected to digital pin 4
const int knockSensor = A0; // the piezo is connected to analog pin A0
const int threshold = 400; // threshold value to decide when the detected sound is a knock or not
// these variables will change:
int sensorReading = 0; // variable to store the value read from the sensor pin
int ledState = LOW; // variable used to store the last LED status, to toggle the light
void setup() {
pinMode(ledPin, OUTPUT); // declare the ledPin as as OUTPUT
Serial.begin(9600); // use the serial port
}
void loop() {
// read the sensor and store it in the variable sensorReading:
sensorReading = analogRead(knockSensor);
// if the sensor reading is greater than the threshold:
if (sensorReading >= threshold) {
// toggle the status of the ledPin:
ledState = !ledState;
// update the LED pin itself:
digitalWrite(ledPin, ledState);
// send the string "Knock!" back to the computer, followed by newline
Serial.print("Knock!");
}
delay(100); // delay to avoid overloading the serial port buffer
Serial.println(sensorReading);
}
Institut für Mechatronik im Maschinenbau (iMEK), Eißendorfer Straße 38, 21073 Hamburg