"Arduino Official Tutorial First series" Sample program 6-2 vibration detection with piezoelectric elements

Source: Internet
Author: User
vibration detection with piezoelectric elements

This example shows you how to use a piezoelectric element to detect vibrations. (The piezoelectric element has many kinds of applications, the buzzer is one kind, but here is not "forward" uses the piezoelectric element, but uses its circuit characteristic "the reverse" uses. That is, the power generated vibration, vibration sound, now is the vibration generated current, judging by the current vibration. This example shows you how to use a piezoelectric element for vibration detection, and you can use this example to identify a knock, knock on a table, or knock on other solid surfaces.

When a piezoelectric element is deformed by sound waves, mechanical disturbances, or vibrations, a differential pressure is generated. On the other hand, if you add voltage to the piezoelectric element, it will generate vibrations. As a result, piezoelectric elements can be generated by electric vibration, but also by the vibration of electricity.

In this example, the voltage at both ends of the piezoelectric speaker is read continuously using Analogread (), and the detected voltage (0-5V) is mapped to a digital (0-1023) by a number-to- analog conversion technology (ADC) .

If the output of the piezoelectric element exceeds a certain limit value (indicating that the vibration has reached a certain strength) your board will be output through the serial port "detected vibration." "This string to the computer.

You need to open the serial monitor to see the effect. complete the hardware device required for this example An Arduino board or Genuino plate piezoelectric element 1mω resistor used as a tap on a solid surface connection line circuit connection


The piezoelectric element is polar, that is, the electric potential is always low on one side, and if an external circuit is added, the current is always flowing from one side to the other side.
Connect the black line (a level that is usually lower in potential) to GND. Connect the Red line (a level with a higher potential) to the A0 port. Also shunt a 1mω resistor to ensure that too much current does not damage the A0 port.
You can remove the plastic housing of the piezoelectric element. This way it is better able to receive external vibrations. Please stick the piezoelectric element on the surface under test and press and tap with appropriate force so that it detects vibration better. schematic diagram

Routine Code

In the following code, the value read from the piezoelectric element is compared to the limit value you set. You can try to increase/decrease the limit value to adjust the sensitivity to vibration.

/* 
  vibration detection Using piezoelectric elements

   This example reads the piezo element to detect the tap. The code reads the value of the piezoelectric element and compares it to the limit value.

   If the result is greater than the limit value, "vibrate detected" is output to the serial monitor. The onboard LEDs on the 13th pin will also light up.

   Circuit Construction:
    * Piezoelectric element anode (+) connection A0
    * Piezoelectric element cathode (-) connection GND
    * 1mω resistor connection A0 and GND

   code public

 *//


/constants:
const INT Ledpin =;      Number 13th PIN connection led
const int knocksensor = A0;//piezoelectric element
Const INT threshold =  Limit value for detecting whether there is a vibration

//variable:
int sensorreading = 0;      The variable that stores the value
int ledstate = low;         Storage led state Volume

void Setup () {
  pinmode (ledpin, output);//declare Ledpin as output mode
  serial.begin (9600);       Serial Port
}

void Loop () {
  //Read the value of the sensor and deposit the sensorreading variable:
  sensorreading = Analogread (knocksensor);

  If the sensorreading exceeds the limit value: If
  (sensorreading >= threshold) {
    //change Ledpin status: Ledstate
    =!ledstate;
    On/Off according to status:
    Digitalwrite (Ledpin, ledstate);
    The output message "Vibration detected!" and a newline
    serial.println ("Vibration detected!");
  }
  Delay (+);  Delay 100 milliseconds to maintain serial port stability
}
Related Information

Pinmode ()
Analogread ()
if ()
Serial.begin ()
Serial.print ()
ADXL3XX: Reads the adxl3xx accelerometer.
Knock: Use piezoelectric elements to detect collisions.
Memsic2125: two-axis accelerometer.
Ping: Use ultrasound to detect the distance of the object.

Original link update process

Date Log Translator
June 22, 2016 Create and translate documents Steven

Translator: Steven
E-mail: gammapi@qq.com
Reproduced please specify the source, all because of love.
I hope you can point out your valuable comments, thank you.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.