Original link: https://www.arduino.cc/en/Tutorial/Knock
Percussion detection
This tutorial shows you how to use a piezoelectric sensor to detect vibrations, such as knocking, tables, or other solid surfaces.
A piezoelectric sensor is an electronic device that generates voltage when it is physically deformed by vibration, sonic, or mechanical strain, and similarly, when you apply a voltage to a piezoelectric transducer, it vibrates and produces tones. Piezo components can be used to play tones and detect tones.
The code uses a analogRead()
function to read the output of the piezoelectric sensor, and encodes the voltage range from 0 to 5 volts at a value of 0 to 1023 during the analog-to-digital conversion (ADC).
If the output of the sensor is stronger than a certain threshold, your development Board will send the string "knock!" through the serial port. "To the computer.
Please open the Serial window to view this string.
Hardware requirements
Circuit
Various piezoelectric components are polar, meaning that the voltages pass through them (or from them) in a particular direction. Ground the black line (lower voltage) and connect the red wire (higher voltage) to the analog pin 0. In addition, a 1 gigabit resistor is paralleled to a piezoelectric component to limit the voltage and current generated by the piezoelectric component to protect the analog input pin.
Some piezoelectric elements may not have plastic housings. They look like a metal plate, which makes it easier to use as an input sensor. Because the piezoelectric sensor works best when firmly pressing and pasting its sensing surface.
Click image to enlarge
The picture was developed using fritzing. For more circuit examples, see the Fritzing project page
Schematic diagram
Click image to enlarge
Piezoelectric sensor in parallel with a 1 ohm resistor then connected to analog pin 0 (A0)
Code
In the following code, the value of the input piezoelectric sensor is compared with the threshold value set by the user. Try increasing or lowering this value to increase the overall sensitivity of the sensor.
/* Knock Sensor Vibration Transducer This sketch reads a piezo element to detect a knocking sound. It reads a analog pin and compares the result to a set threshold. If The result is greater than the threshold, it writes "knock" to the serial port, and toggles the LED on Pin 13. This code reads the value of the piezoelectric element to detect a percussion sound. It reads the analog pins and compares the results to the threshold values. If the result is greater than the threshold, write "knock" to the serial port,//and toggle the status of the LEDs on pin 13. The circuit:* + connection of the piezo attached to analog in 0* the "+" end of the piezoelectric component to A0 *-connection of the piezo attached to G round* the "-" end of the piezoelectric component to the gnd* 1-megohm resistor attached from analog on 0 to ground* 1 mega ohms respectively connected to A0 and Gnd reference URL: http://www.ar Duino.cc/en/tutorial/knock created 2011 by David Cuartielles ReferencepinMode()
analogRead()
if()
serial.begin()
serial.print()
Analoginput-Use a potentiometer to control the blinking of the LEDs.
Analoginoutserial-Reads the analog input, maps the result value, and uses the value to lighten or darken the LED.
Knock-use piezoelectric sensors to detect knocks.
Memsic2125-Two-axis acceleration sensor.
Ping-Use the ultrasonic module to detect objects.
Last modified 2015/07/29 SM
QQ Group
Welcome to our extended family Click to join the hard hit Alliance Arduino group number 8580606
Translation: Hard-hit Alliance translation group-Guangdong Small Wood
Translation time: 2016/12/15
Audit: Hard-hit Alliance translation Group technical Language audit-magic conch, lepton-, Chengdu Jie
Knock: Using piezoelectric sensors to detect percussion